akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/

// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::mem::swap;
use std::ops::*;
use std::str::FromStr;

fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse()
}

fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|x| x.parse()).collect()
}

// code...
fn main() {
    // println!("{}", 1099511627776usize.trailing_zeros());
    // // assert!(1099511627776usize.trailing_zeros() == 40); // ok!
    // println!("{}", 1usize << 40);
    // // assert!(2usize ^ 40 == 1099511627776usize); // ok!

    let n: usize = input().unwrap();
    
    let mut c = 1usize;
    while c <= n {
        c *= 2;
    }

    println!("{}", c-1);
}


Measured memory_bytes: 4352
import sys
import numpy as np

read = sys.stdin.read

n, m, k = map(int, input().split())
ca = np.array(read().split(), dtype=np.int64).reshape([n,m+1])

ans = 10**8

for i in range(2**n):
    b = np.array(list(format(i,'0'+str(n)+'b')), dtype=np.int64)
    d = ca[b == 1].sum(axis=0)
    if np.all(d[1:] >= k):
        ans = min(ans, d[0])

if ans == 10**8:
    print("-1")
else:
    print(ans)

Measured memory_bytes: 27320
#N%2==1なので
#a1=S-2((a2+a3)+(a4+a5)+...+(aN-1+aN))
#=S-2(A2+A4+...+AN-1)よりa1を求め
#ai+ai+1=2Ai<=>ai+1=2Ai-aiより再帰的にa2以降を求める
N=int(input())
A=list(map(int,input().split()))
count=0
allcount=0
matrix=[]
ans=[0]*N
allsum=0
a1=0
for i in range(N):
    allsum=allsum+A[i]
a1=allsum
for i in range(N):
    if i%2==1:
        a1=a1-2*A[i]
ans[0]=a1
for i in range(0,N-1,1):
    ans[i+1]=2*A[i]-ans[i]
print(*ans,sep=" ")

Measured memory_bytes: 14092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second

ll ans,x,y,z,len;
priority_queue<ll,vector<ll>> a;
priority_queue<P,vector<P>> b;

int main(void){
    int n,m,cnt=0;cin>>n>>m;bool ch;
    for(int i=0;i<n;i++){cin>>x;a.push(x);}
    for(int i=0;i<m;i++){
        cin>>y>>z;
        b.push(P(z,y));
    }
    
    while(cnt<n){
        ch=0;
        if(a.top()<b.top().F){
            for(int i=0;i<b.top().S;i++){
                if(a.empty()||b.empty()||cnt>=n)break;
                ans+=b.top().F;cnt++;ch=1;
            }
            b.pop();
        }else if(!a.empty()&&!b.empty()&&cnt<n-1){
            ans+=a.top();cnt++;ch=1;
            //cout<<a.top()<<endl;
            a.pop();
        }
        if(ch==0)break;
        ch=0;
    }
    while(cnt<n){ans+=a.top();a.pop();cnt++;}
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3188
import java.util.*;
class Main {
    public static void main(String...args) {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int divisor = 0;

        while((divisor = x % y) != 0) {
                x = y;
                y = divisor;
        }
        System.out.println(y);
    }
}



Measured memory_bytes: 26240
#include<cstdio>
inline int read(){
	char ch=getchar();
	int o=0;
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		o=(o<<3)+(o<<1)+(ch^48);
		ch=getchar();
	}
	return o;
}
int n;
int main(){
	n=read();
	if(n&1)printf("%.10lf",((n>>1)+1.0)/n);
	else printf("%.10lf",(n>>1)/(double)n);
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n,a,b;
    cin>>n>>a>>b;
    VL arr(n);
    fr(i,0,n)
        cin>>arr[i];
    sort(ALL(arr));
    ll ans=0;
    // if(a>=b)
    // {
    //     cout<<(n-1)*b<<endl;
    // }
    // else
    {
        fr(i,1,n)
        {
            ll diff=(arr[i]-arr[i-1])*a;
            if(diff<b)
            {
                ans+=diff;
            }
            else
            {
                ans+=b;
            }
        }
        cout<<ans<<endl;
    }
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3936
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll chmax(ll &a, ll b){ return a = (a>b) ? a : b;}
ll chmin(ll &a, ll b){ return a = (a<b) ? a : b;}


////////////////////////////////////////////////////////////////
#define PI 3.14159265359
int main(void) {
	int N;
	cin >> N;
	//vector<int> a(N+3, 0), b(N+3, 0), c(N+3, 0);
	//for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];
	vector<vector<int>> happy(N+3, vector<int>(3, 0));
	for(int i=0; i<N; i++){
		cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
	}

	//dp[i][j]: i日目にjをした時，今まで得た合計の幸福度の最大値
	vector<vector<ll>> dp(N+3, vector<ll>(3, 0));
	for(int j=0; j<3; j++) dp[0][j] = 0;

	for(int i=0; i<=N; i++){
		for(int j=0; j<=2; j++){
			int act1 = (j+1)%3, act2 = (j+2)%3;
			dp[i+1][j] = max(dp[i+1][j], dp[i][act1]+happy[i][j]);
			dp[i+1][j] = max(dp[i+1][j], dp[i][act2]+happy[i][j]);
		}
	}

	ll ans = 0;
	for(int j=0; j<=2; j++) ans = max(ans, dp[N][j]);

	cout << ans << endl;	
}



Measured memory_bytes: 11136
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
const int MOD = 1000000007;

int main() {
    int N;
    string S;
    cin >> N >> S;
    int l = S.size();
    rep(i, 0, l) {
        int x = S[i] - 'A';
        x = (x + N) % 26;
        putchar('A' + x);
    }
    cout << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
    int a[100][100],b[100][100];
    long c[100][100];
    int n,m,l;
    int i,j,k;
    
    scanf("%d %d %d",&n,&m,&l);
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&b[i][j]);
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            c[i][j]=0;
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<l-1;j++){
            printf("%ld ",c[i][j]);
        }
        printf("%ld",c[i][l-1]);
        printf("\n");
    }
    
}

Measured memory_bytes: 1896
from time import time
from random import randint

def func(s, x):
    last = [0] * 26
    score = 0
    for i, v in enumerate(x, 1):
        last[v] = i
        c = 0
        for j in range(26):
            c += s[j] * (i - last[j])
        score += s[i * 26 + v] - c
    return score

def main():
    start = time()
    d, *s = map(int, open(0).read().split())
    x = ([*range(26)] * 15)[:d]
    M = func(s, x)
    while time() - start < 1.8:
        y = x[:]
        if randint(0, 1):
            y[randint(0, d - 1)] = randint(0, 25)
        elif randint(0, 1):
            i=randint(0, d - 16)
            j=randint(i + 1, i + 15)
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y)
        if t > M:
            M = t
            x = y
    for t in x:
        print(t + 1)

main()

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int lim = 50;

bool g[51][51];
bool v[51];
int n, m;

void dfs(int u) {
  v[u] = true;
  rep(i, n) {
    if (!g[u][i] || v[i]) continue;
    dfs(i);
  }
}

int main() {
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = true;
  }

  ll ans = 0;
  rep(i, m) {
    rep(j, n) v[j] = false;
    g[a[i]][b[i]] = g[b[i]][a[i]] = false;
    dfs(0);
    bool ok = false;
    rep(j, n) if (!v[j]) ok = true;
    if (ok) ans++;
    g[a[i]][b[i]] = g[b[i]][a[i]] = true;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll n,k;
	cin>>n>>k;
	vec a(n);
	floop(i,0,n)
	cin>>a[i];
	vec ans;
	floop(i,0,n)
	{
		if(i>=k)
		{
			if(a[i]>a[i-k])
			ans.pb(1);
			else
			ans.pb(0);
		}
	}
	floop(i,0,sz(ans))
	{
		if(ans[i]==1)
		cout<<"Yes\n";
		else
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 6868
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,u1;
	int a[100];
	cin>>n;
	for(int i=0;i<n;++i)
	{
		cin>>u1;
		a[i]=u1;
	}
	sort(a,a+n);
	cout<<a[n-1]-a[0];
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
    #include<algorithm>
    #include<vector>
    using namespace std;
     
    int main(){
        int n,m; cin>>n>>m;
        vector<int> x(m);
        for(int i=0;i<m;i++) cin>>x[i];
        sort(x.begin(),x.end());
        vector<int> d(m-1);
        for(int i=0;i<m-1;i++){
            d[i]=x[i+1]-x[i];
        }
        sort(d.begin(),d.end());
        int ans=0;
        for(int i=0;i<m-n;i++){
            ans+=d[i];
        }
        cout<<ans<<endl;
    }

Measured memory_bytes: 1024
def main():
    H, N = list(map(int,input().split()))
    AB = [list(map(int,input().split())) for i in range(N)]
    
    cost = [100000000 for _ in range(H)]
    min_cost = 100000000
    
    cost[0] = 0
    
    for k in range(H):
        for j in range(N):
            if k + AB[j][0] >= H:
                kari1 = cost[k] + AB[j][1]
                if min_cost > kari1:
                    min_cost = kari1
            else:
                kari2 = cost[k] + AB[j][1]
                if cost[k+AB[j][0]] > kari2:
                    cost[k+AB[j][0]] = kari2
    print(min_cost)

if __name__=='__main__':
    main()      

Measured memory_bytes: 42476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    ll arr[3];
    for(i=0;i<3;i++)cin>>arr[i];
    sort(arr,arr+3);
    if(arr[0]+arr[1]==arr[2])cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int t=sc.nextInt();
        int[] a=new int[n+1];
        int leftmin=1000000001;
        int dmax=0;
        int count=0;
        for (int i = 1; i <= n; i++) {
            a[i]=sc.nextInt();
            leftmin=min(leftmin,a[i]);
            if(a[i]-leftmin==dmax){
                count++;
            }else if(dmax<a[i]-leftmin){
                dmax=max(dmax,a[i]-leftmin);
                count=1;
            }
        }
        out.println(count);
    }
}

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

long long N;

int dfs( string s )
{
	if( stoll( s ) > N ) {
		return 0;
	}
	int res = 0;
	if( s.find('7') != string::npos && s.find('5') != string::npos && s.find('3') != string::npos ) {
		res = 1;
	}
	res += dfs( s + '7' );
	res += dfs( s + '5' );
	res += dfs( s + '3' );
	return res;
}

int main() {
	cin >> N;

	int ans = dfs( string("0") );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
	using namespace std;
	static const int INPUT_A_MAX = 10000;
	static const int INPUT_B_MAX = 10000;
	static const int INPUT_C_MAX = 10000;
	static const int INPUT_A_MIN = 0;
	static const int INPUT_B_MIN = 0;
	static const int INPUT_C_MIN = 0;
	int input_a = 0;
	int input_b = 0;
	int input_c = 0;
	int cnt = 0;

	cin >> input_a;
	cin >> input_b;
	cin >> input_c;

	assert (INPUT_A_MIN <= input_a && input_a <= INPUT_A_MAX); /* Precondition */
	assert (INPUT_B_MIN <= input_b && input_b <= INPUT_B_MAX); /* Precondition */
	assert (INPUT_C_MIN <= input_c && input_c <= INPUT_C_MAX); /* Precondition */
	assert (input_a <= input_b);				   /* Precondition */

	/* Calculatoin */
	for(int i = input_a; i <= input_b; i++){
		if(input_c % i == 0){
			cnt++;
		}
	}
	
        /* Output */
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3088
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
//#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k, pr[N];
pair <pair <int,int>, int> p[N], pp[N];
string ss;

int root(int i){
	if (pr[i] != i) return pr[i] = root(pr[i]);
	return i;
}

void join(int x, int y){
	if (rand() & 1){
		pr[x] = y;
	}
	else{
		pr[y] = x;
	}
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	srand(time(0));
	cin >> n;
	vector <pair <int, pair <int,int> > > v;
	for (int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		p[i] = mp(mp(x, y), i);
		pp[i] = mp(mp(y, x), i);
	}
	for (int i = 0; i < n; i++) pr[i] = i;
	sort(p, p + n);
	sort(pp, pp + n);
	for (int i = 1; i < n; i++){
		v.pb(mp(p[i].f.f - p[i - 1].f.f, mp(p[i].s, p[i - 1].s)));
	}
	for (int i = 1; i < n; i++){
		v.pb(mp(pp[i].f.f - pp[i - 1].f.f, mp(pp[i].s, pp[i - 1].s)));
	}
	sort(all(v));
	int res =0;
	for (auto i: v){
		int w = i.f, x = i.s.f, y = i.s.s;
		x = root(x);
		y = root(y);
		if (x != y){
			res += w;
			join(x, y);
		}
	}
	cout << res;
	return 0;
}












Measured memory_bytes: 20720
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve():
    # 数値取得サンプル
    #   1行N項目 x, y = map(int, input().split())
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()

    x, y = map(int, input().split())

    leg = 2 * x

    if leg == y:
        print("Yes")
        return

    for i in range(x):
        leg += 2
        if leg == y:
            print("Yes")
            return

    print("No")


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 8"""
        output = """Yes"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 100"""
        output = """No"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """1 2"""
        output = """Yes"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_1original_1(self):
        test_input = """5 20"""
        output = """Yes"""
        self.assertIO(test_input, output)

    def test_1original_2(self):
        test_input = """5 10"""
        output = """Yes"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


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

#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b)  for(int i=(a);i<(b);++i)
#define rep(i,n)    FOR(i,0,n)
#define rrep(i,n)   for(int i=n-1;i<=0;--i)
#define loop        while(true)
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const ll MAX = 10000000;
const ll MIN = 0;
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; }
using pl = pair<ll, ll>;
using ps = pair<int, string>;

int main() {
    ll ans;
    ll N;
    cin >> N;
    vector<ll> seq(N);
    rep(i,N) sl(seq.at(i));

    sort(seq.begin(), seq.end(), greater<ll>());
    ans = seq.at(0); ll ptr = 2;
    for( ll i = 1; i < N && ptr < N; i++) {
        ans += seq.at(i);
        ptr++;
        if( ptr < N) {
            ans += seq.at(i);
            ptr++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4840
using System;
using System.Collections.Generic;

namespace DataConversion0501
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Dictionary<String, String> convertTable = new Dictionary<String, String>();

                int tableLen = Convert.ToInt32(Console.ReadLine(), 10);

                if (tableLen == 0) break;

                for (int i = 0; i < tableLen; i++)
                {
                    String[] inputs = Console.ReadLine().Split(' ');
                    convertTable.Add(inputs[0], inputs[1]);
                }

                int dataLen = Convert.ToInt32(Console.ReadLine(), 10);

                for (int i = 0; i < dataLen; i++)
                {
                    String input = Console.ReadLine();

                    if (convertTable.ContainsKey(input)) Console.Write(convertTable[input]);
                    else Console.Write(input);
                }

                Console.Write(Environment.NewLine);
            }
        }
    }
}

Measured memory_bytes: 5644
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ans[10];
int row[]= {1,0,-1,0,1,-1,1,-1,0};
int colm[]= {0,1,0,-1,1,-1,-1,1,0};
int main()
{
    //freopen("output.txt", "w", stdout);
    ll r,c,n;
    map<pair<int,int>,int>mp;
    map<pair<int,int>,int>mark;
    vector<pair<int,int> >v,p;
    scanf("%lld %lld %lld",&r,&c,&n);
    for(int i=0; i<n; i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        v.push_back({a,b});
        mp[ {a,b}]=1;
    }
    ans[0]=(r-2)*(c-2);
    for(int i=0; i<n; i++)
    {
        for(int l=0; l<9; l++)
        {
            int flg=0;
            int cnt=0;
            int x=v[i].first+row[l];
            int y=v[i].second+colm[l];
            if(!(0<x && x<=r && 0<y && y<=c))
                continue;
            if(mark[ {x,y}])
                continue;
            if(mp[ {x,y}])
                cnt++;
            mark[ {x,y}]=1;
            for(int j=0; j<8; j++)
            {
                int u=x+row[j];
                int v=y+colm[j];
                if(0<u && u<=r && 0<v && v<=c)
                {
                    if(mp[ {u,v}])
                        cnt++;
                }
                else
                    flg=1;
            }
            if(flg)
                continue;
            if(cnt)
            {
                ans[0]--;
                ans[cnt]++;
            }
            //cout<<x<<" "<<y<<" "<<cnt<<endl;
        }
    }
    for(int i=0; i<10; i++)
        printf("%lld\n",ans[i]);



    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int ps[200005][2];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	string s; cin >> s;
	s = " " + s;

	// W*B*
	rep(i, 1, s.size()) {
		ps[i][0] = ps[i - 1][0] + int(s[i] == '#');
		ps[i][1] = ps[i - 1][1] + int(s[i] == '.');
	}

	int ans = 9999999;
	rep(i, 0, s.size()) {
		//printf("%d; Left B %d; Right W %d\n", i, ps[i][0], ps[n][1] - ps[i][1]);
		ans = min(ans, ps[i][0] + (ps[n][1] - ps[i][1]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 2128
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;


int main() {
    int n; cin >> n;
    if (n %2 == 0) cout << n/2-1 << endl;
    else cout << n/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cstdio>
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;

double dot(point a,point b){
  return a.x*b.x+a.y*b.y;
}

point projection(point a,point b,point c){
  point base = b - a;
  double r = dot(c-a,base)/(abs(base)*abs(base));
  return a+base*r;
}

point reflection(point a,point b){
  point c = a-b;
  return c+a;
}

int main(){
  point a,b,c;
  cin >>a.x>>a.y>>b.x>>b.y;
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> c.x >> c.y;
    point res = projection(a,b,c);
    res = reflection(res,c);
    printf("%.10f %.10f\n",res.x,res.y);
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  string s1;
  cin >> s1;
  
  char c;
  int cn = 1;
  c = s1[0];
  for ( int i=1; i<N; ++i) {
    if ( s1[i] != s1[i-1] ) ++cn;
  }
 
  cout << cn;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b; cin>>a>>b;
	if (b-a>=2019)
	{
		cout << 0;
		return 0;
	}
	
	ll r=a/2019;
	a-=r*2019; b-=r*2019;
	
	ll ans=2999;
	for (int i=a; i<b; i++)
	    for (int j=i+1; j<=b; j++)
	    {
	    	ll tem=(i*j)%2019;
	    	ans=min(ans,tem);
		}
	        
	        
	cout << ans;
 } 

Measured memory_bytes: 256
import collections
import heapq
n = int(input())
p = list(map(int, input().split()))
c = collections.Counter(p)
cond = 0
h = []
for line, cnt in c.most_common():
  if(cnt >= 2):
    for _ in range(cnt // 2):
      heapq.heappush(h, int(-1*line))
if(len(h) < 2):
  print(0)
  exit()
print(heapq.heappop(h) * heapq.heappop(h)) 

Measured memory_bytes: 21540
def f(m, s, g):
    for i in m:
        if s > g:
            s -= i
        else:
            s += i
    return s == g
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
if (f(sorted(m[::2][1::])[::-1], m[0], x)
        and f(sorted(m[1::2])[::-1], 0, y)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
N, x = map(int, input().split())
a = list(map(int, input().split()))
res = 0
if a[0] + a[1] > x:
  d = a[0] + a[1] - x
  if d <= a[1]:
    a[1] -= d
  else:
    a[0] -= d - a[1]
    a[1] = 0
  res += d
for i in range(1, N - 1):
  if a[i] + a[i + 1] > x:
    d = a[i] + a[i + 1] - x
    if d <= a[i + 1]:
      a[i + 1] -= d
    else:
      a[i] -= d - a[i + 1]
      a[i + 1] = 0
    res += d
print(res)

Measured memory_bytes: 59632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <deque>
#include <cmath>
#include <stack>
#include <ctime>
#include <queue>
#include <set>
#include <map>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
#define X first
#define Y second
#define MP make_pair
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
 
const int ppr[] = {257, 263};
const ll INF = 2e18;
const int inf = 2e9;
const int mod[] = {int(1e9 + 7), int(1e9 + 9)};
const int N = 1e6 + 123;
const ld pi = 3.141592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
 
int n, x, cnt, k;

main() {             	
//  freopen(".in", "r", stdin);                          
//  freopen(".out", "w", stdout);
 
//	srand(time(NULL));
	
	speed;

	cin >> n >> k;

	while(n--) {
		cin >> x;
		cnt += (x >= k);
	}

	cout << cnt;
	     
    return 0;                                        
}  

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
using ll = long long;

int main() {
	int n;
	char S[101] = { 0 }, Res[201] = { 0 };
	scanf("%d", &n);
	scanf("%s", S);
	int need_L = 0, pass_L = 0;
	for (int i = 0; i < n; i++) {
		if (S[i] == '(') {
			pass_L++;
		} else if (S[i] == ')') {
			if (1 <= pass_L)
				pass_L--;
			else
				need_L++;
		}
	}
	for (int i = 0; i < need_L; i++)
		printf("%c", '(');
	printf("%s", S);
	for (int i = 0; i < pass_L; i++)
		printf("%c", ')');
	printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

const int M = 1000005;

int main() {
    int N,X,T;
    cin >> N >> X >> T;
    int cnt;
    if(N%X == 0){
        cnt = N/X;
    }
    else{
        cnt = N/X+1;
    }
    cout << cnt*T << endl;
    return 0;
}

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

bool flag = false;

int main(void) {
    int n;
    cin >> n;
    int count[3] = {0};
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 4 == 0)
            count[2]++;
        else if (x % 2 == 0)
            count[1]++;
        else
            count[0]++;
    }
    if (count[1] > 0) {
        flag = count[0] <= count[2];
    }
    else {
        flag = count[0] <= count[2] + 1;
    }
    
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>


const long long MOD = 10e9 + 7;

typedef long long ll;

using namespace std;

ll arr[101][100001];

ll max(ll a, ll b){
	if(a>b)
		return a;
	return b;
}

ll maxVal(int W, vector<int> wt, vector<int> val, int n){
	int i,v;
	
	for(int i=0;i<=n;i++){
		for(v=0;v<=100000;v++){
arr[i][v]=INT_MAX;		}	
	}	

	for(i=0;i<=n;i++){
		arr[i][0]=0;	
	}
	for(int i=1;i<=n;i++){
		for(v=1;v<=100000;v++){
			if(v-val[i-1] < 0){
				arr[i][v]=arr[i-1][v];			
			}
			else{
				arr[i][v] = min(
					arr[i-1][v],
					wt[i-1] + arr[i-1][v-val[i-1]]		
				);			
			}
		}	
	}
	ll maxv=0;
	for(int i=1;i<=n;i++){
		for(v=1;v<=100000;v++){
			if(arr[i][v] <= W){
				maxv= max(maxv,v);			
			}
		}	
	}
	return maxv;
}

int main(){
	int N,W;
	cin>>N>>W;
	vector<int> w,v;
	int x,y;
	for(int i=0;i<N;i++){
		cin>>x>>y;
		w.push_back(x);
		v.push_back(y);	
	}
	cout<<maxVal(W,w,v,N)<<endl;
	
}

Measured memory_bytes: 79104
def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    t = sum(a)
    tmp = t / (4 * m)
    cnt = 0
    for i in range(n):
        if a[i] >= tmp:
            cnt += 1
    if cnt >= m:
        print('Yes')
    else:
        print('No')
if __name__=='__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

int w[107];
vector<pair<int,int> > g[107];
void add(int u, int v, int w){
    g[u].push_back(make_pair(v,w));
    g[v].push_back(make_pair(u,w));
}
int findTheCity(int n, vector<vector<int>>& edges, int dt) {
    for(int i = 0; i < (int)edges.size();i++){
        int u = edges[i][0];
        int v = edges[i][1];
        int w = edges[i][2];
        add(u,v,w);
    }
    
	
	int ans = inf;
	for(int i = 0; i < n; i++){
		clr(w,inf);
		w[i] = 0;
		for(int k = 1; k <= n-1; k++){
			for(int j = 0; j < n; j++){
				for(int l = 0; l < (int)g[j].size(); l++){
					int u = j;
					int v = g[j][l].first;
					int weigth = g[j][l].second;
					if(w[u] + weigth < w[v]){
						w[v] = w[u] + weigth;
					}
				}
			}
		}
		int cont = 0;
		cout<<i<<":\n";
        for(int k = 0; k < n; k++){
            if(k != i && w[k] <= dt){
				cout<< k<<"-"<<w[k];
                cont++;
            }
            cout<<endl;
        }
        
		ans = min(cont, ans);
	}
	
	return ans;
}

int main(){
	int h, a; cin>> h >> a;
	cout<<ceil(h*1.0/a);
	return 0;
}












Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_M = 100000;
int n, m;
int x[MAX_M], y[MAX_M];

int main(){
  cin >> n >> m;
  REP(i, m) cin >> x[i] >> y[i];
  REP(i, m) {
    x[i]--;
    y[i]--;
  }
  bool red[n];
  int num[n];
  REP(i, n) {
    red[i] = false;
    num[i] = 1;
  }
  red[0] = true;

  REP(i, m) {
    num[x[i]]--;
    num[y[i]]++;
    if(red[x[i]]) red[y[i]] = true;
    if(num[x[i]] == 0) red[x[i]] = false;
  }
  
  int ans = 0;
  REP(i, n) {
    if(red[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct Edge{
    Edge(){};
    Edge(int _to,int _cost){
        to = _to;
        cost = _cost;
    }
    int to;
    int cost;
};
struct Data{
    Data(){};
    Data(int _pos,int _t, int _ck){
        pos = _pos;
        t = _t;
        ck = _ck;
    }
    int pos;
    int t;
    int ck;
    bool operator < (const Data &a)const{
        return t > a.t;
    }
};
int main(){
    int c,n,m,s,d;
    while(cin>>c>>n>>m>>s>>d,c){
        int vis[120][12];
        vector<Edge> Node[120];
        for(int i = 0;i < m;i++){
            int x,y,t;
            cin>>x>>y>>t;
            Node[x].push_back(Edge(y,t));
            Node[y].push_back(Edge(x,t));
        }
        for(int i = 0;i < 120;i++)for(int j = 0;j < 12;j++)vis[i][j] = 1e+9;
        priority_queue<Data> Q;
        Q.push(Data(s,0,0));
        while(!Q.empty()){
            Data D = Q.top();Q.pop();
            int p = D.pos;
            int k = D.ck;
            if(vis[p][k] < D.t)continue;
            for(int i = 0;i < Node[p].size();i++){
                Edge e = Node[p][i];
                if(vis[e.to][k] > D.t + e.cost){
                    vis[e.to][k] = D.t + e.cost;
                    Q.push(Data(e.to,vis[e.to][k],k));
                }
                if(k < c && vis[e.to][k + 1] > D.t + e.cost/2){
                    vis[e.to][k + 1] = D.t + e.cost/2;
                    Q.push(Data(e.to,vis[e.to][k + 1],k+1));
                }
            }
        }

        int ans = 1e+9;
        for(int i = 0;i <= c;i++){
            ans = min(ans, vis[d][i]);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1244
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    reverse(all(s));
    map<int,int> m;
    int n=s.length();
    int t=0;
    int p=1;
    m[0]=1;
    rep(i,n){
        t=(t+(s[i]-'0')*p)%2019;
        m[t]++;
        p=p*10%2019;
    }
    int ans=0;
    for(pi e:m)ans+=e.se*(e.se-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 3764
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;


int main() {
  string s;
  cin >> s;
  cin >> s;
  printf("A%cC\n", s[0]);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
typedef vector<int> vi; 
typedef vector<bool> vb; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
 
#define sz(x) (int)(x).size()
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define sor(x) sort(all(x))
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define endl '\n'
 
const ll MOD = 998244353;
const ll INF = 1e18;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int n, k; cin >> n >> k;
   vpi p(k);
   for (pi &i : p)
      cin >> i.f >> i.s;
   vi a(n + 1);
   a[1] = 1; a[2] = MOD - 1;
   int cur = 0;
   for (int i = 1; i <= n; i++) {
      cur = (cur + a[i]) % MOD;
      for (pi j : p) {
         if (i + j.f <= n) {
            a[i + j.f] = (a[i + j.f] + cur) % MOD;
            if (i + j.s < n)
               a[i + j.s + 1] = (a[i + j.s + 1] + MOD - cur) % MOD;
         }
      }
   }
   cout << cur;
   return 0;
}

Measured memory_bytes: 3984
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

struct Elem {
    int pos, mon; ll cost;
    Elem() {}
    Elem(int p, int m, ll c) : pos(p), mon(m), cost(c) {}
    bool operator<(const Elem &e) const {
        return cost > e.cost;
    }
};

ll dist[51][2510];
int main() {
    int N, M, S; scanf("%d%d%d", &N, &M, &S);
    chmin(S, 2500);
    
    vector< vector< tuple<ll, ll, ll> > > G(N);
    for(int i=0; i<M; i++) {
        ll u, v, a, b; scanf("%lld%lld%lld%lld", &u, &v, &a, &b);
        u--; v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }

    vector<ll> C(N), D(N);
    for(int i=0; i<N; i++) scanf("%lld%lld", &C[i], &D[i]);

    priority_queue<Elem> que;
    fill(dist[0], dist[N], LONGINF);
    dist[0][S] = 0;
    que.emplace(0, S, 0LL);
    while(que.size()) {
        int pos, mon; ll cost;
        Elem e = que.top(); que.pop();
        pos = e.pos, mon = e.mon, cost = e.cost;
        if(dist[pos][mon] < cost) continue;

        // 次に進む
        for(auto e : G[pos]) {
            ll to, A, B; tie(to, A, B) = e;
            ll n_mon = mon - A;
            ll n_cost = cost + B;
            if(n_mon >= 0 and dist[to][n_mon] > n_cost) {
                dist[to][n_mon] = n_cost;
                que.emplace(to, n_mon, n_cost);
            }
        }
        // 両替する
        {
            ll n_mon = min(0LL + mon + C[pos], 2500LL);
            ll n_cost = cost + D[pos];
            fprintf(stderr, "n_mon = %lld, n_cost = %lld\n", n_mon, n_cost);
            if(dist[pos][n_mon] > n_cost) {
                dist[pos][n_mon] = n_cost;
                que.emplace(pos, n_mon, n_cost);
            }
        }
    }

    for(int i=1; i<N; i++) {
        ll ans = LONGINF;
        for(int j=0; j<=2500; j++) {
            chmin(ans, dist[i][j]);
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 6860
import re

s = [i for i in input()]
flg = True
for i in range(len(s)):
  if i % 2 == 0 and re.match(r'L',s[i]):
    flg = False
  elif i % 2 != 0 and re.match(r'R',s[i]):
    flg = False
print("Yes" if flg else "No")

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>


using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

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

class UnionFind {

private:
  int N;
  vector<int> par;
  vector<int> rank;

  void init(int n)  {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }

public:
  UnionFind(int n) {
    N = n;
    par.resize(n);
    rank.resize(n);
    init(n);
  }


  int  root(int x) {
    if( par[x] == x ) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);

    if( x == y) return;

    if( rank[x] < rank[y] ) {
      par[x] = y;
    } else {
      par[y] = x;
      if(rank[x] == rank[y]) { rank[x]++; }
    }

  }

};



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

  int N, K, L;
  cin >> N >> K >> L;

  UnionFind uf_roads(N);
  UnionFind uf_rails(N);

  for(int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    --p; --q;
    uf_roads.unite(p, q);
  }


  for(int i = 0; i < L; i++) {
    int r, s;
    cin >> r >> s;
    --r; --s;
    uf_rails.unite(r, s);
  }

  map< P, int > mp;
  for(int i = 0; i < N; i++) {
    int rd = uf_roads.root(i);
    int tr = uf_rails.root(i);
    mp[ P(rd, tr) ]++;
  }

  for(int i = 0; i < N; i++) {
    int rd = uf_roads.root(i);
    int tr = uf_rails.root(i);
    cout << mp[ P(rd, tr) ] << " ";
  }
  cout << endl;


  return 0;
}


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

using llong = long long;

int main() {

    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 1;
    for (int i = 1; i < N; i++) {
        if (S[i - 1] != S[i]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512