akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	ll n;
	cin>>n;
	cout<<3.1415926*2*n<<endl;



	return 0;
}






Measured memory_bytes: 3760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] C = cin.ArrayInt(N);

        int SMAX = 200001;
        long[] stock = new long[SMAX];

        long[] dp = new long[N + 1];
        dp[0] = 1;
        long mod = 1000000007;

        for (int i = 0; i < N; i++)
        {
            dp[i + 1] = dp[i];

            if (i == 0 || C[i] != C[i - 1])
            {
                dp[i + 1] += stock[C[i]];
                dp[i + 1] %= mod;

                stock[C[i]] += dp[i];
                stock[C[i]] %= mod;
            }
        }

        Console.WriteLine(dp[N]);
    }

}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main() {
    const int num[3] = {3, 5, 7};
    int64_t n, ans = 0;
    cin >> n;
    queue<pair<int64_t, bitset<3>>> q;
    for (auto i = 0; i < 3; i++)
        q.emplace(num[i], bitset<3>(1 << (2 - i)));
    while (not q.empty()) {
        auto p = q.front();
        q.pop();
        if (p.first > n) continue;
        for (auto i = 0; i < 3; i++) {
            auto tmp = p;
            tmp.first = tmp.first * 10 + num[i];
            if (tmp.first > n) continue;
            tmp.second.set(2 - i);
            if (tmp.second.all()) ans++;
            q.push(tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 1

#define M 0
#define A 1
#define R 2
#define C 3
#define H 4

lli abs2(lli a){
	if(a>=0)return a;
	else return -a;
}

lli ans=0;

void calc(lli now,lli sum,lli selectNum,lli *data){
	if(selectNum == 3){
		ans += sum;
		return ;
	}
	if(now == 5)return;

	//次を選択するかしないか
	//する
	calc(now+1,sum*data[now],selectNum+1,data);
	calc(now+1,sum,selectNum,data);
}

int main(){

	lli n;
	cin>>n;
	lli data[5]={0};
	string str;
	REP(i,n){
		cin>>str;
		if(str.at(0)=='M'){
			data[M]++;
		}
		else if(str.at(0)=='R')data[R]++;
		else if(str.at(0)=='A')data[A]++;
		else if(str.at(0)=='C')data[C]++;
		else if(str.at(0)=='H')data[H]++;
		else;
	}
	calc(0,1,0,data);

	cout<<ans<<endl;


	return 0;
}

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

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N,K,Q;
v_ll B;
int main(){
  cin >> N >> K >> Q;
  B.assign(N+10,-Q+K);
  for (ll i=1;i<=Q;i++){
    ll a;
    cin >> a;
    B[a]++;
  }
  for (ll i=1;i<=N;i++){
    if (B[i]>0)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int n;
ll a[100000];

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

	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];

	ll total = 0, ans1 = 0, ans2 = 0;

	for(int i = 0; i < n; i++) {
		total += a[i];
		if(i % 2 == 0 && total <= 0) {
			ans1 += 1 - total;
			total = 1;
		} else if(i % 2 != 0 && total >= 0) {
			ans1 += total - (-1);
			total = -1;
		}
	}
	total = 0;
	for(int i = 0; i < n; i++) {
		total += a[i];
		if(i % 2 != 0 && total <= 0) {
			ans2 += 1 - total;
			total = 1;
		} else if(i % 2 == 0 && total >= 0) {
			ans2 += total - (-1);
			total = -1;
		}
	}
	cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	char a, b; cin >> a >> b;

	if(a == 'H'){
		if(b == 'H') cout << "H" << endl;
		else cout << "D" << endl;
	}else{
		if(b == 'H') cout << "D" << endl;
		else cout << "H" << endl;
	}

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a[MAX][MAX];
  int len[MAX];
  int a_list[n+1][n+1];

  for (int i = 0; i < n+1; i++) {
    for (int j = 0; j < n+1; j++) {
      a_list[i][j] = 0; //ゼロで初期化
    }
  }

  for (int i = 1; i < n+1; i++) {
    int index, k;
    cin >> index >> k;
    for (int j = 1; j < k+1; j++) {
      int tmp;
      cin >> tmp;
      a_list[i][tmp] = 1;
    }
  }

  for (int i = 1; i < n+1; i++) {
    for (int j = 1; j < n+1; j++) {
      if (j != 1) cout << " ";
      cout << a_list[i][j];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3116
#include<stdio.h>
int main()
{
    int N,M,A[10000],i,sum=0;
    scanf("%d%d",&N,&M);
    for(i=0;i<M;i++){
        scanf("%d",&A[i]);
        sum+=A[i];
    }
    if(N>=sum)
       printf("%d\n",N-sum);
    else
        printf("-1\n");
    return 0;
}


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

template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);

struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator << (pair<c, d> e) {
	return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator << (c a) {
	cerr << boolalpha << a;
	return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator << (c a) {
	*this << "[";
	for (auto it = a.begin(); it != a.end(); ++it)
		*this << ","[1 - (it != a.begin())] << *it;
	return *this << "]";
}
#else
template<class c> debug& operator << (c) {
	return *this;
}
#endif
};

#define aty(x) " [" << #x ": " << x << "] "

using ll = long long;




int main() {
    
    string s;
    cin >> s;
    
    int ans = 10000;
    
    for (int i = 0; i < (int) s.size() - 2; ++i)
    {
        int cur = 0;
        cur = (s[i] - '0') * 100;
        cur += (s[i + 1] - '0') * 10;
        cur += (s[i + 2] - '0');
        ans = min(ans, abs(cur - 753));
    }
    
    cout << ans;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64; 
long long const INF = 1e18 + 42;
 
 
int main(){
	fast;
	lli n,k;
	cin>>n>>k;
	vector<lli> p(n);
	double sum=0;
	for(int i=0; i<n; i++){
	    cin>>p[i];
	    if(i<k) sum+=p[i];
	}
	double maxsum=sum;
	
	for(int i=k; i<n; i++){
	    sum+=(p[i]-p[i-k]);
	    maxsum= max(maxsum, sum);
	}
	double ans=(maxsum/2.0 + k/2.0);
	cout<<fixed<<setprecision(7)<<ans<<"\n";
	return 0;
}

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


void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n,m,x;
  scanf("%d%d%d",&n,&m,&x);

  int C[n];
  int A[n][m];
  for(int i=0;i<n;i++){
    scanf("%d",&C[i]);
    for(int j=0;j<m;j++){
      scanf("%d",&A[i][j]);
    }
  }


  int ans=10000000;
  for(int bit=0;bit<(1<<n);bit++){
    int B[m];
    int price=0;
    for(int i=0;i<m;i++){
      B[i]=0;
    }

    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
        price+=C[i];
      
        for(int j=0;j<m;j++){
          B[j]+=A[i][j];
        }
      }
    }

    int can=1;
    for(int i=0;i<m;i++){
      if(B[i]<x){
        can=0;
      }
    }

    if(can==1){
      chmin(&ans,price);
    }
  }


  if(ans!=10000000){
    printf("%d\n",ans);
  }
  else{
    printf("-1\n");
  }

  return 0;
}

Measured memory_bytes: 1736
N, W = [int(i) for i in input().split()]
dp = [0] * (W + 1)
v = w = 0
for _ in range(0, N):
    v, w = [int(i) for i in input().split()]
    for j in range(W, w - 1, -1):
        if dp[j] < dp[j - w] + v:
            dp[j] = dp[j - w] + v
print(dp[W])

Measured memory_bytes: 7992
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String S = scanner.next();
        int[][] dp = new int[N+1][N+1];

        for(int i = N-1; i >= 0; i--) {
            for(int j = N-1; j >= 0; j--){
                if(S.charAt(i) != S.charAt(j)) {
                    dp[i][j] = 0;
                }else{
                    dp[i][j] = dp[i+1][j+1] + 1;
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                if(i >= j) continue;
                int now = Math.min(dp[i][j], j - i );
                ans = Math.max(ans, now);
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

struct node
{
	int sum,pos;
}a[100005];

bool cmp(node a,node b)
{
	return a.sum<b.sum;
}

int n;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].sum);
		a[i].pos=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		printf("%d ",a[i].pos);
	return 0;
}

Measured memory_bytes: 1536
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math


def main():
    a,b,c,d = getList()
    ans = min([abs(a+b-c-d), abs(a+c-b-d), abs(a+d-b-c)]
    )
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 6036
import Control.Monad
import Data.Char

main :: IO ()
main = getLine >>= main'
    where
        main' s = readLn >>= putStrLn . solve s

solve :: String -> Int -> String
solve s@(x : y : zs) k
    | k > 0 && x == 'a' = x : solve (y : zs) k
    | k > 0 && isEnough x k = 'a' : solve (y : zs) (k - ord 'z' + ord x - 1)
    | k > 0 = x : solve (y : zs) k
    | otherwise = s
    where
        isEnough c n = ord 'z' - ord c + 1 <= n
solve (y : _) k
    | k > 0 && m <= ord 'z' - ord y = [chr $ m + ord y]
    | k > 0 = [chr $ ord 'a' + m - ord 'z' + ord y - 1]
    | otherwise = [y]
    where
        m = k `mod` 26


Measured memory_bytes: 5116
using System;
using System.Linq;
using System.Collections.Generic;

namespace KEYENCE2020
{
    class C
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];
            long S = input[2];
            long[] res = new long[N];
            long Max = 1000000000;

            for (long i = 0; i < K; i++)
            {
                res[i] = S;
            }

            for (long i = K; i < N; i++)
            {
                if (S == Max) res[i] = Max - 1;
                else res[i] = S + 1;
            }
            Console.WriteLine(string.Join(" ", res));
        }
    }
}


Measured memory_bytes: 23644
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a*100+b*10+c)%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

num = 0
for i in range(0,A+1):
    for ii in range(0,B+1):
        for iii in range(0,C+1):
            t = i*500 + ii*100 + iii*50
            if t ==X:
                num+=1
print(num)

Measured memory_bytes: 3064
import itertools

n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    t=list(map(int,input().split()))
    c.append(t[0])
    a.append(t[1:])

ans=float('inf')

def j(q):
    tmp=0
    cnt=[0]*m
    for i in range(n):
        if q[i]==1:
            tmp+=c[i]
            for j in range(m):
                cnt[j]+=a[i][j]
    if min(cnt)>=x:
        return tmp
    return 0

for tk in itertools.product([0,1],repeat=n):
    h=list(tk)
    ff=j(h)
    if ff!=0:
        ans=min(ans,ff)
if ans==float('inf'):
    print(-1)
    exit()
print(ans)


Measured memory_bytes: 9160
W, H, N = map(int, input().split())
xya = [''] * N
for i in range(N):
    xya[i] = list(map(int, input().split()))

h, w = H, W
x0, y0 = 0, 0
ans = 1

for i in range(N):
    if xya[i][2] == 1:
        if xya[i][0] <= w:
            x0 = max(xya[i][0], x0)
        else:
            ans = 0
    elif xya[i][2] == 2:
        if x0 <= xya[i][0] and xya[i][0] <= w:
            w = xya[i][0]
        elif xya[i][0] < x0:
            ans = 0
    elif xya[i][2] == 3:
        if xya[i][1] <= h:
            y0 = max(xya[i][1], y0)
        else:
            ans = 0
    else:
        if y0 <= xya[i][1] and xya[i][1] <= h:
            h = xya[i][1]
        elif xya[i][1] < y0:
            ans = 0
if ans != 0:
    ans = (w - x0) * (h - y0)
print(ans)

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, M, ans=0, tmp=0;
vector<ll> A, color, Bs;
vector<vector<ll>> G, As;

void bfs(ll st, ll id) {
    queue<ll> Q;
    color[st] = id;
    Q.push(st);
    while(!Q.empty()) {
        ll u = Q.front();
        Q.pop();
        for(int i=0;i<G[u].size();i++) {
            if(color[G[u][i]]!=-1) continue;
            color[G[u][i]]=id;
            Q.push(G[u][i]);
        }
    }
}

signed main(){
    cin >> N >> M;
    G.resize(N);
    color.resize(N,-1);
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    for(int i=0;i<M;i++) {
        ll x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for(int i=0;i<N;i++) {
        if(color[i]==-1) {
            bfs(i, tmp);
            tmp++;
            vector<ll> vemp;
            As.push_back(vemp);
        }
        As[color[i]].push_back(A[i]);
    }
    //cout << "OK" << endl;
    for(int i=0;i<tmp;i++) {
        sort(As[i].begin(), As[i].end());
        if(tmp!=1) ans += As[i][0];
        for(int j=1;j<As[i].size();j++) {
            Bs.push_back(As[i][j]);
        }
    }
    //cout << "OK" << endl;
    sort(Bs.begin(), Bs.end());
    if(2*(tmp-1)>N) {
        cout << "Impossible" << endl;
    }
    else {
        for(int i=0;i<tmp-2;i++) {
            ans += Bs[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 13644
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include<time.h>
using namespace std;
typedef long long ll;
const int MAXN=200000+10;
struct edge{
    int v,next;
}e[MAXN<<1];
int tot=0;
int head[MAXN];
int c[MAXN];
ll sum[MAXN];
ll son[MAXN];
ll res[MAXN];
void add(int u,int v){
    e[tot].v=v;
    e[tot].next=head[u];
    head[u]=tot++;
}

void dfs(int u,int p){
    son[u]=1;
    ll y=sum[c[u]];
    ll x=sum[c[u]];
    for(int k=head[u];k!=-1;k=e[k].next){
        int v=e[k].v;
        if(v!=p){
            dfs(v,u);
            son[u]+=son[v];
            ll temp=son[v]-sum[c[u]]+x;
            res[c[u]]+=(temp-1)*temp/2+temp;
           // cout<<c[u]<<" "<<(temp)<<" "<<(temp-1)*temp/2+1<<endl;
            x=sum[c[u]];
        }
    }
    sum[c[u]]+=son[u]-(sum[c[u]]-y);
}
 
int vis[MAXN];
void init(){
    memset(head,-1,sizeof(head));
    memset(sum,0,sizeof(sum));
    memset(vis,0,sizeof(vis));
    tot=0;
}
int main(){
    int cas=1;
    int n;
    //freopen("1003.in","r",stdin);
    while(scanf("%d",&n)!=EOF){
        ll cnt=0;
        init();
        for(int i=1;i<=n;i++){
            scanf("%d",c+i);
            if(!vis[c[i]]){
                cnt++;
                vis[c[i]]=1;
            }
        }
        for(int i=0;i<n-1;i++){
            int u,v;
            scanf("%d%d",&u,&v);
            add(u,v);
            add(v,u);
        }
        dfs(1,0);
     	
        for(int i=1;i<=n;i++){
            if(vis[i]){
                ll temp=n-sum[i];
          //      cout<<i<<" "<<temp<<endl;
                if(temp)
                res[i]+=temp*(temp-1)/2+temp;
            }
        }
        //cout<<n*(n-1)/2+n<<" "<<res[1]<<endl;
        for(int i=1;i<=n;i++)
        if(vis[i]) 
        printf("%lld\n",1ll*n*(n-1)/2+n-res[i]);
        else printf("0\n");
    }
}

Measured memory_bytes: 32608
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();
      
      long num = (c - a - b);
      long cur = 0;
      long cnt = 4;
      for(long i = 1; i <= num; i++) {
          cur += num;
          if(cur >= a * b && cnt > 0) {
            cur -= a*b;
            cnt--;
          }
      }
      if(cur > 0 && cnt == 0)
        System.out.println("Yes");
      else
        System.out.println("No");
  }
}


Measured memory_bytes: 22608
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in();
    ll sumnow=0;
    map<ll,ll>cnt;
    for(ll i=0;i<n;++i){
        ll ai=in();
        sumnow+=ai;
        ++cnt[ai];
    }
    ll q=in();
    for(ll i=0;i<q;++i){
        ll b=in(),c=in();
        cout<<(sumnow+=cnt[b]*(c-b))<<endl;
        cnt[c]+=cnt[b];
        cnt[b]=0;
    }
}


Measured memory_bytes: 9544
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n, k; cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    ll ans = 0;
    rep(i,n) {
        ans += min(x[i], abs(k-x[i])) * 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile(" ");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 180584
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
a = [(num,i) for i,num in enumerate(a)]
a.sort(reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
for i in range(n+1):
    for j in range(n-i+1):
        if i>0:
            dp[i][j] = max(dp[i][j], dp[i-1][j] + a[i+j-1][0]*abs(a[i+j-1][1]-(i-1)))
        if j>0:
            dp[i][j] = max(dp[i][j], dp[i][j-1] + a[i+j-1][0]*abs(a[i+j-1][1]-(n-j)))
ans = max(dp[i][n-i] for i in range(n+1))
print(ans)

Measured memory_bytes: 105952
#include <iostream>

using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int cnt = 0;
	int passed = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'b')
			cnt++;
		if (s[i] == 'c')
			cout << "No\n";
		else if (s[i] == 'a' && passed < a + b)
		{
			passed++;
			cout << "Yes\n";
		}
		else if (s[i] == 'b' && passed < a + b && cnt <= b)
		{
			passed++;
			cout << "Yes\n";
		}
		else
			cout << "No\n";
	}
}


Measured memory_bytes: 896
class UnionFind
  def initialize(n); @data = Array.new(n,-1); end
  def find(a); @data[a] < 0 ? a : @data[a] = find(@data[a]); end
  def same?(a,b); find(a) == find(b); end
  def size(a); -@data[find(a)]; end
  def unite(a,b)
    a = find(a); b = find(b)
    return if a == b
    a,b = b,a if @data[a] > @data[b]
    @data[a] += @data[b]; @data[b] = a
  end
end

# UnionFind.new(N) := 要素数Nで初期化
# Ai := i番目の要素
# find(i) := Aiが属するグループ
# same?(i,j) := Ai,Ajが同じグループに属する
# size(i) := Aiが属するグループの要素の数
# unite(i,j) := Ai,Ajを同じグループに統合する

n,m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).map{|v|v-1}

uf = UnionFind.new(n)
m.times do
  x,y = gets.split.map(&:to_i)
  x -= 1; y -= 1
  uf.unite(x,y)
end

ans = 0
n.times do |i|
  ans += 1 if uf.same?(a[i],i)
end

puts ans

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9

int main(){

    int n;
    cin >> n;

    int ans=0, tmp=n;
    while(tmp>1000){
        tmp -= 1000;
    }
    ans = 1000- tmp;


    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3632
N, M = map(int, input().split())
ablist = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])
broken = 0
ans = 0
for a, b in ablist:
    if a > broken:
        ans += 1
        broken = b - 1
print(ans)


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

#define		mins(a, b)	a = min(a, b)		//min_self
#define		maxs(a, b)	a = max(a, b)		//max_self


typedef long long ll;

const ll INF = 1e18L+5;

int main(){
	ll n, cap;
	scanf("%lld %lld", &n, &cap);	
	vector <ll> w(n);
	vector <ll> v(n);
	ll max_val = 0;
	for (int i = 0; i < n; ++i){
		scanf("%lld %lld", &w[i], &v[i]);
		max_val += v[i];
	}

	vector <ll> dp(max_val+1, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i){
		for (int j = max_val-v[i]; j >= 0; --j){
			mins(dp[j+v[i]], dp[j]+w[i]);
		}
	}
	ll ans = 0;
	for (int i = 0; i <= max_val; ++i){
		if(dp[i] <= cap)
			maxs(ans, (ll)i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int
main()
{
    int h, w, d;
    assert(scanf("%d %d %d", &h, &w, &d) == 3);
    int *num2x = new int[h * w + 1];
    int *num2y = new int[h * w + 1];
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int num;
            assert(scanf("%d", &num) == 1);
            num2x[num] = x;
            num2y[num] = y;
        }
    }

    vector<vector<unsigned int> > cumpower(d+1);
    for (int rem = 1; rem <= d; rem++) {
        unsigned int power = 0;
        cumpower[rem].push_back(0);
        for (int i = rem; i <= h * w - d; i += d) {
            int x1 = num2x[i], y1 = num2y[i];
            int x2 = num2x[i + d], y2 = num2y[i + d];
            power += abs(x2 - x1) + abs(y2 - y1);
            cumpower[rem].push_back(power);
        }
    }

    int q;
    assert(scanf("%d", &q) == 1);
    unsigned int *ans = new unsigned int[q];
    for (int i = 0; i < q; i++) {
        unsigned int power = 0;
        int start, end;
        assert(scanf("%d %d", &start, &end) == 2);
        int rem = (start - 1) % d + 1;
        power = cumpower[rem][(end - 1) / d] -
            cumpower[rem][(start - 1) / d];
        ans[i] = power;
    }
    for (int i = 0; i < q; i++)
        printf("%u\n", ans[i]);
}


Measured memory_bytes: 6400
#include <iostream>

using namespace std;

int main()
{
    int n,d,flag=0;
    char a[100+10];
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    d=n/2;
    for(int i=1; i<=n/2; i++)
    {

        if(a[i]==a[i+d])
            flag=1;
        else
        {
            flag=0;
            break;
        }
    }
    if(flag==0||n%2!=0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        max_n = min(num_v, B)
        for i in range(A, max_n + 1):
            ans += math.factorial(num_v) // math.factorial(num_v - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= math.factorial(num_cnt) \
                           // math.factorial(num_cnt - cnt) \
                           // math.factorial(cnt)
        print(max_avg_ptn)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <algorithm>
#include <list>
#include <cmath>
#include <cassert>
#include <deque>
#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>

using namespace std;

typedef int64_t ll;
typedef long double ld;
typedef pair<int, int> pii;

const int SZ = 1000000 + 100;

ll n, k;

int solve() {
    cin >> n >> k;
    ll ans = 0;
    while (n > 0) {
        ++ans;
        n /= k;
    }
    cout << ans;

    return 0;
}

int main() {
    ios_base::sync_with_stdio(false);

    //freopen("input.txt", "r", stdin);

    solve();

    return 0;
}


Measured memory_bytes: 256
//Saurabhsahab
#include<bits/stdc++.h>
#define ll long long 
#define mod 1000000007
#define pb push_back
#define  V vector<ll>
#define lcm(x,y) boost::math::lcm(x,y)
#define f(i,s,n) for(ll i=s;i<n;i++)
#define f1(i,s,n) for(ll i=s;i>n;i--)
#define T ll t ; cin>>t; while(t--)
using namespace std ;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll x,s=0;
    cin>>x;
    ll m=100;
    while(m<x){
        m=m+((m*1)/100);
        s++;
    }
    cout<<s;
}

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

int main() {
  string s; cin>>s;
  int n=s.size();
  int a=0,b=0,c=0;
  rep(i,n){
    if(s.at(i)=='a'){a++;}
    if(s.at(i)=='b'){b++;}
    if(s.at(i)=='c'){c++;}
  }
  int maximum = max(max(a,b),c);
  int minimum = min(min(a,b),c);
  if(maximum - minimum <=1){cout<<"YES";}
  else{cout<<"NO";}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
long long counter;
counter=0;
long long N,x;
cin>>N>>x;
long long a[x];
for(long long i=0;i<x;i++){
   cin>>a[i];}
counter=a[1]-a[0];
for(long long i=0;i<x-1;i++){
 counter=max(counter,a[i+1]-a[i]);}
counter=max(counter,N-a[x-1]+a[0]);
 cout<<N-counter<<endl;}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
struct Node
{
	int value;
   Node* prev,* next;
};
Node* head;
void Init()
{
    head=(Node*)malloc(sizeof(Node));
    head->next=head;
    head->prev=head;
}

Node* FindNode(int x)
{
	Node*temp=head->next;
	while(temp!=head&&temp->value!=x)
        temp=temp->next;
    return temp;
}
void Insert(int x)
{
	Node*temp=(Node*)malloc(sizeof(Node));
    temp->value=x;
    head->next->prev=temp;
    temp->next=head->next;
    head->next=temp;
    temp->prev=head;
}

void Delete(Node*temp)
{
	if(temp==head)
        return ;
	temp->next->prev=temp->prev;
	temp->prev->next=temp->next;
    //free(temp);
}

void DeleteFirst()
{
    Delete(head->next);
}
void DeleteLast()
{
	Delete(head->prev);
}
/*
void PrintList()
{
    /*
    Node*temp=head->next;
    int flag=0;
    while(1)
    {
        if(temp==head)
            break;
        else
        {
            if(flag++>0)
                printf(" ");
            printf("%d",temp->value);
            temp=temp->next;
        }
    }
    printf("\n");
    
     Node* temp=head->next;
    while(temp->next!=head)
    {
        printf("%d ",temp->value);
        temp=temp->next;
    }
    printf("%d\n",temp->value);
}
*/
int main()
{
	int n;
	scanf("%d",&n);
	char str[12];
	int x;
	Init();
    
	while(n--)
	{
		scanf("%s",str);
		if(str[0]=='i'){scanf("%d",&x);Insert(x);}
		else if(str[0]=='d'&&str[6]=='F')DeleteFirst();
		else if(str[0]=='d'&&str[6]=='L')DeleteLast();
		else if(str[0]=='d'){scanf("%d",&x);Delete(FindNode(x));}
	}
    
    /*
	for(i = 0; i < n; i++) {
        scanf("%s %d", str, &x);
        if (str[0] == 'i') {
            Insert(x);
        }
        else if(str[0] == 'd') {
            if(str[6] == 'F')
                DeleteFirst();
            else if(str[6] == 'L')
                DeleteLast();
            else
                //DeleteValue(x);
                Delete(FindNode(x));
        }
    }
    */
    Node* temp=head->next;
    while(temp->next!=head)
    {
        printf("%d ",temp->value);
        temp=temp->next;
    }
    printf("%d\n",temp->value);
    
    //PrintList();
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    ll ans = 0;
    
    rep(i,n){
        while(a[i]%2==0){
            a[i] /= 2;
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#include <bits/stdc++.h>
#define debug(...)
#endif

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    int N, R;
    scan(N, R);
    if (10 <= N) {
        print(R);
    } else {
        print(R + (100 * (10 - N)));
    }

    return 0;
}

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int N; cin>>N;
	ll level[N + 1], patties[N + 1];
	level[0] = patties[0] = 1;
	for(int i = 1; i <= N; i++){
		level[i] = 2*level[i - 1] + 3;
		patties[i] = 2*patties[i - 1] + 1;
	}
	ll X; cin>>X;
	ll ans = 0;
	for(int i = N; i >= 0; i--){
		if(i == 0){
			if(X >= 1)ans++;
		}else{
			if(X <= 1 + level[i - 1]){
				X--;
				continue;
			}else{
				ans += 1 + patties[i - 1];
				X -= 2 + level[i - 1];
			}
		}
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
    int a, b; cin >> a >> b;
    int d = a + b;
    if (d >= 24) {
        d -= 24;
    }
    cout << d << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
char f( char c ){ 
  if( 'a' <= c && c <= 'z' ) return c - 'a' + 'A';
  return c;
}
int main( void )
{
  string s;
  while( 1 ){
    getline( cin, s );
    if( cin.eof() ) break;
    transform( s.begin(), s.end(), s.begin(), f );
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b; cin>>a>>b;
    cout<<a-b+1<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_int_tuple() -> (i32, i32) {
    let v: Vec<i32> = read_vec();
    (v[0], v[1])
}

struct Store {
    price: i64,
    amount: i64
}

fn main() {
    let (N, M) = read_int_tuple();
    let N = N as usize;
    let mut M = M as i64;
    let mut stores = Vec::new();
    for _ in 0..N {
        let (A, B) = read_int_tuple();
        stores.push(Store {
            price: A as i64,
            amount: B as i64
        });
    }
    stores.sort_by(|a, b| a.price.cmp(&b.price));
    let mut ans: i64 = 0;
    for store in stores {
        if store.amount > M {
            ans += (store.price * M);
            break;
        } else {
            ans += store.price * store.amount;
            M -= store.amount;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, d, a;
  cin >> n >> d >> a;
  vector<pair<ll, ll>> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  vector<ll> sum(n+1);
  ll ans = 0, idx = 0;
  rep (i, n) {
    ll num = max((p[i].second-sum[i]+a-1)/a, 0LL);
    ans += num;
    while (idx < n && p[idx].first <= p[i].first+d*2)
      idx++;
    sum[idx] -= num*a;
    sum[i+1] += sum[i]+num*a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main(){
  int n,k; cin >> n >> k;
  string s; cin >> s;
  int count=0; // 幸福な人の数
  for(int i=0;i<n-1;++i){
    if(s[i]==s[i+1]) count++;
  }
  cout << min(count+2*k, n-1) << endl; // 1回の操作で2人幸福な人を増やせる.n-1が限界値.
  return 0;
}

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

int main() {
  string s;
  cin >>s;
  int n=s.size();
    for (int i=0;i<=(n-3)/2;i++){
      
      if (s[i]!=s[n-1-i]){
        cout <<"No"<<endl;
        return 0;
      }
      
      if (s[i]!=s[(n-3-2*i)/2]){
        cout <<"No"<<endl;
        return 0;
      }
      
      if (s[n-1-i]!=s[(n+1+2*i)/2]){
        cout <<"No"<<endl;
        return 0;
      }
      
    }
    cout << "Yes"<<endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
from1 = set()
ton = set()
for i in range(M):
  l,r = map(int,input().split())
  if l == 1:
    from1.add(r)
  if r == N:
    ton.add(l)
if len(from1&ton) > 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 19024
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(const std::vector<long>& values)
{
  long result = 1;
  for (auto v : values) {
    if (1000000000000000000 / v < result) return -1;
    result *= v;
  }
  return result;
}

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

  std::vector<long> values(n);
  for (auto& v : values) {
    std::cin >> v;
    if (v == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  std::cout << std::setprecision(20);
  std::cout << solve(values) << std::endl;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int ANS[100000];

int main()
{

	string S;
	cin >> S;

	vec(P)
	fx(S.size()-1) {
		if (S.at(x) != S.at(x + 1)) {
			pb(P,x)
		}
	}
	int index = 0;
	int x = 0;
	while (x<S.size()) {

		if (S.at(x) == 'L') {
				int y = abs(P.at(index) - x);
				if (y % 2 == 0) {
					ANS[P.at(index)]++;
				}
				else {
					ANS[P.at(index) + 1]++;
				}
				x++;

		}
		else {
			if (x <= P.at(index)) {
				int y = P.at(index) - x;
				if (y % 2 == 0) {
					ANS[P.at(index)]++;
				}
				else {
					ANS[P.at(index) + 1]++;
				}
				x++;
			}
			else {
				index++;
			}
		}

	}
	fx(S.size()) {
		cout << ANS[x] << ' ';
	}	
    return 0;
}



Measured memory_bytes: 1528
#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
int main()
{
	int a = 0;
	int b = 0;
	for(int i=0;i<3;i++)
	{
		char t;
		cin>>t;
		if(t=='A') a++;
		else b++;
	}
	if(a==0||b==0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	 
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, int> pdd;

const ll mod = 23333333333333333;
const int N = 1e8 + 10, M = 1e5 + 10;
const ll INF = 5e17;
const int inf = 0x3f3f3f3f;
const double eps = 1e-4;

#define pi acos(-1)
#define mk make_pair

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll res = 0;
    int cnt = 0;
    if (n < b)
    {
        cout << a * n / b << endl;
    }
    else
    {
        cout << a * (b - 1) / b << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
using namespace std;


int main() {
	int N, Y;

	cin >> N >> Y;
	for (int x = 0; x <= N; x++) {
		for (int y = 0; y <= N - x; y++) {
			int z = N - x - y;
			if (x * 10000 + y * 5000 + z * 1000 == Y) {
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}
	cout << "-1" << " " << "-1" << " " << "-1" << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

    string ans = "No";
    if (a == b && a != c)
        ans = "Yes";
    else if (a == c && a != b)
        ans = "Yes";
    else if (b == c && b != a)
        ans = "Yes";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256