akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace ConsoleApp1AtCoder_Beginner_Contest_132
{
    class Program
    {
        public const int Mod7 = 1000000007;
        //配列にする
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        //Listにする
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var cmb = new Combination(2010);
            var ans1 = cmb.com((int)(2 + N - K - 1), (int)(N - K));
            WriteLine(ans1 % Mod7);
            for (var i = 2; i <= K; ++i)
            {
                long k1Ci1 = cmb.com((int)(K - 1), (int)(i - 1));
                long i1Hnki1 = cmb.com((int)(i - 1 + N - K - (i - 1) - 1), (int)(N - K - (i - 1)));
                long iHnki1 = cmb.com((int)(i + N - K - i - 1), (int)(N - K - i));
                long k2Ci2 = cmb.com((int)(K - 1), (int)(i - 1));
                long i1Hnkip1 = cmb.com((int)(i + 1 + (N - K - (i + 1)) - 1), (int)(N - K - (i + 1)));
                var ans = (k1Ci1 * i1Hnki1) % Mod7 + (2 * k1Ci1 * iHnki1) % Mod7 + (k2Ci2 * i1Hnkip1) % Mod7;
                ans %= Mod7;
                WriteLine(ans);
            }
        }
        //組み合わせ
        public class Combination
        {
            readonly long mod;
            readonly long[] fac, finv, inv;
            public Combination(long n, long mod = 1000000007)
            {
                long max = n + 1;
                this.mod = mod;
                fac = new long[max];
                finv = new long[max];
                inv = new long[max];
                fac[0] = fac[1] = 1;
                finv[0] = finv[1] = 1;
                inv[1] = 1;
                for (int i = 2; i < max; ++i)
                {
                    fac[i] = fac[i - 1] * i % mod;
                    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
                    finv[i] = finv[i - 1] * inv[i] % mod;
                }
            }
            public long com(int n, int k)
            {
                if (n < k) return 0;
                if (n < 0 | k < 0) return 0;
                return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
            }
        }

    }
}


Measured memory_bytes: 13340
#include <bits/stdc++.h>
using namespace std;
int main(){
  double N, count;
  cin >> N;
  double ans;
  for ( int i = 1; i<N+1; i++){
    if ( i%2 == 1 ) count++;
  }
  cout << fixed << setprecision(10);
  cout << count/N << endl;
}

Measured memory_bytes: 256
n,k,q = gets.split.map(&:to_i)
point = Array.new(n,0)
for i in 1..q
  point[(gets.to_i)-1] += 1
end
for i in 0..n-1
  if point[i] > q-k
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 3196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

bool toshi_hikaku(pair<int, pair<ll,ll>> x, pair<int, pair<ll,ll>> y) {
    return x.second.first < y.second.first;
}

bool index_hikaku(pair<int, pair<ll,ll>> x, pair<int, pair<ll,ll>> y) {
    return x.first < y.first;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    vector<pair<int, pair<ll,ll>>> countries;
    rep(i,m)
    {
        ll p,y;
        cin >> p >> y;
        pair<ll,ll> pr = make_pair(y,p);
        pair<int, pair<ll,ll>> pp = make_pair(i, pr);
        countries.push_back(pp);
    }
    sort(countries.begin(), countries.end(), toshi_hikaku);

    map<ll,ll> mp;
    rep(i,n) mp[i] = 0;
    ll ans[m];
    rep(i,m)
    {
        mp[countries[i].second.second]++;
        ans[countries[i].first] = mp[countries[i].second.second];
    }

    sort(countries.begin(), countries.end(), index_hikaku);

    rep(i,m)
    {
        cout << setw(6) << setfill('0') << countries[i].second.second;
        cout << setw(6) << setfill('0') << ans[i] << endl;
    }
}


Measured memory_bytes: 11504
N = int( input())
S = []
Sum = 0
for _ in range(N):
    s = int( input())
    Sum += s
    S.append(s)
S.sort()
ans = 0
if Sum%10 == 0:
    for s in S:
        if s%10 != 0:
            ans = Sum - s
            break
else:
    ans = Sum
print(ans)

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s; cin >> s;
	int q,ind,f; char ch;
	cin >> q;
	bool r=0;
	while(q--){
		cin >> ind;
		if(ind==1){
			r=1-r;
		}else{
			cin >> f >> ch;
			if(f==1){
				if(!r)s.insert(s.begin(),ch);
				else s+= ch;
			}else{
				if(!r)s+=ch;
				else s.insert(s.begin(),ch);
			}
		}
	}
	if(r)reverse(all(s));
	cout << s << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 912
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void)
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2; 
	
	double x = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
	
	double y = sqrt(x);
	
	printf("%.4f\n", y);
	//cout << y << endl;
	
	return 0;
}

Measured memory_bytes: 3256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		Long[] arr=new Long[n];
		for(int i=0;i<n;i++){
			arr[i]=in.nextLong();
		}
		Arrays.sort(arr);
		long ans=0;
		for(int i=0;i<k;i++){
			ans+=arr[i];
		}
		System.out.print(ans);
	}
}

Measured memory_bytes: 38896
#include<iostream>
#define INF 1000000000
using namespace std;

struct Card {
	char suit;
	int num;
};

void merge(Card a[], int left, int mid, int right);
void mergeSort(Card a[], int left, int right);
int partition(Card a[], int p, int r);
void quickSort(Card a[], int p, int r);
bool isStable(Card a[], Card b[], int n);


int main() {
	int i, j, n;
	Card c1[100000], c2[100000];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> c1[i].suit >> c1[i].num;
		c2[i] = c1[i];
	}
	quickSort(c1, 0, n - 1);
	mergeSort(c2, 0, n);
	if (isStable(c1, c2, n) == true)cout << "Stable\n";
	else cout << "Not stable\n";
	for (i = 0; i < n; i++) {
		cout << c1[i].suit << " " << c1[i].num << endl;
	}
	return 0;
}

int partition(Card a[], int p, int r) {
	int i, j, x;
	x = a[r].num;
	i = p - 1;
	for (j = p; j < r; j++) {
		if (a[j].num <= x) {
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i + 1], a[r]);
	return i + 1;
}

void quickSort(Card a[], int p, int r) {
	int q;
	if (p < r) {
		q = partition(a, p, r);
		quickSort(a, p, q - 1);
		quickSort(a, q + 1, r);
	}
}

void merge(Card a[], int left, int mid, int right) {
	int i, j, k, n1, n2;
	Card l[50001], r[50001];
	n1 = mid - left;
	n2 = right - mid;
	for (i = 0; i < n1; i++) {
		l[i] = a[left + i];
	}
	for (i = 0; i < n2; i++) {
		r[i] = a[mid + i];
	}
	l[n1].num = INF;
	r[n2].num = INF;
	i = 0;
	j = 0;
	for (k = left; k < right; k++) {
		if (l[i].num <= r[j].num) {
			a[k] = l[i];
			i++;
		} else {
			a[k] = r[j];
			j++;
		}
	}
}

void mergeSort(Card a[], int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(a, left, mid);
		mergeSort(a, mid, right);
		merge(a, left, mid, right);
	}
}

bool isStable(Card a[], Card b[], int n) {
	int i;
	for (i = 0; i < n; i++) {
		if (a[i].suit != b[i].suit || a[i].num != b[i].num)return false;
	}
	return true;
}

Measured memory_bytes: 5420
x1,y1,x2,y2=gets.split.map{|n|n.to_i}
x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)

printf("%d %d %d %d\n",x3,y3,x4,y4)


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(void){
    
    int D;
    
    cin >> D;
    
    if (D == 25) {
        cout << "Christmas";
    }
    else if (D == 24){
         cout << "Christmas Eve";
    }
    else if (D == 23){
        cout << "Christmas Eve Eve";
        }
        else if (D == 22){
        cout << "Christmas Eve Eve Eve";
        }
        else {
            cout << "";
        }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

int main()
{
	fastIO;
	int h, w; cin >> h >> w;
	int ch, cw; cin >> ch >> cw; ch--, cw--;
	int dh, dw; cin >> dh >> dw; dh--, dw--;
	vs s(h);
	vector<vi> path(h,vector<int>(w,-1));

	for(int i = 0; i < h; i++) cin >> s[i];
	path[ch][cw] = 0;

	priority_queue <pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> q;
	q.push({0,{ch,cw}});

	while(!q.empty())
	{
		int a = q.top().s.f;
		int b = q.top().s.s;
		int v = q.top().f;
		q.pop();

		for(int i = -2; i <= 2; i++)
			for(int j = -2; j <= 2; j++)
			{
				int x = a + i;
				int y = b + j;

				if(!i && !j || x < 0 || y < 0 || x >= h || y >= w || s[x][y] == '#') continue;

				if(abs(i) + abs(j) == 1 && (path[x][y] == -1 || path[x][y] > path[a][b])) path[x][y] = path[a][b], q.push({path[x][y],{x,y}});
				else if(path[x][y] == -1 || path[x][y] > path[a][b] + 1) path[x][y] = path[a][b] + 1, q.push({path[x][y],{x,y}});
			}
	}

	cout << path[dh][dw] << endl;

	return 0;
}

Measured memory_bytes: 8740
// ਅਗਮਜੋਤ ਸਿੰਘ
// AGAMJOT SINGH

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// a_gamer

int power(int x, unsigned int y, int p) { 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
  
int max(int a, int b){
    if (a > b)
        return a;
    else
        return b;
}
int maxSubArraySum(vector<int> &v){
    int size = v.size();
    int max_so_far = 0, max_ending_here = 0;
    int a[size];
    for (int i = 0; i < size; i++)
    {
        a[i] = v[i];
    }
    for (int i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_ending_here < 0)
            max_ending_here = 0;
        else if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;
    }
    return max_so_far;
}
int NcR(int n, int r) { 
   
    long long p = 1, k = 1;  
    if (n - r < r) 
        r = n - r;  
    if (r != 0) {   
        while (r) { 
            p *= n; 
            k *= r;  
            long long m = __gcd(p, k);  
            p /= m; 
            k /= m;  
            n--; 
            r--; 
        }  
    }  
    else
        p = 1;  
    return p; 
}

signed main(){ 
    fastio;
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i] >> c[i];
    } 
    int umax[n],mmax[n],lmax[n];
    for(int i=0;i<n;i++){
        if(i == 0){
            umax[i] = a[i];
            mmax[i] = b[i];
            lmax[i] = c[i];
        }
        else{
            umax[i] = a[i] +  max(lmax[i-1] , mmax[i-1]);
            mmax[i] = b[i] +  max(lmax[i-1] , umax[i-1]);
            lmax[i] = c[i] +  max(umax[i-1] , mmax[i-1]);
        } 
    }
    cout << max(umax[n-1], max(lmax[n-1] , mmax[n-1]));
}

Measured memory_bytes: 4992
N, M = map(int, input().split())
AB=[]
for _ in range(N):
    AB.append(list(map(int, input().split())))
#print(N, M, AB)

bill=0
num=0
AB=sorted(AB, key=lambda val:val[0])
#print(AB)
for i in range(N+1):
    if num<M:
        num+=AB[i][1]
        bill+=AB[i][0]*AB[i][1]
        #print(num, bill)
    else:
        bill=bill-(num-M)*AB[i-1][0]
        print(bill)
        break



Measured memory_bytes: 29792
#include<iostream>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
int n, sum, k, p, a[123456], b[123456];
signed main() {
	cin >> n;
	k = n * (n + 1) / 2;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
		p += sum / k;
		sum %= k;
		if (i)b[i] = a[i - 1] - a[i];
	}
	b[0] = a[n - 1] - a[0];
	if (sum != 0) {
		cout << "NO\n";
		return 0;
	}
	k = p; p = 0;
	for (int i = 0; i < n; i++) {
		b[i] += k;
		if (b[i] % n != 0 || b[i] < 0) {
			cout << "NO\n";
			return 0;
		}
		p += b[i] / n;
	}
	cout << (p == k ? "YES\n" : "NO\n");
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);++i)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;--i)
#define FOR(i,s,n) for(int i = s;i < (int)n;++i)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;--i)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline void out(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
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;}
constexpr int INF = 1e18;
 
 
int MOD;
 
long long mod_pow(long long x, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}
 
long long mod_inv(long long x)
{
	return mod_pow(x, MOD - 2);
}
 
//mod_inv(x)でxの逆元をとれる
 
signed main(){
	int N;
	string s;
	cin >> N >> MOD >> s;
	if(MOD == 2){
		int ans = 0;
		REP(i,N){
			if((s[i] - '0') % 2 == 0)ans += i + 1;
		}
		out(ans);
		return 0;
	}
	if(MOD == 5){
		int ans = 0;
		REP(i,N){
			if((s[i] - '0') == 0 || (s[i] - '0') == 5)ans += i + 1;
		}
		out(ans);
		return 0;
	}
	vector<int>a(N);
	map<int,int>mp;
	REP(i,N){
		a[i] = mod_pow(10,N - i - 1) * (s[i] - '0') % MOD;
	}
	++mp[0];
	int ans = 0;
	int now = 0;
	REP(i,N){
		now += a[i];
		now %= MOD;
		ans += mp[now]++;
	}
	out(ans);
}

Measured memory_bytes: 2564
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1 , n-1):
    if p[i-1] < p[i] < p[i+1]:
        count +=1 
    elif p[i-1] > p[i] > p[i+1]:
        count +=1 
print(count) 


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int n,k;
  long long int num,sum=0;
  cin >> n;
  cin >> k;
  vector<long long int> data;
  for(int i=0;i<n;i++){
    cin >> num;
    data.push_back(num);
  }
  sort(data.begin(),data.end());
  for(int i=0;i<n-k;i++){
    sum += data[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, m;
  cin >> n >> m;
  vl x(m);
  rep(i, m) cin >> x[i];
  sort(all(x));
  
  vl d(m-1);
  rep(i, m-1) d[i]=x[i+1]-x[i];
  sort(all(d), greater<ll>());
  
  ll ans=x[m-1]-x[0];
  rep(i, min(m-1,n-1)) ans-=d[i];
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        a[i] *= 2; b[i] *= 2;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2){
        cout << (b[n/2]-a[n/2])/2+1 << "\n";
    }else {
        cout << (b[n/2]+b[n/2-1])/2 - (a[n/2]+a[n/2-1])/2+1 << "\n";
    }
    return 0;
}

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

using namespace std;

struct edge{
  int v,w;
};

vector<int> minimum_spanning_arborescence(const vector<vector<edge> > &G,int root){
  const int INF=1<<29;
  const int N=G.size();
  vector<int> prev(N,-1),weight(N,INF);
  for(int i=0;i<N;i++){
    for(auto e:G[i]){
      if(e.v!=root&&e.w<weight[e.v]){
	weight[e.v]=e.w;
	prev[e.v]=i;
      }
    }
  }
  vector<int> check(N,N);
  int cycle_len=0;
  vector<char> in_cycle(N);
  for(int i=0;i<N;i++){
    for(int j=i;j>=0;){
      if(check[j]<i)break;
      if(check[j]==i){
	for(int k=j;;){
	  cycle_len++;
	  in_cycle[k]=true;
	  k=prev[k];
	  if(k==j)goto found;
	}
      }
      check[j]=i;
      j=prev[j];
    }
  }
  return prev;
 found:
  int nN=N-cycle_len+1;
  vector<int> newv(N),oldv(N);
  for(int i=0,idx=0;i<N;i++){
    if(!in_cycle[i]){
      oldv[idx]=i;
      newv[i]=idx++;
    }else{
      newv[i]=nN-1;
    }
  }
  vector<vector<edge> > nG(nN);
  vector<int> in(N,-1),out(N,-1);
  vector<int> in_val(N,INF),out_val(N,INF);
  for(int i=0;i<N;i++){
    for(auto e:G[i]){
      int nc=e.w-weight[e.v];
      if(!in_cycle[i]){
	if(!in_cycle[e.v]){
	  nG[newv[i]].push_back({newv[e.v],nc});
	}else{
	  if(nc<in_val[i]){
	    in_val[i]=nc;
	    in[i]=e.v;
	  }
	}
      }else{
	if(!in_cycle[e.v]){
	  if(nc<out_val[e.v]){
	    out_val[e.v]=nc;
	    out[e.v]=i;
	  }
	}
      }
    }
  }
  for(int i=0;i<N;i++){
    if(in_val[i]<INF){
      nG[newv[i]].push_back({nN-1,in_val[i]});
    }
    if(out_val[i]<INF){
      nG[nN-1].push_back({newv[i],out_val[i]});
    }
  }
  auto r=minimum_spanning_arborescence(nG,newv[root]);
  vector<int> rv(N);
  for(int i=0;i<nN-1;i++){
    if(r[i]<0){
      rv[oldv[i]]=r[i];
    }else if(r[i]<nN-1){
      rv[oldv[i]]=oldv[r[i]];
    }else{
      rv[oldv[i]]=out[oldv[i]];
    }
  }
  int v_into_cycle=oldv[r[nN-1]];
  int v_in_cycle=in[v_into_cycle];
  rv[v_in_cycle]=v_into_cycle;
  int x=prev[v_in_cycle];
  for(int i=0;i<cycle_len-1;i++){
    rv[x]=prev[x];
    x=prev[x];
  }
  return rv;
}

int main(){
  int V,E,r;
  cin>>V>>E>>r;
  vector<vector<edge> > G(V);
  for(int i=0;i<E;i++){
    int s,t,w;
    cin>>s>>t>>w;
    G[s].push_back({t,w});
  }
  auto msa=minimum_spanning_arborescence(G,r);
  for(auto e:msa){
    //    cout<<e<<endl;
  }
  int ans=0;
  for(int i=0;i<G.size();i++){
    for(auto e:G[i]){
      if(msa[e.v]==i){
	ans+=e.w;
      }
    }
  }
  cout<<ans<<endl;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> v(n,0);
	for (int i=1; i<n; i++)
	{
		int jousi;
		cin >> jousi;
		v.at(jousi - 1)++;
	}

	for (int buka: v)
	{
		cout << buka << endl;
	}
	return 0;
}

Measured memory_bytes: 4048
// ABC 96 C

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

typedef long long ll;

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; }
const long long INF = 1LL<<60;

char s[51][51];

int main()
{
  int H, W;
  cin >> H >> W;

  rep(h, H) {
    rep(w, W) {
      cin >> s[h][w];
    }
  }
  int dh[] = {-1, 0, 1, 0};
  int dw[] = {0, -1, 0, 1};
  rep(h, H) {
    rep(w, W) {
      if (s[h][w] == '.') {
        continue;
      }
      bool flag = false;
      rep(i, 4) {
        if (h + dh[i] < 0 || h + dh[i] >= H || w + dw[i] < 0 || w + dw[i] >= W) {
          continue;
        }
        if (s[h + dh[i]][w + dw[i]] == '#') {
          flag = true;
        }
      }
      if (!flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
As = Array.new(N)
N.times do |i|
  As[i] = gets.split.map(&:to_i)
end
As.sort_by!{|k,v| v}
sum = 0
ans = "Yes"
As.each{|k,v|
  sum += k
  if sum > v
    ans = "No"
    break;
  end
}

puts ans


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const ll mod = 998244353;


ll dp[3010][3010];

int main(){
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3010; ++j) {
            dp[i+1][j] += 2 * dp[i][j];
            dp[i+1][j] %= mod;
            if (j - a[i] >= 0){
                dp[i+1][j] += dp[i][j-a[i]];
                dp[i+1][j] %= mod;
            }
        }
    }
    cout << dp[n][s] << endl;
}


Measured memory_bytes: 74188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

char s[100010];

int main()
{
	scanf("%s", s);
	int n = strlen(s);
	puts((s[0]==s[n-1])!=(n%2)?"First":"Second");
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e12;

int main(){
    int h, w;
    cin >> h >> w;

    vector<vector<int>> c(10, vector<int>(10));
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin >> c[i][j];
        }
    }
    
    vector<int> numbers(10);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int a;
            cin >> a;
            if(a != -1) numbers[a] += 1;
        }
    }

    vector<int> mp(10);
    for (int k=0; k<10; k++){// potential relay points
        for (int i=0; i<10; i++){
            for (int j=0; j<10; j++){
                c[i][j] = min(
                    c[i][j],// without going through k
                    c[i][k] + c[k][j]// with going through k
                );
            }
        }
    }
    for(int i=0; i<10; i++) mp[i] = c[i][1];

    int ans = 0;
    for(int i=0; i<10; i++){
        ans += numbers[i] * mp[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s; cin>>s;
    for(auto& c:s){
        if(c=='1') c='9';
        else c='1';
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components


def solve():
    N, M = map(int, input().split())
    X = [0 for _ in range(M)]
    Y = X[:]
    for i in range(M):
        X[i], Y[i], _ = map(lambda x: int(x)-1, input().split())
    
    graph = csr_matrix(([1]*M, (X, Y)), (N, N))
    ans = connected_components(graph)[0]
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 28064
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def ufinit(n):
  global ufsz, ufances
  ufsz = [1] * n
  ufances = [0] * n
  for i in range(n):
    ufances[i] = i

def ufroot(x):
  global ufances
  a = []
  y = x
  while ufances[y] != y:
    a.append(y)
    y = ufances[y]
  for z in a:
    ufances[z] = y
  return y

def ufconn(x,y):
  global ufsz, ufances
  i = ufroot(x)
  j = ufroot(y)
  if i==j:
    return
  #k  = [i,j].min
  k  = j if (ufsz[i]<ufsz[j]) else i
  if k==j:
    ufances[i] = j
  else:
    ufances[j] = i
  ufsz[k] = ufsz[i] + ufsz[j]

n,m = inm()
a = []
b = []
for i in range(m):
    aa,bb = inm()
    a.append(aa-1)
    b.append(bb-1)
ufinit(n)
cnt = n*(n-1)//2
ngr = [1]*n
ans = [0]*m
ans[m-1] = cnt
for i in range(m-1,0,-1):
    ra = ufroot(a[i])
    rb = ufroot(b[i])
    if ra != rb:
        cnt -= ngr[ra]*ngr[rb]
        ufconn(ra,rb)
        ngr[ra] += ngr[rb]
        ngr[rb] = ngr[ra]
    ans[i-1] = cnt
for i in range(m):
    print(ans[i])


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

int main() {
  string s, t;
  cin >> s >> t;
  int a = 0;
  
  for(int i=0; i<3; i++){
    if(s.at(i) == t.at(i)){
      a ++;
    }
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c,d,e,f,g,h,i;
    scanf("%d %d %d",&a,&b,&c);
    scanf("%d %d %d",&d,&e,&f);
    scanf("%d %d %d",&g,&h,&i);
    int x = a+e+i;
    int y = b+f+g;
    int z = c+d+h;
    if(x==y && y==z) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String[] args){
        int N, A, B, X = 0;
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();

        for(int a = 0; a <= 1; a++){
            for(int b = 0; b <= 9; b++){
                for(int c = 0; c <= 9; c++){
                    for(int d = 0; d <= 9; d++){
                        for(int e = 0; e <= 9; e++){
                            if(A <= a+b+c+d+e && a+b+c+d+e <= B && 10000*a+1000*b+100*c+10*d+e <= N){
                                X = X + 10000*a+1000*b+100*c+10*d+e;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(X);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=4010;
int n,pre[maxn][3],suf[maxn][3];
char s[maxn];
int d[maxn];
ll ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	scanf("%s",s+1);
	for (int i=1;i<=n;i++) {
		if (s[i]=='R') d[i]=0;
		else if (s[i]=='G') d[i]=1;
		else d[i]=2;
	}
	for (int i=1;i<=n;i++) {
		for (int j=0;j<3;j++) pre[i][j]=pre[i-1][j];
		pre[i][d[i]]++;
	}
	for (int i=n;i>=1;i--) {
		for (int j=0;j<3;j++) suf[i][j]=suf[i+1][j];
		suf[i][d[i]]++;
	}
	for (int i=1;i<=n;i++) {
		for (int j=0;j<3;j++)
		for (int k=0;k<3;k++)
			if (d[i]!=j&&j!=k&&k!=d[i])
				ans+=pre[i-1][j]*suf[i+1][k];
	}
	for (int i=1;i<=n;i++)
	for (int j=i+1,k;j<=n;j++) {
		k=j*2-i;
		if (j<k&&k<=n) {
			if (d[i]!=d[j]&&d[j]!=d[k]&&d[k]!=d[i]) ans--;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

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


int main(){
    int n; cin >> n;
    int w; cin >> w;

    ll arr[n][2];

    for (int i = 0; i < n; i++){
        cin >> arr[i][1] >> arr[i][0];
    }
    ll dp[n+1][w+1];

    memset(dp, 0, sizeof(dp));
    // dp[0][0] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= w; j++){
            if (j-arr[i-1][1] >= 0) dp[i][j] = max(dp[i-1][j], dp[i-1][j-arr[i-1][1]] + arr[i-1][0]);
            else dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[n][w] << endl;
}

Measured memory_bytes: 79104
#include <stdio.h>

int main(){
  int sum=0;
  int N=0,K=0;
  int x[100]={0};
  scanf("%d",&N);
  scanf("%d",&K);
  for(int i=0;i<N;i++) scanf("%d",&x[i]);
  for(int i=0;i<N;i++){
    if(x[i]<(K-x[i])){
      sum += x[i]*2;
    }else{
      sum += (K-x[i])*2;
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="SSS")
        cout<<"0"<<endl;
    else if(s=="RSS")
        cout<<"1"<<endl;
    else if(s=="SRS")
        cout<<"1"<<endl;
    else if(s=="SSR")
        cout<<"1"<<endl;
    else if(s=="RSR")
        cout<<"1"<<endl;
    else if(s=="RRS")
        cout<<"2"<<endl;
    else if(s=="SRR")
        cout<<"2"<<endl;
    else if(s=="RRR")
        cout<<"3"<<endl;
    
    return 0;
}

Measured memory_bytes: 3124
#include<stdio.h>

int main(void){
	
	int a,b,c;
	
	int answer;   //?´???°????????°
	
	do{
		scanf("%d %d %d",&a,&b,&c);
	}while((a<1)||(b<1)||(c<1)||(a>10000)||(b>10000)||(c>10000)||(a>b));
	
	
	for(answer=0;;a++){
		
		
		if(a>b){
			break;
		}
		
		if(c%a==0){
			answer++;
		}
		
	}
	
	//printf("%d %d %d\n",a,b,c);
	
	
	printf("%d\n",answer);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	vector<ll> vec(n+1,0);
	for(ll i=1;i<=n;i++){
		cin>>vec[i];
	}
	map<ll,ll> map;
	std::map<ll,ll> ::iterator it;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		it=map.find(i-vec[i]);
		if(it!=map.end()){
			ans+=map[i-vec[i]];
		}
		map[i+vec[i]]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 17060
import bisect
N, K = map(int, input().split())

V = [int(x) for x in input().split()]

ans = 0
for a in range(K+1):
    for b in range(K+1):
        max_CD = min(a + b, min(2*N, K) - (a+b))
        if max_CD < 0 or a + b > N:
            break
        vs = V[:a] + V[N-b:]
        vs.sort()
        i = bisect.bisect_left(vs, 0)
        #print(a, b, max_CD, vs, i, sum(vs[min(i, max_CD):]))
        ans = max(ans, sum(vs[min(i, max_CD):]))
print(ans)


Measured memory_bytes: 42224
#include <stdio.h>

void QQ(int,int);

int main(void){
  int i,j;

  QQ(i,j);
  
  return 0;
}

void QQ(int i,int j){

 for( i = 1 ; i <= 9 ; i++ )
    for( j = 1 ; j <= 9 ; j++ )
      printf("%dx%d=%d\n" ,i ,j , i*j );

}

Measured memory_bytes: 524
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		sc.close();

		int ans = 0;
		for (;; ans++) {
			if (B <= 1 + ((A - 1) * ans)) {
				break;
			}
		}

		out.println(ans);

	}

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


Measured memory_bytes: 25044
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 998244353;
const int inf = 1e9 + 7;
const int N = 3e2 + 5;
const double eps = 1e-9;
int dp[N][N][N];

int add(int x, int y) { return x+y < mod ? x+y : x+y-mod; }
int mul(int x, int y) { return x * 1ll * y % mod; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  int n, k; cin >> k;
  n = sz(s); k = min(k, n);
  s = '#' + s + '0';
  dp[n+1][0][0] = 1;
  for (int i = n+1; i; i--) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= n; l++) if (dp[i][j][l] != 0) {
        dp[i-1][j][l] = add(dp[i-1][j][l], dp[i][j][l]);
        if (s[i] != '0')
          continue;
        for (int c = 1; c <= i && s[i-c] == '1'; c++)
          dp[i-1][j+c][l+c] = add(dp[i-1][j+c][l+c], dp[i][j][l]);
        for (int c = 1; c <= l; c++)
          dp[i-1][j][l-c] = add(dp[i-1][j][l-c], dp[i][j][l]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    ans = add(ans, dp[0][i][0]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 84396
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main()
{
    int n;
    cin >> n;
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    rep(i, n)
    {
        string x;
        cin >> x;
        if (x == "AC")
        {
            ++a;
        }
        else if (x == "WA")
        {
            ++b;
        }
        else if (x == "TLE")
        {
            ++c;
        }
        else
        {
            ++d;
        }
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	long long int l, r;
	std::cin >> l >> r;
	int result = 2019;
	long long int temp;


	for (long long int i = l; i < r; i++) {
		for (long long int j = i + 1; j <= r; j++) {
			temp = i * j % 2019;
			if (temp == 0) {
				std::cout << 0 << std::endl;
				return 0;
			}
			else if (result > temp) {
				result = temp;
			}
		}
	}

	std::cout << result << std::endl;

	return 0;
}

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

#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> l4;


const int maxn = 1e5+1;
int n, color[maxn];
vector<int> g[maxn];
ii edges[maxn];
int in[maxn];
bool del[maxn];
ii dfs(int cur, int p);
int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= n-1; ++i)
    {
      scanf("%d %d", &edges[i].first, &edges[i].second);
      g[edges[i].first].pb(edges[i].second);
      g[edges[i].second].pb(edges[i].first);
      ++in[edges[i].first];
      ++in[edges[i].second];
    }
  for (int i = 1; i <= n; ++i)
    {
      char ch;
      scanf(" %c", &ch);
      color[i] = ch == 'B';
    }
  queue<int> q;
  for (int i = 1; i <= n; ++i)
    if (in[i] <= 1 && color[i] == 1)
      q.push(i);
  int new_n = n;
  while (!q.empty())
    {
      int cur = q.front();
      q.pop();
      del[cur] = true;
      //      cerr << "delete " << cur << endl;
      --new_n;
      for (auto nxt : g[cur])
        {
          --in[nxt];
          if (color[nxt] == 1 && in[nxt] == 1)
            q.push(nxt);
        }
    }
  for (int i = 1; i <= n; ++i)
    g[i].clear();
  int new_e = 0;
  for (int i = 1; i <= n-1; ++i)
    if (!del[edges[i].first] && !del[edges[i].second])
      {
        g[edges[i].first].pb(edges[i].second);
        g[edges[i].second].pb(edges[i].first);
        ++new_e;
      }
  int root = 0;
  for (int i = 1; i <= n; ++i)
    if (g[i].size() > 1)
      {
        root = i;
        break;
      }
  if (new_n <= 2)
    {
      printf("%d\n", new_n);
      return 0;
    }
  int ans = 2*new_n-2;
  //  cerr << new_n << " " << new_e << endl;
  for (int i = 1; i <= n; ++i)
    if (g[i].size() > 1 && g[i].size()%2 == 1)
      {
        color[i] ^= 1;
      }
  for (int i = 1; i <= n; ++i)
    ans += (g[i].size() > 1) && (color[i] == 0);
  //  cerr << "pre ans = " << ans << endl;
  if (new_n > 2)
    ans -= dfs(root, -1).first;
  printf("%d\n", ans);
}
ii dfs(int cur, int p)
{
  if (g[cur].size() == 1)
    {
      return mp(0, 0);
    }
  int a = 0, b = 0, c = 0;
  for (auto nxt : g[cur])
    if (nxt != p)
      {
        auto tmp = dfs(nxt, cur);
        //        cerr << "dfs " << color[nxt] << " " << nxt << " " << cur << " " << tmp.first << " " << tmp.second << endl;
        a = max(a, tmp.first);
        if (tmp.second > b)
          swap(b, tmp.second);
        if (tmp.second > c)
          swap(c, tmp.second);
      }
  int offset = 2-2*color[cur];
  return mp(max(offset+b+c, a), b+offset);
}


Measured memory_bytes: 14208
n = int(input())
ans = [0, 0, 0, 0]
s = [input() for i in range(n)]
for j in s:
  if j == "AC":
    ans[0]+=1
  elif j == "WA":
    ans[1]+=1
  elif j == "TLE":
    ans[2]+=1
  elif j == "RE":
    ans[3]+=1
num = 0
for list1 in ["AC", "WA", "TLE", "RE"]:
  print(list1 + " x " + str(ans[num]))
  num += 1

Measured memory_bytes: 16324
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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 namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int s, w;
    cin >> s >> w;
    
    if (s <= w) {
        cout << "unsafe" << endl;
        
    } else {
        cout << "safe" << endl;
    }


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

Measured memory_bytes: 3588
#include "iostream"
#define endl '\n'

using namespace std;

int main() {
  int a, b, c, d = 0;
  int flag = 0;

  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;

  while (true) {
    c -= b;
    if (c <= 0) {
      flag = 1;
      break;
    }

    a -= d;
    if (a <= 0) {
      flag = -1;
      break;
    }
  }

  cout << (flag == 1 ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 999999999
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;

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

    int main()
    {
       string s;
       cin>>s;
       int cnt=0;
       int ans=0;
       for(int i=0; i<s.size(); i++)
       {
           if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
           {
               ++cnt;
               ans =max(ans,cnt);
           }else {ans =max(ans,cnt); cnt=0;}
       }
       cout<<ans<<endl;
    }



Measured memory_bytes: 256
#include <math.h>
#include<stdio.h>
void maxs(int *a,int *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}
int main()
{
	int a, b, c, i=0;
	scanf("%d%d%d", &a, &b, &c);
	if(a<b)
		maxs(&a, &b);
	if (c > a)
		maxs(&c, &a);
	if (b < c)
		maxs(&b, &c);
	if ((b - c )% 2)
		a++, b++, i++;
	while (b < a)
	{
		b++;
		c++;
		i++;
	}
	while (c != b)
	{
		c += 2;
		i++;
	}
	printf("%d", i);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; (i) < ((int)(n)); ++(i))
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main() {
    ll ans = 1;
    int n;
    cin >> n;
    rep(i, n) ans = (ans * 10) % MOD;
    ll d1 = 1, d2 = 1;
    rep(i, n) d1 = (d1 * 8) % MOD;
    rep(i, n) d2 = (d2 * 9) % MOD;
    ans = (ans - 2 * d2) % MOD;
    ans = (ans + d1) % MOD;
    if(ans < 0)
        ans += MOD;

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,a[100010],s[100010];

int main(){
    cin >> N;

    int i;
    for (i=1; i<=N; i++) cin >> a[i];
    sort(a+1,a+N+1);
    for (i=1; i<=N; i++) s[i]=a[i]+s[i-1];

    for (i=N; i>0; i--){
        if (2*s[i]<a[i+1]) break;
    }

    cout << N-i << "\n";
    return 0;
}


Measured memory_bytes: 1792
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int N = readln.chomp.to!int;
    long[] a = readln.split.to!(long[]);
    auto list = DList!(long)(0);
    int ans = 0;
    foreach(i; 0..N) {
        while(list.back > a[i]) {
            list.removeBack;
        }
        if (list.back < a[i]) {
            ans++;
            list.insertBack(a[i]);
        }
    }
    ans.writeln;
}

Measured memory_bytes: 17552
#include <iostream>

int main(){
    int n;
    std::cin >> n;
    int a[n],b[n];
    
    for(int i=0;i<n;++i){
        std::cin >> a[i];
    }
    
    for(int i=0;i<n;++i){
        b[a[i]-1]=i+1;
    }
    
    for(int i=0;i<n;++i){
        std::cout << b[i] << " ";
    }
    
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int min_cost_bottomup(int*,int);
int min_cost_topdown(int*,int);

#define index(n) n-1

int main()
{
    int N;
    cin >> N;
    int *h;
    h = new int[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }

    cout << min_cost_bottomup(h,N) <<endl;

    return 0;
}

int min_cost_bottomup(int *h, int n)
{
    int *m;
    m = new int[n];
    m[0]=0;
    m[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        m[i] = min(m[i-2]+abs(h[i]-h[i-2]),m[i-1]+abs(h[i]-h[i-1]));
    }
    return m[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define ll long long
ll a;
int main()
{
	cin >> a;
	
	if(22<=a&&a<=25)
	cout << "Christmas";
	for(int i=0; i<=24; i++)
	{
		if(a<=i&&i<=24)
		cout << " Eve";
	}
}

Measured memory_bytes: 256
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        String[] B = sc.next().split("\\.");

        int b1 = Integer.parseInt(B[0]);
        int b2 = Integer.parseInt(B[1]);
        //System.out.println(b1);
        //System.out.println(b2);

        int b = b1 * 100 + b2;
        long ans = A * b;
        System.out.println(ans/100);
        return;
    }

}

Measured memory_bytes: 35820
n,a,b,c,d = map(int, input().split())
s = list(input())
s.append(".")
a -= 1
b -= 1
c -= 1
d -= 1

if c > d:
    if "##" not in "".join(s[a+1:c]) and "##" not in "".join(s[b+1:d]) and "..." in "".join(s[b-1:d+2]):
        print("Yes")
    else: print("No")
else:
    if "##" not in "".join(s[a+1:c]) and "##" not in "".join(s[b+1:d]):
        print("Yes")
    else: print("No")

Measured memory_bytes: 12056
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define int int64_t
#define pb push_back
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
typedef gp_hash_table<int, int, chash> ht;
const int MOD = 1e9 + 7;
const int N = 1e5 + 3;
int dp[N],h[N],n;
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> h[i];
		dp[i] = LLONG_MAX;
	}
	dp[1] = 0;
	for(int i = 1 ; i < n ; i ++)
		dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1])),
		dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
	cout << dp[n];
}




Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static const int NMAX = 105;
static const int WMAX = 10005;
static const int DIAGONAL = 1;
static const int TOP = 0;

struct Item { int value, weight; };

int N, W;
Item item[NMAX];
int C[NMAX][WMAX], G[NMAX][WMAX];

void compute(int &maxValue, vector<int> &selection)
{
    for (int w = 0; w <= W; ++w)
    {
        C[0][w] = 0;
        G[0][w] = DIAGONAL;
    }

    for (int i = 0; i <= N; ++i)
    {
        C[i][0] = 0;
    }

    for (int i = 1; i <= N; ++i)
    {
        for (int w = 1; w <= W; ++w)
        {
            C[i][w] = C[i - 1][w];
            G[i][w] = TOP;
            if (item[i].weight > w) continue;
            if (C[i - 1][w - item[i].weight] + item[i].value > C[i - 1][w])
            {
                C[i][w] = C[i - 1][w - item[i].weight] + item[i].value;
                G[i][w] = DIAGONAL;
            }
        }
    }
    maxValue = C[N][W];
    selection.clear();
    for (int i = N, w = W; i >= 1; --i)
    {
        if (G[i][w] == DIAGONAL)
        {
            selection.push_back(i);
            w -= item[i].weight;
        }
    }

    reverse(selection.begin(), selection.end());
}

int main()
{
    int maxValue;
    vector<int> selection;
    cin >> N >> W;
    for (int i = 1; i <= N; ++i)
    {
        cin >> item[i].value >> item[i].weight;
    }
    compute(maxValue, selection);
    cout << maxValue << endl;
    return 0;
}



Measured memory_bytes: 11056