akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

int solve(vi& a) {
    sort(ALL(a));
    int best = INT_MAX;
    do {
        int cost = 0 + abs(a[1]-a[0]) + abs(a[2]-a[1]);
        best = min(best,cost);
    } while (next_permutation(ALL(a)));
    return best;
}

int main() {
    vi a(3);
    loadvec(a,3);
    cout << solve(a) << endl;
    return 0;
}


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

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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  vector<int> dp(N, 0);
  rep(i, N) cin >> h.at(i);

  dp.at(0) = 0;
  dp.at(1) = abs(h.at(1) - h.at(0));
  for(int i = 2; i < N; ++i){
    int i_1 = dp.at(i-1) + abs(h.at(i) - h.at(i-1));
    int i_2 = dp.at(i-2) + abs(h.at(i) - h.at(i-2));
    dp.at(i) = min(i_1, i_2);
  }
  cout << dp.at(N-1) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define n_max llong(1e5 + 500)
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}


vector<pair<llong,llong>> factoring(llong n){
    vector<pair<llong,llong>> ans;
    if( n== 1){
        ans.push_back( make_pair(1,1));
        return ans;
    }
    llong i=1;
    while(1){
        i+=1;
        if( i * i > n) break;
        pair<llong,llong> tmp;
        tmp.first=i;
        tmp.second=0;
        while(1){
            if(n%i != 0) break;
            n/=i;
            tmp.second+=1;
        }
        if(tmp.second!=0) ans.push_back(tmp);
    }
    if(n!=1) ans.push_back( make_pair(llong(n),llong(1)));
    return ans;

}


llong fac[n_max];  /// fac[n] = n!
llong finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
llong inv[n_max];  /// (n * inv[n]) % MOD = 1
 
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR (i, 2, n_max) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}
 
llong nCk (int n, int k) {
  if (n < k || k < 0 || n < 0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

signed main(){
    init();
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> soinsuu = factoring(m);
    int ans = 1;

    itrfor(itr,soinsuu){
        int yaku = itr->fi;
        int kata = itr->se;
        if(yaku == 1) continue;
        ans *= nCk(n + kata -1 ,kata );
        ans %= MOD;
    }

    cout << ans << endl;

}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
 int main(){
     int a,b,c;
     cin >> a >> b >> c;
        if(a <= b && a <= c){
     cout << a << " ";
            if(b <= c){ cout << b << " " << c << endl;
             } else { cout << c << " " << b << endl;}
        }else if(b <= a && b <= c){
               cout << b << " ";
         if(a <= c){ cout << a << " " << c << endl;
          }else{ cout << c << " " << a << endl;}
      } else{
             cout << c << " ";
              if(a <= b){cout << a << " " << b << endl;
                }else { cout << b << " " << a << endl;}
        
      }
        
     return 0;
 }
 


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    int ans = 0;
    rep(i,5){
        int t; cin >> t;
        ans = max(ans,(n-1)/t);
    }
    cout << ans + 5 << endl;
    
    
    return 0;
}

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

using namespace std;


int main() {
	int a, b, c;
	cin >> a;
	if (a == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cin >> b>>c;
		cout<<b + c << endl;
	}



	return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	string s;
	scans(s);
	int g = 0, p = 0;
	for (const auto& aa : s) {
		if (aa == 'g')++g;
		else ++p;
	}
	printf("%d\n", (int)s.length() / 2 - p);

	Please AC;
}

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

class MainClass : Scanner
{
    static void Main()
    {
        var (N, M, V, P) = ReadTuple<int,long,int,int>();
        var A = RLongs();
        Array.Sort(A);
        Array.Reverse(A);
        P--;
        int U = N - V;
        var D = new long[N];
        for (int i = 0; i < N-1; i++)
        {
            if (i < P) continue;
            D[i + 1] = D[i] + (A[i] - A[i + 1]) * (i+1-P);
        }
        
        int ans = 0;
        
        for (int i = 0; i < N; i++)
        {
            if (i + 1 <= P) { ans++;continue; }
            if (A[P] - A[i] > M) break;
            if (D[i] > Min(i + 1 - P, U) * M) break;

            ans++;
        }
        WriteLine(ans);
    }
}



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

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

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


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

signed main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  vector<int> res;
  for (int i = 0; i < n; ++i) {
    int k = -1;
    for (int j = 0; j < (int) a.size(); ++j) {
      if (a[j] == j) {
        k = j;
      }
    }
    if (k == -1) {
      cout << -1 << '\n';
      return 0;
    }
    res.push_back(k);
    a.erase(a.begin() + k);
  }
  reverse(res.begin(), res.end());
  for (int x : res) {
    cout << x + 1 << '\n';
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main(void) {
    int N;
    vector<int> a(200010,0), b(200010,0);
    cin >> N;
    for (int i=0;i<N;i++) {
        cin >> a[i];
        b[a[i]] = i;
    }

    set<int> S;
    S.insert(-1);
    S.insert(N);
    long long ans = 0LL;
    for (int i=1;i<=N;i++) {
        auto itr = S.lower_bound(b[i]);
        long long r = *itr - b[i];
        long long l = b[i] - *(--itr);
        ans += i * l * r;
        S.insert(b[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
W, H, N = map(int, input().split())
field = [[1 for i in range(W)] for j in range(H)]
xya = [list(map(int, input().split())) for _ in range(N)]

for i in range(N):
    x, y, a = xya[i]
    if a == 1:
        for w in range(x):
            for h in range(H):
                field[h][w] = 0
    elif a == 2:
        for w in range(x, W):
            for h in range(H):
                field[h][w] = 0

    elif a == 3:
        for w in range(W):
            for h in range(y):
                field[h][w] = 0

    elif a == 4:
        for w in range(W):
            for h in range(y, H):
                field[h][w] = 0
ans = 0
for i in field:
    ans += sum(i)
print(ans)


Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


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

    vector<ll> h(N);
    for (ll i = 0ll; i < N; ++i) {
        cin>>h[i];
    }
    sort(h.rbegin(),h.rend());
    ll maxi=h[0]/B+1,mini=h[0]/A-1;
    ll x=(maxi+mini)/2;
    while(maxi-mini>1ll){
        //printf("%d %d %d\n",maxi,mini,x);
        ll cnt=0ll;
        for (ll i = 0ll; i < N; ++i) {
            cnt+=max(0ll,(ll)ceil((double)(h[i]-B*x)/(A-B)));
        }
        if(cnt>x){
            ll mid=(x+maxi)/2;
            mini=x; x=mid;
        }else{
            ll mid=(x+mini)/2;
            maxi=x; x=mid;
        }
    }
	
    cout<<maxi<<endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int n;
char a[100],b[100];
ll dp[2000][2];
int main()
{
	scanf("%d%s%s",&n,a+1,b+1);
	if(a[1]==a[2]) dp[2][1]=6;
	else dp[1][0]=3;
	for(int i=2+(a[1]==a[2]);i<=n;i++)
	{
		if(i<n&&a[i]==a[i+1])
			dp[i+1][1]=(dp[i-1][0]*2+dp[i-1][1]*3)%mod,i++;
		else
			dp[i][0]=(dp[i-1][0]*2+dp[i-1][1])%mod;
	}
	printf("%d\n",(dp[n][0]+dp[n][1])%mod);
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

n = int(input())
a = list(map(int,input().split()))

a = list(accumulate(a))

ans1 = 0
tmp1 = 0
for i in range(n):
    b = a[i] + tmp1
    if i % 2 == 0 and b <= 0:
        tmp1 += 1 - b
        ans1 += 1 - b
    elif i % 2 == 1 and b >= 0:
        tmp1 += -1 - b
        ans1 += 1 + b

ans2 = 0
tmp2 = 0
for i in range(n):
    b = a[i] + tmp2
    if i % 2 == 1 and b <= 0:
        tmp2 += 1 - b
        ans2 += 1 - b
    elif i % 2 == 0 and b >= 0:
        tmp2 += -1 - b
        ans2 += 1 + b

ans = min(ans1,ans2)
print(ans)

Measured memory_bytes: 14212
def main():
    n = int(input())
    d, x = map(int, input().split())
    As = [int(input()) for _ in range(n)]

    ans = 0
    for a in As:
        i = 0
        while True:
            if i*a+1 > d:
                break
            ans += 1
            i += 1
    ans += x
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
	int n,i;
	int a[105];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=n-1;i>=0;i--)
	{
		if(!i)printf("%d",a[i]);
		else printf("%d ",a[i]);
	}
	printf("\n");	
	return 0;
}


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

using namespace std;

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

#define F first
#define S second

ll n, a, b, c, d;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> a >> b >> c >> d;
	ll des = abs(a-b);
	n--;
	for (ll i = 0; i <= n; i++){
		ll l = -i*c, r = -i*d;
		l += (n-i)*d;
		r += (n-i)*c;
		if (r <= des && des <= l){
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}


Measured memory_bytes: 256
n,d = gets.chomp.split(" ").map(&:to_i)
x_arr = n.times.map{gets.chomp.split(" ").map(&:to_i)}

count = 0
(0..n-2).each do |i|
  (i+1..n-1).each do |j|
    y = x_arr[i]
    z = x_arr[j]
    dist = 0
    y.zip(z).each do |yi, zi|
      dist += (yi - zi) ** 2
    end
    count += 1 if Math.sqrt(dist).to_i == Math.sqrt(dist)
  end
end

puts count


Measured memory_bytes: 1788
#include<stdio.h>

int main(void){
	
	int H,W;
	int i,j;

	while(1){
		
		scanf("%d %d",&H,&W);
		if(H==0 && W==0)break;
		for(i=0;i<H;i++){
			if(i==0 || i==H-1){
				for(j=0;j<W;j++){
					printf("#");
				}
			}
			else{
				for(j=0;j<W;j++){
					if(j==0 ||j==W-1){
						printf("#");
					}
					else{
						printf(".");
					}
				}
			}	
		printf("\n");
		if(i==H-1)printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 572
#include<iostream>

using namespace std;

int main()
{
    int a,b,c,i;
    for(i=1;i<=3000;i++)
    {
        cin >> a >> b;
        if(a==0 && b==0)
            break;
        if(a>b)
        {
            c=a;
            a=b;
            b=c;
        }
        cout<<a<<" "<<b<<endl;
    }
}


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

int main() {
  long double a,b,h,m;
  cin>>a>>b>>h>>m;
  long double pi=acos(-1);
  long double rad=(30*h+0.5*m-6*m)*pi/180;
  long double x=sqrt(a*a+b*b-2*a*b*cos(rad));
  printf("%.100Lf",x);
}

Measured memory_bytes: 4152
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;


int main() {
	int i, j;
	int A, B;
	cin >> A >> B;
	string X,Y;
	int ans = 0;
	for (i = A; i <= B; ++i) {
		X = to_string(i);
		Y = X;
		reverse(X.begin(), X.end());
		if (X == Y) {
			++ans;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    if(0<c-a-b && 4*a*b<(c-a-b)*(c-a-b)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}

void solve() {
  LL A, B, C, D; cin >> A >> B >> C >> D;
  LL lcm = (C * D) / gcd(C, D);
  cout << (B-A+1) - (B/C-(A-1)/C) - (B/D-(A-1)/D) + (B/lcm-(A-1)/lcm) << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  long long ans = 0, b_cnt = 0;
  for (char c : s) {
    if (c == 'B') {
      b_cnt++;
    } else {
      ans += b_cnt;
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod1e7(ll a){
  return (a % 1000000007);
}

ll mod1e9(ll a){
  return (a % 1000000009);
}

ll mod998(ll a){
  return (a % 998244353);
}

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

vector<ll> fac(200001);
void factorial(){
  fac[0] = 1; 
  for(ll i=1; i < 200001; i++){
    fac[i] = mod998(fac[i-1]*i);
  }
}
    
ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return mod998(fac[n]/fac[r]/fac[n-r]);
}

int main(){
  ll a,b,x; cin >> a >> b >> x;
  
  if(a <= x and x <= a+b) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
  
}

Measured memory_bytes: 4596
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int kakaku,daikin,sagaku;
    while(cin>>daikin>>kakaku,daikin){
        int s1000=0,s500=0,s100=0;
        sagaku=kakaku-daikin;
        for(;;)if(sagaku-1000>=0){sagaku-=1000;s1000++;}else break;
        for(;;)if(sagaku-500>=0){sagaku-=500;s500++;}else break;
        for(;;)if(sagaku-100>=0){sagaku-=100;s100++;}else break;
        cout<<s100<<" "<<s500<<" "<<s1000<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

ans = r * g * b

for i in range(1, N-1):
    now = S[i]
    for j in range(1, min(i, N-1-i)+1):
        if len(set([S[i-j], now, S[i+j]])) == 3:
            ans -= 1


print(ans)

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

int main() {
  vector<int> C(3);
  for(int i=0;i<3;i++){
    cin >>C.at(i);
  }
  sort(C.begin(),C.end());
  
  cout <<(C.at(2)-C.at(0)) <<endl;
  return 0;
}



Measured memory_bytes: 256
def solve(lengths):
    # O(n**2) solution?
    # if we have a, b , with a > b
    # then a < c + b, c < a + b -> a - b < c < a + b is the only condition
    # let's say we iterate from max b and max a , so there will be no duplicates.
    # the diff b - a is the only important thing, since a + b will always be bigger than c
    # So we could do DP on this.

    c_counts = {}
    lengths.sort(reverse=True)
    ans = 0
    for i in range(len(lengths)):
        for j in range(i + 1, len(lengths)):
            a, b = lengths[i], lengths[j]
            c_limit = (j, a - b)
            if c_limit in c_counts:
                ans += c_counts[c_limit]
                continue
            c_count = 0
            for k in range(j + 1, len(lengths)):
                c = lengths[k]
                if c > a - b:
                    c_count += 1
                else:
                    # Descending so..
                    break
            c_counts[c_limit] = c_count
            ans += c_count
    return ans


if __name__ == "__main__":
    n = int(input())
    l_s = [int(l) for l in input().split(' ')]
    print(solve(l_s))


Measured memory_bytes: 144256
#include<iostream>
using namespace std;
typedef long long ll;
int n,a,b;
int main()
{
  	cin>>a>>b;
	bool flag=0;
	int res=min(int(a/0.08),int(b/0.1));
	for(int i=res;i<=100000;i++)
	{
		//cout<<i<<' '<<int(i*0.08)<<' '<<int(i*0.1)<<endl;
		if(int(i*0.08)==a&&int(i*0.1)==b) 
		{
			flag=1;
			cout<<i;
			break;
		}
	}
	if(!flag) cout<<-1;
  	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<ULL> A(N); rep(i, N) cin >> A[i];
		ULL S = 0; rep(i, N) S += A[i];
		ULL m = 1000000000; rep(i, N) m = min(m, A[i]);
		if (S % 2 == 1) { cout << "First" << endl; return; }
		if (N % 2 == 0 && m % 2 == 1) { cout << "First" << endl; return; }
		cout << "Second" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}



Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
 int main(){
 int n;
  string s;
  cin >> n >> s;
 int a = 0, b = 0;
  for(int i=0;i<n;i++){
  	if(s.at(i)=='R'){
    a++;
    }
  }
  int ans = a;
   // 一番左に境界を置いたと考える時の場合。
  for(int i=0;i<n;i++){
    if (s[i] == 'R') a--;
    else {
      b++;
    }
    int now = max(a,b);
    ans = min(ans, now);
  }
  cout <<ans<< endl; 
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<double> c_sum(n + 1);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        c_sum[i + 1] = c_sum[i] + 0.5 * (p + 1);
    }

    double ret = 0;
    for (int i = k; i <= n; i++) ret = max(ret, c_sum[i] - c_sum[i - k]);
    cout << fixed << setprecision(15) << ret << endl;
    return 0;
}

Measured memory_bytes: 1792
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	ll n, m;
	cin >> n >> m;

	ll c;
	c = n * 2;
	ll cnt;
	if (m >= c) {
		m -= c;
		cnt = n;
		cnt += (m / 4);
		cout << cnt << endl;
		return 0;
	}
	else {
		cnt = (m /2);
		cout << cnt << endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Text;
using System.Linq;

namespace abc158
{
    class Program
    {
        static void Main()
        {
            var s = ReadLine();
            var q = int.Parse(ReadLine());
            var isReverse = false;
            var headSb = new StringBuilder(200000);
            var tailSb = new StringBuilder(200000);
            for (var i = 0; i < q; ++i)
            {
                var query = ReadLine();
                if ("1".Equals(query))
                {
                    isReverse = !isReverse;
                }
                else
                {
                    var fc = query.Split(' ');
                    var f = fc[1];
                    var c = fc[2];
                    if (isReverse)
                    {
                        if ("1".Equals(f))
                        {
                            tailSb.Append(c);
                        }
                        else
                        {
                            headSb.Append(c);
                        }
                    }
                    else
                    {
                        if ("1".Equals(f))
                        {
                            headSb.Append(c);
                        }
                        else
                        {
                            tailSb.Append(c);
                        }
                    }
                }
            }
            if (isReverse)
            {
                var tail = string.Concat(tailSb.ToString().Reverse());
                var body = string.Concat(s.Reverse());
                WriteLine(tail + body + headSb.ToString());
            }
            else
            {
                var head = string.Concat(headSb.ToString().Reverse());
                WriteLine(head + s + tailSb.ToString());
            }
        }
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	string s;
	cin >> n >> s;
	int res = 0;
	rep (i, s.size()) {
	  res++;
	  while (i + 1 < n && s[i + 1] == s[i]) i++;
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3756
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;

public class Main {
	 static InputReader in = new InputReader(System.in);
	 static PrintWriter out = new PrintWriter(System.out);
	 
	 public static void main(String[] args) {
		 int n = in.nextInt();
		 int result = 0;
		 int a =0;
		 int b =0;
		 while (n -- >0)
		 {
			 a = in.nextInt();
			 b = in.nextInt();
			 result+= (b-a)+1;
		 }
		 
		
		 out.println(result);
		 out.close();

	 }
	 static class InputReader {
	        public BufferedReader reader;
	        public StringTokenizer tokenizer;
	 
	        public InputReader(InputStream stream) {
	            reader = new BufferedReader(new InputStreamReader(stream), 32768);
	            tokenizer = null;
	        }
	 
	        public String next() {
	            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	                try {
	                    tokenizer = new StringTokenizer(reader.readLine());
	                } catch (IOException e) {
	                    throw new RuntimeException(e);
	                }
	            }
	            return tokenizer.nextToken();
	        }
	 
	        public int nextInt() {
	            return Integer.parseInt(next());
	        }
	 
	        public long nextLong() {
	            return Long.parseLong(next());
	        }
	 
	        public double nextDouble() {
	            return Double.parseDouble(next());
	        }
	 
	        public String nextLine() {
	            try {
	                return reader.readLine();
	            } catch (Exception e) {
	                e.printStackTrace();
	            }
	            return null;
	        }
	 
	        public boolean hasNext() {
	            String next = null;
	            try {
	                next = reader.readLine();
	            } catch (Exception e) {
	            }
	            if (next == null) {
	                return false;
	            }
	            tokenizer = new StringTokenizer(next);
	            return true;
	        }
	 
	        public BigInteger nextBigInteger() {
	            return new BigInteger(next());
	        }
	    }
	}

Measured memory_bytes: 32944
n,m = gets.split.map(&:to_i)
a = Hash.new(0)
$mod = 10**9+7
for i in 2..Math.sqrt(m).floor+1
  break if m < i*i
  while m%i == 0
    m /= i
    a[i] += 1
  end
end
if m != 1
  a[m] += 1
end
fact = Array.new(100100,1)
for i in 2..100099
  fact[i] = (fact[i-1]*i)%$mod
end
def exp(a,b)
  if b == 0
    1
  elsif b == 1
    a
  elsif b%2 == 0
    (exp(a,b/2)**2)%$mod
  else
    (a*exp(a,b/2)**2)%$mod
  end
end
fact_inv = Array.new(100100,0)
fact_inv[100099] = exp(fact[100099],$mod-2)
(100098).downto (0) do |i|
  fact_inv[i] = (fact_inv[i+1]*(i+1))%$mod
end
ans = 1
a.values.each do |i|
  ans *= (fact[n+i-1]*fact_inv[i]*fact_inv[n-1])%$mod
  ans %= $mod
end
puts ans

Measured memory_bytes: 5372
#include <bits/stdc++.h>
 
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
 
using namespace std;
typedef pair<int,int>P;
 
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int dx1[]={-1,-1,-1,0,0,1,1,1};
int dy1[]={-1,0,1,-1,1,-1,0,1};
int h,w;
char S,T;
 
vector<int>v[1000];
 
int sx,sy,gx,gy;
string s[100];
 
void INPUT(){
 
  cin>>h>>w>>S>>T; 
 
  r(i,h)cin>>s[i];
 
  r(i,h)r(j,w){
    if(s[i][j]==S)sx=j,sy=i;
    if(s[i][j]==T)gx=j,gy=i;
  }
}
 
void make_GRAPH(){
  r(i,h)r(j,w)if('A'<=s[i][j]&&s[i][j]<='Z'){
    r(k,4){
      int x=j+dx[k]+dx[k];
      int y=i+dy[k]+dy[k];
      if(x<0||y<0||x>=w||y>=h)continue;
      if(k%2==1&&s[y][x]=='|')continue;
      if(k%2==0&&s[y][x]=='-')continue;
 
      if(k%2==1&&s[y][x]=='-'){
        while(s[y][x]=='-'){
          y+=dy[k];
          x+=dx[k];
        }
        y+=dy[k];
        x+=dx[k];
        v[s[i][j]-'A'].push_back(s[y][x]-'A');
      }
 
      else if(k%2==0&&s[y][x]=='|'){
        while(s[y][x]=='|'){
          y+=dy[k];
          x+=dx[k];
        }
        y+=dy[k];
        x+=dx[k];
        v[s[i][j]-'A'].push_back(s[y][x]-'A');
      }
 
    }
  }
}
bool used[100009];
int d[100005];
 
void BFS(){
 
  queue<P>q;
 
  q.push(P(s[sy][sx]-'A',0));
  used[s[sy][sx]-'A']=1;
 
  while(!q.empty()){
    P p=q.front();q.pop();
    int x=p.first;
    int cost=p.second;
    d[x]=cost;
    r(i,v[x].size()){
      int next=v[x][i];
      if(!used[next]){
        used[next]=1;
        q.push(P(next,cost+1));
      }
    }
  }
  cout<<d[s[gy][gx]-'A']<<endl;
}
 
int main(){
  INPUT();
  make_GRAPH();
  BFS();
}


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

using namespace std;

template <class T>
struct Triple {
	T a, b, c;

	Triple() : a(0), b(0), c(0) {

	}

	Triple(const T & a, const T & b, const T & c) : a(a), b(b), c(c) {
		
	}
};

vector<Triple<int> > ans;

bool answer(const int & N, const int & K) {
	if (N < K * 2 - 1)
		return false;

	for (int i = 0; i < N; i++)
		ans.emplace_back(K + i, K + N * 2 - i - 1, K + N * 2 + i);
	int x = K - 1;
	int y = (x + 1) / 2, z = x / 2;
	for (int i = 0; i < y; i++)
		swap(ans[i].b, ans[y * 2 - i - 1].b);
	for (int i = 0; i < z; i++)
		swap(ans[y * 2 + i].b, ans[y * 2 + z * 2 - i].b);
	for (int i = 0; i <= x * 2; i++)
		ans[i].c = ans[i].a + ans[i].b;
	return true;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	int N, K;
	
	cin >> N >> K;

	if (answer(N, K)) {
		for (const auto & t : ans)
			cout << t.a << ' ' << t.b << ' ' << t.c << '\n';
	} else
		cout << "-1" << '\n';

	return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> v[N];
vector<bool> vs(N);
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll x,y;
    cin>>x>>y;
    if(2*x<=y&&y<=4*x&&y%2==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}

Measured memory_bytes: 5984
#include<iostream>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef pair<int,int> P;

int n;
P p[1000];
int dp[1001][1001];
const int INF = 1e9+1;

int main(){
  cin >> n;
  rep(i,n)cin >> p[i].second >> p[i].first;
  sort(p,p+n);
  
  rep(i,n+1)rep(j,n+1)dp[i][j] = INF;
  dp[0][0] = 0;
  
  rep(i,n){
    rep(j,n){
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
      if(dp[i][j] + p[i].second <= p[i].first){
	dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j] + p[i].second);
      }
    }
  }

  for(int i=n;i>=0;i--){
    if(dp[n][i] < INF){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 1236
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))
SIZE = [0] + [1] * N  # 1-indexed


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    X, Y = find(x), find(y)
    SX, SY = SIZE[X], SIZE[Y]
    if SX > SY:
        m = X
    else:
        m = Y
    SIZE[m] = SX + SY
    SIZE[X + Y - m] = 0
    UF[X + Y - m] = m


def is_same(x, y):
    return find(x) == find(y)


def scan_uf():
    for i in range(len(UF)):
        find(i)


ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
    if not is_same(a, b):
        ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
        unite(a, b)
    else:
        ans += [ans[-1]]
print(*ans[-2::-1], sep='\n')


Measured memory_bytes: 31012
#include <iostream>
#include<queue>
#include <stack>
#include <string.h>
using namespace std;




int main() {
	int a, b, k;
	cin >> a >>b >> k;
	int r;
	r = 0;
	int ans1, ans2;
	ans1 = 0; ans2 = 0;
	while (r <= k-1) {
		if (r % 2 == 0) {
			int c, am;
			am = a % 2;
			a = a - am;
			c = a / 2;
			a = a / 2;
			b = b + c;
		}
		else {
			int am, c;
			am = b % 2;
			b = b - am;
			c = b / 2;
			b = b / 2;
			a = a + c;
		}
		r++;
	}
	cout << a << ' ' << b << endl;
return 0;
}

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

#define LL long long
using namespace std;

int main(void){
    int flg = 0;

    int msbV = 0, lsbV = 0;

    char str[4];

    scanf("%s", str);

    msbV = (str[0] - 0x30) * 10 + (str[1] - 0x30);
    lsbV = (str[2] - 0x30) * 10 + (str[3] - 0x30);

    if((lsbV > 0 && lsbV <= 12) && (msbV > 0 && msbV <= 12)){
        cout << "AMBIGUOUS" << endl;
    }else if (lsbV > 0 && lsbV <= 12){
        cout << "YYMM" << endl;
    }else if (msbV > 0 && msbV <= 12){
        cout << "MMYY" << endl;
    }else {
        cout << "NA" << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

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

const LL mod = 1000000007;

int count(int x) 
{
    if (x == 0) return 0;
    return count(x >> 1) + (x & 1);
}

int main()
{
    int N;
    cin >> N;
    VI A(20);
    VVI x(20, VI(20)), y(20, VI(20));
    REP(i, N) {
        cin >> A[i];
        REP(j, A[i]) cin >> x[i][j] >> y[i][j];
    }

    int ans = 0;
    FOR(bits, 1, (1 << N)) {
        bool ok = true;
        REP(i, N) {
            if (!(bits & (1 << i))) continue;
            REP(j, A[i]) {
                if (((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if (ok) ans = max(ans, count(bits));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	int M, N;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> ab;
	for (int i = 0; i < N; i++) {
		int t1, t2;
		std::cin >> t1 >> t2;
		std::pair<int,int> tmp = std::make_pair(t1,t2);
		ab.emplace_back(tmp);
	}

	std::sort(
		ab.begin(),
		ab.end(),
		[](const std::pair<int,int>& x, const std::pair<int, int>& y) {return x.first < y.first; }
	);

	//for (int i = 0; i < ab.size(); i++) {
	//	std::cout << ab[i].first << " " << ab[i].second << std::endl;
	//}
	int drink_cnt = 0;
	long long yen = 0;
	for (int i = 0; i < N; i++) {
		long long tmp = 0;
		for (int j = 0; j < ab[i].second; j++) {
			tmp += ab[i].first;
			drink_cnt++;
			if (drink_cnt >= M) {
				break;
			}
		}
		yen += tmp;
		if (drink_cnt >= M) {
			break;
		}
	}

	std::cout << yen << std::endl;

	return 0;
}

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

typedef long long ll;
const int inf = 1000000000; // 10^9

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;

  double ans;
  for(int i=1; i<=n; i++) {
    ans = i*1.08;
    if(floor(ans) == n) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << ":(" << '\n';
  return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>

using namespace std;

using TUP = tuple<string, int, int>;

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

	vector<TUP> stores;
	for (int i = 1; i <= n; i++) {
		cin >> s >> p;
		p *= -1;
		// stores.emplace_back(tie(s, p, i));
		stores.emplace_back(s, p, i);
	}
	sort(stores.begin(), stores.end());

	int id;
	for (auto t: stores) {
		tie(s, p, id) = t;
		cout << id << endl;
		// cout << s << " " << p << " " << id << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;
typedef gp_hash_table<int,null_type> hash_map;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,M,arr[MAXN];
ll res=1;

int main(){
    scanf("%d %d",&len,&M);
    for(int i=1; i<=len; i++){
        scanf(" %d",&arr[i]);
        res = lcm(res,arr[i]/2);
    }
    for(int i=1; i<=len; i++)
        if((res*2/arr[i])%2 == 0)
            return 0*printf("0\n");
    ll ans = 1LL*M/(res*2);
    if(ans*res*2+res <= M) ans++;
    printf("%lld\n",ans);
}

Measured memory_bytes: 640
import java.math.BigInteger;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		if(h == 1 || w == 1) {
			System.out.println(1);
		} else {
			BigInteger ans = new BigInteger(Long.toString(h / 2));
			ans = ans.multiply(new BigInteger(Long.toString(w)));
			if(h % 2 == 1) {
				ans = ans.add(new BigInteger(Long.toString((w + 1) / 2)));
			}
			System.out.println(ans);
		}
 
	}
 
}

Measured memory_bytes: 21844
#include "stdio.h"
#include "string.h"

int main(){
  char str[21];
  int i=0;
  int flag=0;

  memset(str,'0',21);

  fgets(str,sizeof(str),stdin);

  for(i=20,flag=0;i>=0;i--){
    if(str[i]==0){
      flag++;
    }else if(flag==1 && str[i]!=10){
      printf("%c",str[i]);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Graph {
    int n;
    vector<set<int>> edge;
    vector<int> reached;

public:
    Graph(int N) : n(N), edge(N), reached(N) {}
    void add(int i, int j) {
        edge[i].emplace(j);
        edge[j].emplace(i);
    }
    void remove(int i, int j) {
        edge[i].erase(j);
        edge[j].erase(i);
    }
    void dfs(int i = 0) {
        if (reached[i]) return;
        reached[i] = true;
        for (auto &j : edge[i]) { dfs(j); }
    }
    bool connected() {
        fill(reached.begin(), reached.end(), false);
        dfs();
        bool res = true;
        REP(i, n) res *= reached[i];
        return res;
    }
};

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

    int N, M;
    cin >> N >> M;
    Graph graph(N);
    vector<int> a(M), b(M);
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph.add(a[i], b[i]);
    }
    int res = 0;
    REP(i, M) {
        graph.remove(a[i], b[i]);
        if (!graph.connected()) ++res;
        graph.add(a[i], b[i]);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int i = 0; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 K, N;
    cin >> K >> N;
    vector<i64> A(N);
    rep(i, N) cin >> A[i];

    i64 ans = A[N-1] - A[0];
    for(int i = 1; i < N; i++){
        ans = min(ans, K - (A[i] - A[i-1]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/22/20 21:00:03
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string sa,sb,sc; cin>>sa>>sb>>sc;
  map<char, int> cti;
  cti['a'] = 0;
  cti['b'] = 1;
  cti['c'] = 2;
  auto solve = [&]() {
    queue<int> s[3];
    for (auto c:sa) s[0].push(cti[c]);
    for (auto c:sb) s[1].push(cti[c]);
    for (auto c:sc) s[2].push(cti[c]);
    int turn = 0;
    while (true) {
      if (s[turn].empty()) {
        return turn;
      }
      auto next = s[turn].front(); s[turn].pop();
      turn = next;
    }
  };
  cout << string("ABC")[solve()] << endl;

  return 0;
}


Measured memory_bytes: 256
from math import gcd


k = int(input())

ans = 0

gcd_sum = [0] * 201

for i in range(1, k+1):
    for j in range(1, k+1):
        gcd_sum[i] += gcd(i, j)

for a in range(1, k+1):
    for b in range(1, k+1):
        q = gcd(a, b)
        ans += gcd_sum[q]

print(ans)


Measured memory_bytes: 9180