akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int n;
  int b,f,r,v;
  int count[4][3][10];
  cin >> n;
  for(int i = 0;i < 4;i++){
    for(int j = 0;j < 3;j++ ){
      for(int k = 0;k < 10;k++){
	count[i][j][k] = 0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    count[b-1][f-1][r-1] += v;
  }
 

for(int i = 0;i < 4;i++){
    for(int j = 0;j < 3;j++ ){
      for(int k = 0;k < 10;k++){
	cout << " " << count[i][j][k];
      }
      cout << endl;
    }
    if (i < 3){
            for (int l = 0; l < 20; l++){
                cout << "#";
            }
            cout << endl;
  }
 }


  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
ll mod = 1000000007;
ll pow(ll b, ll e) {
  if(e == 0) return 1LL;
  if(e % 2 == 1) return pow(b, e - 1) * b % mod;
  ll m = pow(b, e >> 1);
  return m * m % mod;
}
ll inv(ll a) { return pow(a, mod - 2); }
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<ll> fact(n + 1);
  fact[0] = 1LL;
  for(ll r = 1; r <= n; r++)
    fact[r] = fact[r - 1] * r % mod;
  ll ans = 0;
  for(ll i = 1; i <= k; i++) {
    ll a = n - k + 1;
    if(a < i) {
      puts("0");
      continue;
    }
    ans = fact[a] * inv(fact[i]) % mod;
    ans = ans * inv(fact[a - i]) % mod;

    ans = ans * fact[k - 1] % mod;
    ans = ans * inv(fact[i - 1]) % mod;
    ans = ans * inv(fact[k - i]) % mod;

    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 256
import queue

n,m=map(int,input().split())
G=[[] for _ in range(n)]
for index1 in range(m):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)


dist=[-1]*n
dist[0]=0
q=queue.Queue()
q.put(0)

while not q.empty():
    now=q.get()
    for next in G[now]:
        if dist[next]>=0:
            continue
        dist[next]=now
        q.put(next)

print('Yes')
for i in range(1,n):
    print(dist[i]+1)


Measured memory_bytes: 97040
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, m = list(map(int, input().strip().split()))
    c = [0] + sorted(list(map(int, input().strip().split())))
    dp = [[0] * (n+1) for _ in range(m+1)]
    dp[0] = [INF] * (n+1)
    dp[0][0] = 0
    for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

    print(dp[m][n])

if __name__ == '__main__':
    main()



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




int main()
{
  string S,T;
  cin >> S >> T;

  char now;
  int s_len = S.size(),t_len = T.size();
  char s_right = S.at(s_len - 1), t_last = T.at(t_len - 1);
  for (int i = s_len - 1; i >= 0; i--)
  {
    if (i < t_len - 1)
    {
      cout << "UNRESTORABLE" << endl;
      break;
    }
    if (S.at(i) == t_last | S.at(i) == '?')
    {
      for (int j = 0; j < t_len; j++)
      {
        if (S.at(i - j) != T.at(t_len - j - 1) & S.at(i - j) != '?')
        {
          break;
        }
        if (j == t_len - 1)
        {
          for (int k = 0; k < s_len; k++)
          {
            if (k == i - j)
            {
              for (char t : T)
              {
                cout << t;
              }
              k += t_len - 1;
              continue;
            }
            now = S.at(k);
            if (now == '?')
            {
              cout << 'a';
              continue;
            }
            cout << S.at(k);
          }
          cout << endl;
          return 0;
        }
      }
    }
  }
}


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

vector<vector<int> > graph;
vector<bool> used;

void dfs(int x){
	used[x]=1;
	for(int v : graph[x]){
		if(!used[v]){
			used[v]=1;
			dfs(v);
		}
	}
}

signed main(){
	int n,m,cnt=0;
	cin >> n >> m;
	graph.resize(n);
	used.resize(n);
	for(int i(0);i<n;++i){
		used[i]=0;
	}
	for(int i(0);i<m;++i){
		int x,y;
		cin >> x >> y;
		x--; y--;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	for(int i(0);i<n;++i){
		if(!used[i]){
			dfs(i);
			cnt++;
		}
	}
	
	cout << cnt-1;
}


Measured memory_bytes: 9308
import bisect
 
N=int(input())
b1=0
d=0

ans=0
 
A=list(map(int, input().split()))
A=sorted(A)
B=list(map(int, input().split()))
B=sorted(B, reverse=True)
C=list(map(int, input().split()))
C=sorted(C)
D=[]
E=[]

for b in B:
  d=d+len(C)-bisect.bisect_right(C,b)
  D.append(d)

D=sorted(D, reverse= True)  
B=sorted(B)

for a in A:
  if 0 <= bisect.bisect_right(B,a) <= len(D)-1:
    ans += D[bisect.bisect_right(B,a)]
print(ans)

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

int main() {
	int m ,f, b;
	cin >> m >> f >> b;
	int x = b-m;
	if(x<0) cout << '0' << endl;
	else if(f>=x) cout << x << endl;
	else if(m+f<b) cout << "NA" << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <functional>

#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

long factorial(int n){
	return n == 0 ? 1 : n * factorial(n-1);
}

int main(){
	int n;
	cin >> n;
	cout<<factorial(n)<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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 abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

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



const long long MOD = 1000000007;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int X, Y;
    cin >> X >> Y;
    int moto = A * X + B * Y;
    int ans = 1000000007;
    for (int i = 0; i <= max(X, Y); i++) {
        ans = min(moto + i * C*2 - A * min(i,X) - B * min(i,Y), ans);
        //cout << ans << endl;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N,K;cin>>N>>K;
    vector<ll> p(N+1);
    REPS(i,N)cin>>p[i];
    vi Asum(N+1);Asum[0]=0;REPS(i,N)Asum[i]=Asum[i-1]+p[i];
    ll ans=0;
    REPS(i,N-K+1){
        //cout<<Asum[i+K-1]-Asum[i-1]<<"\n";
        ans=max(ans,Asum[i+K-1]-Asum[i-1]);
    }
    cout<<dcml(10)<<(ans+(1*K))/2.0<<"\n";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;

int main(){
    int h, w;
    cin >> h >> w;
    vv(char) s(h);
    int igeta = 0;
    rep(i, h){
        rep(j, w){
            char ts;
            cin >> ts;
            s[i].push_back(ts);
            if(ts == '#') igeta++;
        }
    }

    // ゴールまでの最短距離を求める BFS
    vvint dist(h, vint(w, -1));
    dist[0][0] = 1;
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    vector<pair<int, int>> moveList = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    while(!que.empty()){
        auto now = que.front();
        int px = now.first, py = now.second;
        que.pop();
        for(auto next : moveList){
            int nx = px + next.first;
            int ny = py + next.second;
            if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
            if(s[ny][nx] == '#') continue;
            if(dist[ny][nx] != -1) continue;
            que.push(make_pair(nx, ny));
            dist[ny][nx] = (dist[py][px] + 1);
        }
    }

    int ans = h * w - igeta - dist[h - 1][w - 1];
    if(dist[h - 1][w - 1] == -1) ans = -1; 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;
	cin>>x>>y;
	ll ret=INF*INF;
	if(x<=y) ret=min(ret,y-x);
	if(-x<=y) ret=min(ret,1+y+x);
	if(-x<=-y) ret=min(ret,2-y+x);
	if(x<=-y) ret=min(ret,1-y-x);
	cout<<ret<<endl;
}


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

using namespace std;

using ll = long long;

const long long MOD = 1e9+7;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i] << endl;
    }
}

class Mll
{
    public:
    ll x;

    Mll() : x(0){}
    Mll(ll x=0) : x((x%MOD+MOD)%MOD){}

    Mll operator-() const
    {
        return Mll(-x);
    }

    Mll& operator+=(const Mll& A)
    {
        if((x += A.x) >= MOD) x -= MOD;
        return *this;
    }
    Mll& operator-=(const Mll& A)
    {
        if((x += MOD - A.x) >= MOD) x -= MOD;
        return *this;
    }
    Mll& operator*=(const Mll& A)
    {
        (x *= A.x) %= MOD;
        return *this;
    }
    
    Mll operator+(const Mll& A)
    {
        Mll res(*this);
        return res+=A;
    }
    Mll operator-(const Mll& A)
    {
        Mll res(*this);
        return res-=A;
    }
    Mll operator*(const Mll& A)
    {
        Mll res(*this);
        return res*=A;
    }
    
    Mll pow(ll t) const // t乗
    {
        if(t==0) return 1;
        Mll A = pow(t>>1);
        A *= A;
        if(t&1) A *= *this;
        return A;
    }

    // for prime mod
    Mll inv() const
    {
        return pow(MOD-2);
    }
    Mll& operator/=(const Mll& A)
    {
        return (*this) *= A.inv();
    }
    Mll operator/(const Mll& A) const
    {
        Mll res(*this);
        return res/=A;
    }

    friend ostream& operator<<(ostream& os, const Mll& M)
    {
        os << M.x;
        return os;
    }
};

vector<Mll> ALLIN_MLL(ll N)
{
    vector<ll> numbers_ll(N);
    ALLIN1_NUMBER(numbers_ll);

    vector<Mll> numbers_Mll;
    for(ll i=0;i<N;i++)
    {
        Mll add(numbers_ll[i]);
        numbers_Mll.push_back(add);
    }

    return numbers_Mll;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

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

    vector<ll> ret(N);

    for(ll i=1;i*i<N;i++)
    {
        for(ll j=1;j*j<N;j++)
        {
            for(ll k=1;k*k<N;k++)
            {
                ll A = i*i + j*j + k*k + i*j + j*k + k*i;
                if(A<=N)
                {
                    ret[A-1]++;
                }
            }
        }
    }

    ALLOUT_NUMBER(ret);

    return 0;
}

Measured memory_bytes: 3704
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
C = []

S = sum(A2) + A1[0]

for i in range(1,N):
  C.append(S)
  S += A1[i]-A2[i-1]
  
if N != 1:
  print(max(C))
else:
  print(A1[0]+A2[0])

Measured memory_bytes: 9144
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if(A < 6){
    cout << 0 << "\n";
  }else if(6 <= A && A <= 12){
    cout << B/2 << "\n";
  }
  else{
    cout << B << "\n";
  }
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n && n != 0){
	
	int dp[31];
	
	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 4;
	
	for(int i = 4; i <= n; ++i){
		dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
	}
	
	int sum = dp[n];
	
	if(sum % 10 == 0)
		sum /= 10;
	else
		sum = sum / 10 + 1;
	
	if(sum % 365 == 0)
		sum /= 365;
	else
		sum = sum / 365 + 1;
	
	cout << sum << endl;
	}
}

Measured memory_bytes: 1188
n = int(input())
s = input()
d = []

num_first = 0
for i in range(1, n):
    if s[i] == 'E':
        num_first += 1

d.append(num_first)

for i in range(1, n):
    tmp = 0
    if s[i-1] == 'W':
        tmp += 1
    if s[i] == 'E':
        tmp -= 1
    d.append(d[i-1] + tmp)

print(min(d))

Measured memory_bytes: 15520
#include <bits/stdc++.h>
//#define int long long

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    string s[3];
    REP(i, 3) cin >> s[i];
    
    REP(i, 3) cout << s[i][i];
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>

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

    int32_t N;
    std::cin >> N;
    std::vector<int32_t> A(N);
    for(auto& i : A){
        std::cin >> i;
    }

    int32_t base_cost = std::abs(A[0]);
    for(int32_t i = 1; i < N; i++){
        base_cost += std::abs(A[i] - A[i-1]);
    }
    base_cost += std::abs(A[N-1]);

    for(int32_t i = 0; i < N; i++){
        int32_t res = 0;
        if(i == 0){
            res = base_cost - std::abs(A[0]) - std::abs(A[1] - A[0]) + std::abs(A[1]);
        }
        else if(i == N - 1){
            res = base_cost - std::abs(A[i] - A[i-1]) - std::abs(A[N-1]) + std::abs(A[N-2]);
        }
        else{
            res = base_cost - std::abs(A[i] - A[i-1]) - std::abs(A[i+1] - A[i]) + std::abs(A[i+1] - A[i-1]);
        }
        std::cout << res << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdint>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int is_onechar(string S) {
    rep(i, S.size() - 1) {
        if(S[i] != S[i + 1])
            return false;
    }
    return true;
}

int main() {
    string S;
    cin >> S;
    ll K;
    cin >> K;
    if(S.size() == 1) {
        cout << K / 2 << endl;
    } else if(S.size() == 2) {
        if(S[0] == S[1]) {
            cout << K << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        if(is_onechar(S)) {
            cout << ((ll)S.size() * K) / 2 << endl;
        } else {
            ll res = 0;
            ll cnt = 1;
            vector<ll> v;
            for(int i = 0; i < S.size() - 1; i++) {
                if(S[i] == S[i + 1])
                    cnt++;
                else {
                    v.pb(cnt);
                    cnt = 1;
                }
            }
            v.pb(cnt);
            for(int i = 0; i < v.size(); i++) {
                res += K * (v[i] / 2);
            }
            if(S.front() == S.back()) {
                res -= (K - 1) * (v.front() / 2);
                res -= (K - 1) * (v.back() / 2);
                res += (K - 1) * ((v.front() + v.back()) / 2);
            }
            cout << res << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;


signed main(){
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    REP(i,n-1){
        if(s[i]!=s[i+1]){
            ans++;
            i++;
        }
    }
    print(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

ll N, M;

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

    std::cin >> N >> M;

    // if minimizing, lb satisfies lb > ub
    // if maximizing, lb satisfies lb < ub
    int64_t lb = 0, ub = 10000000000000;

    while(std::abs(ub - lb) > 1){
        int64_t mid = (lb + ub) / 2;

        bool can = true;
        if(mid * 2 > M){can = false;}
        ll rest = M - mid * 2;
        if(mid > N + rest / 2){can = false;}
        
        if(can){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    std::cout << lb << std::endl;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

int H, W;
double ex[500][500];
string vs[500];

using D = pair<double,PII>;
void bfs(PII p, VVI& dist){
  queue<PII> q;
  q.push(p);
  dist[p.FF][p.SS] = 0.;
  
  while(!q.empty()){
	p = q.front();
	q.pop();

	REP(d,4){
	  PII np(p.FF + dy[d], p.SS + dx[d]);
	  if(vs[np.FF][np.SS] != '.')
		continue;
	  int nc = dist[p.FF][p.SS] + 1;
	  if(dist[np.FF][np.SS] > nc){
		dist[np.FF][np.SS] = nc;
		q.push(np);
	  }
	}
  }
}

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

  cin >> W >> H;
  REP(y,H) cin >> vs[y];
  fill((double*)ex, (double*)ex+500*500, INF);

  PII S, G;
  vector<PII> star;
  int sum = 0;
  REP(y,H) REP(x,W){
	if(vs[y][x] == 's'){
	  vs[y][x] = '.';
	  S = MP(y,x);
	  ++sum;
	}
	else if(vs[y][x] == 'g'){
	  G = MP(y,x);
	  ++sum;
	}
	else if(vs[y][x] == '*'){
	  star.PB(MP(y,x));
	}
  }
  shuffle(ALL(star), mt19937());

  VVI dist(H, VI(W, INF));
  bfs(G, dist);

  VVI sp_dist(H, VI(W, INF));
  for(auto&& p: star)
	bfs(p, sp_dist);

  using LD = long double;
  LD lb = 0., ub = 1e15;
  REP(i,100){
	LD X = (lb + ub) / 2.;
	LD acc = 0.;
	int n = 0;
	REP(y,H) REP(x,W){
	  if(vs[y][x] == '.'){
		++n;
		if(dist[y][x] != INF){
		  if(sp_dist[y][x] != INF)
			acc += min((LD)dist[y][x], sp_dist[y][x] + X);
		  else
			acc += dist[y][x];
		}
		else
		  acc += sp_dist[y][x] + X;
	  }
	}

	if(acc / n < X)
	  ub = X;
	else
	  lb = X;
  }

  LD ans = 0.;
  if(dist[S.FF][S.SS] != INF){
	if(sp_dist[S.FF][S.SS] != INF)
	  ans += min((LD)dist[S.FF][S.SS], sp_dist[S.FF][S.SS] + lb);
	else
	  ans += dist[S.FF][S.SS];
  }
  else
	ans += sp_dist[S.FF][S.SS] + lb;
  cout << fixed << setprecision(11) << ans << endl;

  return 0;
}

Measured memory_bytes: 7152
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main() {
     
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    
     int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    set <int > s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  int ans=s.size();
  printf("%d",ans);
    
	return 0;
}

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

int N;
int v[(int)1e5];

int main() {
    cin >> N;
    rep(i, N) cin >> v[i];

    map<int, int> even_cnt, odd_cnt;

    rep(i, N) {
        if (i % 2 == 0) {
            even_cnt[v[i]]++;
        } else {
            odd_cnt[v[i]]++;
        }
    }


    vector<tuple<int, int>> v_even;
    vector<tuple<int, int>> v_odd;

    for (auto iter = even_cnt.begin(); iter != even_cnt.end(); iter++) {
        v_even.push_back(make_tuple(iter->second, iter->first));
    }

    for (auto iter = odd_cnt.begin(); iter != odd_cnt.end(); iter++) {
        v_odd.push_back(make_tuple(iter->second, iter->first));
    }

    sort(v_even.rbegin(), v_even.rend());
    sort(v_odd.rbegin(), v_odd.rend());

    int cnt = 0;

    // TOP が異なる 
    if (get<1>(v_even[0]) != get<1>(v_odd[0])) {
        cnt = get<0>(v_even[0]) + get<0>(v_odd[0]);
    } else {
        // TOP が同じ
        cnt = get<0>(v_even[0]);
        if (N > 2) {
            cnt += max(get<0>(v_even[1]), get<0>(v_odd[1])); 
        }
    } 

    cout << N - cnt << endl;
}

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

prelist = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    prelist.append((S, P, i))
    
anslist = sorted(prelist)

base_city = ''
prelist2 = []
anslist2 = []

for ans_tuple in anslist:
    city, score, position = ans_tuple[0], ans_tuple[1], ans_tuple[2]
    
    if base_city == city:
        prelist2.append((ans_tuple[1], ans_tuple[2]))
    
    elif base_city != city:
        # 処理
        base_city = city
        anslist2 = sorted(prelist2, reverse=True)
        for ans2_tuple in anslist2:
            score, position = ans2_tuple[0], ans2_tuple[1]
            print(position + 1)
            
        prelist2 = []
        anslist2 = []
        
        prelist2.append((ans_tuple[1], ans_tuple[2]))
    
#finalaize    
anslist2 = sorted(prelist2, reverse=True)
for ans2_tuple in anslist2:
    score, position = ans2_tuple[0], ans2_tuple[1]
    print(position + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main() {
    int flg = 0;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if(i %2 == 0){
            if(s[i] != 'R' && s[i] != 'U' &&s[i] != 'D') flg = 1;
        }else{
            if(s[i] != 'L' && s[i] != 'U' &&s[i] != 'D') flg = 1;
        }
    }
    if(flg) cout << "No"<< endl;
    else cout << "Yes" << endl;
    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint
{
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if (mod <= (x += a.x))
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if (mod <= (x += mod - a.x))
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        return mint(*this) += a;
    }
    mint operator-(const mint a) const
    {
        return mint(*this) -= a;
    }
    mint operator*(const mint a) const
    {
        return mint(*this) *= a;
    }
    mint pow(long long t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return *this = a.inv();
    }
    mint operator/(const mint a) const
    {
        return mint(*this) /= a;
    }
};
istream &operator>>(istream &is, const mint &a)
{
    return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a)
{
    return os << a.x;
}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    if (2 <= abs(N - M))
        cout << 0 << endl;
    else
    {
        mint ans = mint(1);
        for (long long i = 1; i <= N; i++)
        {
            ans *= i;
        }
        for (long long i = 1; i <= M; i++)
        {
            ans *= i;
        }
        if (N == M)
            ans *= 2;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
main()
{
int A,B,C;
cin >> A>>B>>C;
if(A==5&&B==5&&C==7){cout<<"YES"<<endl;}
else if(A==5&&B==7&&C==5){cout<<"YES"<<endl;}
else if(A==7&&B==5&&C==5){cout<<"YES"<<endl;}
else {cout<< "NO"<<endl;}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N, K;
  std::cin >> N >> K;

  double answer = 0.0;
  for (i64 i = 1; i <= N; ++i) {
    answer += std::pow(2, -std::max<i64>(static_cast<i64>(std::ceil(std::log2(K) - std::log2(i))), 0)) / N;
  }

  std::cout << std::fixed << std::setprecision(12) << answer << std::endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    string s;
    ll k;
    cin>>s>>k;
    int num=0;
    char ans='1';
    for(int i=0;i<s.length();i++){
        if('1'!=s[i]){
            ans=s[i];
            num=i+1;
            break;
        }
    }
    if(k<num){
        cout<<'1';
    }else{
        cout<<ans;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MOD = 1e9 + 7;
int cnt[MAXN];

int main()
{
        int n;
        cin >> n;
        for (int i = 2; i <= n; i++)
        {
                int cur = i;
                for (int j = 2; j <= i; j++)
                {
                        while (cur % j == 0)
                        {
                                cur /= j;
                                cnt[j]++;
                        }
                }
        }
        int res = 1;
        for (int i = 2; i <= n; i++)
        {
                res = (long long) res * (cnt[i] + 1) % MOD;
        }       
        cout << res << '\n';
        return 0;
}


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

int main(){
	string s;
	int n;
	cin>>n;
	cin>>s;
	int max=0,x=0;

	for(int i=0;i<s.length();i++){
		if(s[i]=='I')
			x++;
		else if(s[i]=='D')
			x--;
		if(max<x)
			max=x;
	}
	cout<<max<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int a[m][2];
    for(int i=0; i<m; ++i){
        cin >> a[i][0] >> a[i][1];
    }
    int maxl=a[0][0], minr=a[0][1];
    for(int i=0; i<m; ++i){
        if(a[i][0]>maxl) maxl = a[i][0];
        if(a[i][1]<minr) minr = a[i][1];
    }

    if((minr-maxl)<0) cout << 0;
    else cout << minr - maxl + 1;
    cout << endl;

    return 0;

}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;


ll gcd(ll a, ll b)   //Function to find gcd of two numbers
{
    if (a == 0)
    return b;
    return gcd(b % a, a);
}

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

    int n;
    cin>>n;
   
    ll ans=0;

    for(int c=1;c<=n-1;c++)
    {
        //find the factors of N
        int m = n-c;
        
        int cnt=0;

        for(int i=1;i*i<=m;i++)
        {
           if(m%i==0)
           {
               if((m/i)==i)
               cnt++;
               else
               cnt+=2;
               
           }
        }

        ans+=cnt;
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3664
# frozen_string_literal: true

k, s = gets.chomp.split(" ").map(&:to_i)
cnt = 0

(0 .. k).each do |x|
    (0 .. k).each do |y|
        c = s - x - y
        if c >= 0 && c <= k
            cnt += 1
        end
    end
end

puts cnt


Measured memory_bytes: 1788
import java.util.*

fun main(args: Array<String>) = abc157e()

fun abc157e() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val q = readLine()!!.toInt()
    val queries = (1..q).map {
        readLine()!!.split(' ').map { it }
            .let { Query(if (it[0].toInt() == 1) QueryType.UPDATE else QueryType.GET, it[1].toInt(), it[2]) }
    }

    val charToBit = LongArray(26)
    charToBit[0] = 1L
    for (i in 1..25) charToBit[i] = charToBit[i - 1] * 2

    val arr = LongArray(n)
    s.forEachIndexed { index, c -> arr[index] = charToBit[c - 'a'] }

    val st = SegmentTree(arr, Long::or)
    val answer = StringBuilder()

    for ((type, x, y) in queries) {
        when (type) {
            QueryType.UPDATE -> st[x - 1] = charToBit[y[0] - 'a']
            else -> answer.appendln(st[x - 1..y.toInt() - 1])
        }
    }

    print(answer)
}

private data class Query(val type: QueryType, val x: Int, val y: String)
private enum class QueryType { UPDATE, GET }

private class SegmentTree(init: LongArray, val monad: (Long, Long) -> Long) {
    val indices: Int
    val nodes: LongArray

    init {
        var indices = 1
        while (indices < init.size) indices = indices shl 1
        val nodes = LongArray(2 * indices - 1)
        for (i in init.indices) nodes[i + indices - 1] = init[i]
        for (i in indices - 2 downTo 0) nodes[i] = monad(nodes[2 * i + 1], nodes[2 * i + 2])
        this.indices = indices
        this.nodes = nodes
    }

    operator fun set(x: Int, value: Long) {
        var index = x + indices - 1
        nodes[index] = value
        while (index > 0) {
            index = (index - 1) / 2
            nodes[index] = monad(nodes[2 * index + 1], nodes[2 * index + 2])
        }
    }

    operator fun get(range: IntRange): Int =
        BitSet.valueOf(longArrayOf(get(range.first, range.last + 1))).cardinality()

    fun get(a: Int, b: Int, k: Int = 0, l: Int = 0, r: Int = indices): Long {
        if (r <= a || b <= l) return 0
        if (a <= l && r <= b) return nodes[k]
        return monad(
            get(a, b, 2 * k + 1, l, (l + r) / 2),
            get(a, b, 2 * k + 2, (l + r) / 2, r)
        )
    }
}


Measured memory_bytes: 94596
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  REP(i, n) { cin >> s[i]; }
  REP(i, m) { cin >> t[i]; }

  ll dp[n + 1][m + 1] = {};
  REP(i, n + 1) { dp[i][0] = 1; }
  REP(i, m + 1) { dp[0][i] = 1; }
  REP(i, n) {
    REP(j, m) {
      if (s[i] == t[j]) {

        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
      } else {
        dp[i + 1][j + 1] =
            (((dp[i + 1][j] + dp[i][j + 1]) % MOD) - dp[i][j] + MOD) % MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 31488
PROGRAM bb
      IMPLICIT NONE
      INTEGER :: a,b,c,x
      INTEGER :: alpha,beta,gamma,S,ans,piyo
      !C50 B100 A500
      
      read*,a
      read*,b
      read*,c
      read*,x
      
      piyo = x
      ans = 0
      
      
      DO alpha = 0,a
        DO beta = 0,b
          DO gamma = 0,c
            
            S = alpha*500 + beta*100 + gamma*50
            IF( S==piyo )THEN
              ans = ans + 1
            END IF
          END DO
        END DO
      END DO
      
      
      
      print'(I0)',ans
      
      
      
      
      
      
      
      
      
      
      END PROGRAM

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}


int main() {
  int n,k;
  cin >> n >> k;
  vi a(n,0);
  rep(i,n) {
    cin >> a.at(i);
  }
  int r = 1000000000;
  int l = 0;

  int c = (r+l) / 2;
  while(c!=r and c != l) {
    ll count = 0;
    rep(i,n) {
      count += ru(a.at(i),c)-1;
    }
    if(count <= k) r = c;
    else l = c;
    c = (r+l) / 2;
  }
  cout << c +1 << endl;

  return 0;
}


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

int main() {
  // Input
  int S;
  cin >> S;
  
  // Compute
  int head, foot;
  string ans;
  head = S / 100;
  foot = S % 100;
  
  if (head == 0) {
    if (foot == 0) {
      ans = "NA";
    }
    else if (foot <= 12) {
      ans = "YYMM";
    }
    else {
      ans = "NA";
    }
  }
  else if (head <= 12) {
    if (foot == 0) {
      ans = "MMYY";
    }
    else if (foot <= 12) {
      ans = "AMBIGUOUS";
    }
    else {
      ans = "MMYY";
    }
  }
  else {
    if (foot == 0) {
      ans = "NA";
    }
    else if (foot <= 12) {
      ans = "YYMM";
    }
    else {
      ans = "NA";
    }
  }
  
  // Output
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
 
        var M = array.Max();
        if ((3 * M - array.Sum()) %2 == 0)
        {
            Console.WriteLine((3 * M - array.Sum()) / 2);
        }
        else
        {
            Console.WriteLine((3 * M + 3 - array.Sum()) / 2);
        }
    }
}

Measured memory_bytes: 13652
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<algorithm>
#define ll long long
using namespace std;

int lv[320000];
struct T
{
    int x,y;
    int next;
}e[600000];
int be[320000];
int ind[320000];
int t=1;
int p[320000];
int flag[320000];

int q[300000];
int qt=0;

int n,m;

void topsort(int x)
{
    if (flag[x]==1) return;
    q[qt++]=x;
    flag[x]=1;
    for (int i=be[x]; i; i=e[i].next)
    {
        if (ind[e[i].y]==1)
         topsort(e[i].y);
        ind[e[i].y]--;
    }
}

void addedge(int tx,int ty)
{
    e[t].x=tx;
    e[t].y=ty;
    e[t].next=be[tx];
    be[tx]=t;
    t++;
}

int main()
{
    int tx,ty;
    cin>>n>>m;
    int st=0;
    for (int i=0; i<n-1+m; ++i)
    {
        scanf("%d %d",&tx,&ty);
        addedge(tx,ty);
        ind[ty]++;
    }
    for (int i=1; i<=n; ++i)
        if (ind[i]==0)
            st=i;
    topsort(st);
    for (int i=0; i<qt; ++i)
    {
        int ttx=q[i];
        for (int i=be[ttx]; i; i=e[i].next)
            if (lv[e[i].y]<lv[e[i].x]+1)
            {
                lv[e[i].y]=lv[e[i].x]+1;
                p[e[i].y]=e[i].x;
            }
    }
    for (int i=1; i<=n; ++i)
      printf("%d\n",p[i]);
    return 0;
}


Measured memory_bytes: 12928
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,m = get_nums_l()
lines = sys.stdin.readlines()

shops = [None] * n
for i,line in enumerate(lines):
    shops[i] = tuple(map(int, line.split(" ")))

shops.sort(key=lambda s:s[0])

ans = 0
i = 0
count = 0
while count < m:
    nokori = max(0, m - count)
    kau = min(nokori, shops[i][1])
    count += kau
    ans += kau * shops[i][0]
    i += 1

print(ans)

Measured memory_bytes: 26452
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair 
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
typedef unsigned long long ull;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	string c;
	cin>>c;
	for(int i=0;i<c.size()-1;i++)
	{
		if(c[i]=='A' && c[i+1]=='C')
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

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

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

    string input;
    cin >> input;

    for (size_t i = 0; i < input.length(); i++) {
        if (i % 2 == 0) {
            if (input[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (input[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<string> w(n); rep(i, n) cin >> w[i];
	set<string> st; {
		rep(i, n) st.insert(w[i]);
	}
	bool flag = true;
	for (int i = 1; i < n; ++i) {
		if (w[i - 1].back() != w[i].front()) flag = false;
	}
	if (flag && st.size() == n)  printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		int a,b,x,y;
		Scanner scan = new Scanner(System.in);
	     a = Integer.parseInt(scan.next());
		 b = Integer.parseInt(scan.next());
		if((a>=1)&&(b<=100)){
		x=a*b;
		y=(a+b)*2;
		System.out.println(x+" "+y);
		}
	}
}

Measured memory_bytes: 26084
#include<stdio.h>


int a ,b ;


#define AM a * 200
#define PM b * 300

#define SUM a + b

#define kale AM + PM



int main()
{
	int i = 9 ;
	while( i-- )
	{
		char name[ 31 ] ;

		scanf( "%s %d %d" ,name ,&a ,&b ) ;

		printf( "%s %d %d\n" ,name ,SUM ,kale ) ;
	}

	return 0 ;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<string> vs;
typedef vector<Def> vi;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;

int main(){
  string s;
  while(cin>>s,s!="."){
    int co=0;
    string t="";
    rep(i,s.size()){
      if(s[i]=='+')co++;
      else if(s[i]=='-')co--;
      else if(s[i]=='?'){
	co=0;
	t+="A";
      }else if(isalpha(s[i])){
	int c=s[i]-'A';
	c+=co;
	c+=26*1000;
	c%=26;
	t+=(char)(c+'A');
	
	co=0;
      }else t+=s[i];
    }
    loop(i,2,t.size()){
      rep(j,t.size())if(j+i<t.size()&&t[j]=='['&&t[j+i]==']'){
	string T=t.substr(j+1,i-1);
	reverse(all(T));
	t=t.substr(0,j)+T+t.substr(j+i+1);
	i--;
	break;
      }
    }
    cout<<t<<endl;
  }
}
//[[a]]



Measured memory_bytes: 3164
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    fastio();

    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < (int)s.size(); ++i){
    	ans += (s[i] - '0');
    }
   	cout << ((ans % 9 == 0) ? "Yes" : "No");
 

    return 0;
}

/*

*/

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

int main(){
    int ans[10]={0};
    for(int i=0;i<7;i++){
        int h,l;
        cin>>h>>l;
        ans[i]=h-l;
    }
    for(int i=0;i<7;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
    }

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
int v, e;
struct Edge {
  Edge() {}
  Edge(int from_, int to_, int capacity_, int rev_) : from(from_), to(to_), capacity(capacity_), rev(rev_) {}
  int from;
  int to;
  int capacity;
  int rev;
};

std::vector<Edge> edges[128];

void addEdge(int from, int to, int capacity) {
  int n1 = edges[from].size();
  int n2 = edges[to].size();
  edges[from].push_back(Edge(from, to, capacity, n2));
  edges[to].push_back(Edge(to, from, 0, n1));
}

bool checked[128];
void init_flow() {
  for(int i = 0; i < 128; ++i) {
	checked[i] = false;
  }
}
int flow(int from, int to, int v) {
  if( from == to ) return v;
  checked[from] = true;
  for(Edge& edge : edges[from]) {
	if( checked[edge.to] ) continue;
	int nv = std::min(v, edge.capacity);
	if( nv == 0 ) continue;
	int f = flow(edge.to, to, nv);
	if( f == 0 ) continue;
	edge.capacity -= f;
	edges[edge.to][edge.rev].capacity += f;
	return f;
  }
  return 0;
}

int maximum_flow(int from, int to) {
  int res = 0;
  for(;;) {
	init_flow();
	int v = flow(from, to, (1 << 30));
	if( v == 0 ) break;
	res += v;
  }
  return res;
}

int main() {
  scanf("%d %d", &v, &e);
  for(int i = 0; i < e; ++i) {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	addEdge(a, b, c);
  }

  printf("%d\n", maximum_flow(0, v - 1));

  return 0;
}

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

int main() {
	int a,b,ans=0;
	cin>>a>>b;
	if(a>b)ans=a*2-1;
	else if(a<b)ans=b*2-1;
	else ans=a+b;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256