akhauriyash/Code-Regression huggingface dataset:
#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=INT_MAX,MOD=1e9+7;

int main(){
    int n; cin>>n;
    bool open[n][10]; rep(i,n)rep(j,10) cin>>open[i][j];
    int profit[n][11]; rep(i,n)rep(j,11) cin>>profit[i][j];

    int ans=-INF;
    for(int i=1;i<(1<<10);i++){
        int tmp=0;
        for(int shop=0;shop<n;shop++){
            int cnt=0;
            for(int j=0;j<10;j++){
                if((i>>j&1)&&open[shop][j]) cnt++;
            }
            tmp+=profit[shop][cnt];
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int64 gcd(int64 a, int64 b) {
  while (b) {
    int64 c = a;
    a = b;
    b = c % b;
  }
  return a;
}

int64 solve(int64 n, int64 C, int64 D) {
  int64 ret = n / C + n / D;
  int64 G = C / gcd(C, D) * D;
  ret -= n / G;
  ret = n - ret;
  return ret;
}

int main() {
  int64 A, B;
  int C, D;
  cin >> A >> B >> C >> D;
  int64 ret = solve(B, C, D);
  ret -= solve(A - 1, C, D);
  cout << ret << endl;
  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) cout << "Left" << endl;
  else if (A + B < C + D) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 約数列挙：nの約数を昇順に返す
vector<long long> enumDivisors(long long n){
    vector<long long> ret;
    for(long long i=1; i*i<=n; i++){
        if(n%i == 0){
            ret.push_back(i);
            if(n/i != i) ret.push_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, m, ans = 1; cin >> n >> m;

    auto eDiv = enumDivisors(m);
    for(long long i=0; i<eDiv.size(); i++){
        if(eDiv[i] > (1.0*m/n)) break;
        else ans = eDiv[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define mp(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define all(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define pb push_back
#define pf push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


void solve(){
    int n, a, b, ct;
    ll ans;
    string s;
    
    ans = 0;
    
    cin >> n >> a >> b;
    rep1(i, n){
        s = to_string(i);
        ct = 0;
        for(auto i:s)
            ct += i - '0';
        if(ct >= a && ct <= b)
            ans += i;
    }
    cout << ans << '\n';
}

int main(){
    
    solve();
}





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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int
typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n;
  cin >> n;
  vector<int> v(n, 0);
  int maxv = -1;
  int minv = INT_MAX;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    maxv = max(maxv, v[i]);
    minv = min(minv, v[i]);
  }
  cout << maxv - minv << endl;

}

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

using namespace std ;

#define N 100010
#define inf 0x3f3f3f3f

int n , K , d[ N ] ;
int head[ N << 1 ] , cnt , vis[ N ] ;
struct edge {
	int to , nxt ;
}e[ N << 1 ] ; 
priority_queue< pair<int,int> , vector< pair<int,int> > , greater< pair<int,int> > > q ;

void ins( int u , int v ) {
	e[ ++ cnt ].to = v ;
	e[ cnt ].nxt = head[ u ] ;
	head[ u ] = cnt ;
}

int main() {
	for( int i = 0 ; i < N ; i ++ ) d[ i ] = inf ;
	scanf( "%d" , &n ) ;
	for( int i = 1 ; i < n ; i ++ ) {
		int u , v ;
		scanf( "%d%d" , &u , &v ) ;
		ins( u , v ) ; ins( v , u ) ;
	}
	scanf( "%d" , &K ) ;
	for( int i = 1 ; i <= K ; i ++ ) {
		int p , v ;
		scanf( "%d%d" , &v , &p ) ;
		d[ v ] = p ;
		q.push( make_pair( p , v ) ) ;
	}
	while( !q.empty() ) {
		int u = q.top().second , val = q.top().first ;
		q.pop() ; 
		for( int i = head[ u ] ; i ; i =e[ i ].nxt ) {
			int v = e[ i ].to ;
			if( d[ v ] == inf ) d[ v ] = val + 1 , q.push( make_pair( d[ v ] , v ) ) ;
			if( abs( d[ v ] - d[ u ] ) != 1 ) {
				puts( "No" ) ;
				return 0 ;
			}
		}
	}
	puts( "Yes" ) ;
	for( int i = 1 ; i <= n ; i ++ ) {
		printf( "%d\n" , d[ i ] ) ;
	}
	return 0 ;
}

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

int main(){
	int H, W;

	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0) break;

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
from operator import itemgetter
import copy
N= int(input())
S=[]
P=[]
SP=[]


for i in range(N):
    S1,P1=input().split()
    S.append(S1)
    P.append(int(P1))
    SP.append([S1,int(P1)])
SPold = copy.deepcopy(SP)
#print(SPold)
SPsort = sorted(SP, key = lambda x:(x[0],-x[1]))
#SP.sort(key=itemgetter(0,1))
#SP.sort(key=itemgetter(1))
#print(SPsort)
for i in range(N):
    for j in range(N):
        if SPsort[i] == SPold[j]:
            print(j+1)

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

def DFS(s):
    if int(s) > N:
        return 0
    if "7" in s and "5" in s and "3" in s:
        ret = 1
    else:
        ret = 0
    for c in "753":
        ret += DFS(s + c)
    return ret

print(DFS("0"))

Measured memory_bytes: 9160
/**
 * Created by yoshiwaratomohiro on 2017/06/18.
 */
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int[] snum = new int[s.length()];
        for(int i=0;i<s.length();i++){
            snum[i]=s.charAt(i)-'a';
        }

        int min=10000;
        for(int i=0;i<26;i++){
            int[] ans = new int[s.length()];
            for(int j=0;j<s.length();j++){
                ans[j]=i;
            }

            int s_[] = new int[s.length()];
            for(int j=0;j<s.length();j++){
                s_[j]=snum[j];
            }


 inside:           for(int j=0;j<s.length();j++){
                for(int k=0;k<s_.length;k++){
                    if(s_[k]!=i){
                        break;
                    }
                    if(k==s_.length-1){
                        min=Math.min(min,j);
                        break inside;
                    }
                }


                    int[] conv=new int[s.length()-j-1];

                for(int k=1;k<s.length()-j;k++){
                    if(s_[k-1]==i||s_[k]==i){
                        conv[k-1]=i;
                    }else{
                        conv[k-1]=s_[k-1];
                    }
                }
                s_=new int[s.length()-j-1];
                for(int k=0;k<s.length()-j-1;k++){
                    s_[k]=conv[k];
                }
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 22100
w,h,N=map(int,input().split())
X,Y,W,H=0,0,w,h
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:X=max(x,X)
    elif a==2:W=min(W,x)
    elif a==3:Y=max(y,Y)
    else:H=min(y,H)
    if X>=w or Y>=h or W<=0 or H<=0 or X>=W or Y>=H:
        print(0)
        exit()
print((W-X)*(H-Y))

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<ii> a(n);
	for (int i=1; i<=n; i++) {
		int x; cin>>x;
		a[i-1]={x,i};
	}
	sort(a.begin(),a.end());
	for (auto it : a)
		cout<<it.second<<" ";
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int loop;
		int numA;
		int numB;

		String output = "";
		String line;
		String command;

		Scanner sc = null;



		try {
			sc = new Scanner(System.in);
			//?????????????????????????????\???????´?
			line = sc.nextLine();
			String[] word = line.split("");

			//???????????°???????????????
			loop = sc.nextInt();
			for (int i = 0; i < loop; i++) {
				command = sc.next();

				//???????????§??????
				switch (command) {

				//print
				case "print":
					numA = sc.nextInt();
					numB = sc.nextInt();

					for (int j = numA; j <= numB; j++) {
						output += word[j];
					}
					System.out.println(output);

					output = "";
					break;

				//reverse
				case "reverse":
					numA = sc.nextInt();
					numB = sc.nextInt();
					String s = "";
					int size = numB - numA;
					for (int j = 0; j <= size / 2; j++) {
						s = word[numB];
						word[numB] = word[numA];
						word[numA] = s;
						numA++;
						numB--;

					}
					break;

				//replace
				case "replace":
					numA = sc.nextInt();
					numB = sc.nextInt();
					line = sc.next();
					String[] list = line.split("");
					for (int k = 0; k < list.length; k++) {
						word[numA] = list[k];
						numA++;
					}
					break;
				default:
					break;
				}
			}


		} finally {
			sc.close();
		}
	}

}

Measured memory_bytes: 49712
#include<stdio.h>
int main(){
	int a[6],b,c,d,e,f=0,i;
	for(i=0;i<5;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<40)
		{
			a[i]=40;
		}
	}
	f=a[0]+a[1]+a[2]+a[3]+a[4];
	f=f/5;
	printf("%d\n",f);
	
	return 0;
	}


Measured memory_bytes: 2048
s = input()
a = "".join(str(i % 2) for i in range(len(s)))
b = "".join(str(i % 2) for i in range(1, len(s) + 1))
da = bin(int(a, 2) ^ int(s, 2)).count("1")
db = bin(int(b, 2) ^ int(s, 2)).count("1")
print(min(da, db))

Measured memory_bytes: 9588
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Combination comb(2000001);
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	mint ans = 0;
	for(int i = r1; i <= r2; ++i){
		ans += comb(c2+i+1, i+1) - comb(c1+i, i+1);
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 34228
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    long long x,l,last,cnt,i;
    vector<pair<long long,long long>> v(n);
    for(i=0;i<n;++i)
    {
        cin>>x>>l;
        v[i].first = x+l;
        v[i].second = x-l;
    }
    sort(v.begin(),v.end());
    last = v[0].first;
    cnt = 1;
    for(i=0;i<n;++i)
    {
        if(v[i].second >= last)
        {
            ++cnt;
            last = v[i].first;
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int N;
    cin >> N;
    multiset<string> mset;
    set<string> set;
    REP(i, N){
        string s;
        cin >> s;
        mset.insert(s);
        set.insert(s);
    }
    vector<pair<int, string>> array(set.size());
    int i = 0;
    for (auto x : set)
    {
        // cout << x;
        int cnt = mset.count(x);
        array.push_back(make_pair(cnt, x));
        // array.at(i).first = x;
        // array.at(i).second = cnt;
        i++;
    }
    sort(array.begin(), array.end(), greater<pair<int,string> >());

    // REP(i, set.size()) {
    //     cout << array.at(i).first << " " << array.at(i).second << endl;
    // }
    // cout << endl;
    vector<string> ans;
    REP(i, set.size())
    {
        ans.push_back(array.at(i).second);
        // cout << array.at(i).second << endl;
        if(array.at(i).first != array.at(i+1).first)
            break;
    }
    sort(ALL(ans));
    REP(i, ans.size()) {
        cout << ans.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 41288
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n, m;
int map[200];
int main(){
	int i, j, k;
	cin >> n;
	memset(map, 0, sizeof(map));
	for(i = 1; i <= 9; ++i)
		for(j = 1; j <= 9; ++j){
			map[i*j] = 1;
		}
	if(map[n] == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll md = 1000000007;
vector<ll> fact(1e6+7), invfact(1e6+7);

ll fn(ll n, ll a, ll r, ll mod = md) {
    ll res = 1, x = r%mod;
    ll ans = 0;
    while(n) {
        if(n&1) ans = (x*ans + res)%mod;
        res = ((res*x)%mod + res%mod)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    ans = (ans*a)%mod;
    return ans;
}

ll nCr(ll n, ll r) {
    if(r == 0) return 1;
    ll num = fact[n];
    ll den = (invfact[r] % md *invfact[n-r] % md)%md;
    return (num*den)%md;
}

ll mul(ll a, ll b, ll mod = md) {
    ll res = (a%mod * b%mod)%mod;
    return res;
}

ll mulm(ll a, ll b, ll mod = md) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) r = (r+a)%mod;
        a = (a+a)%mod;
        b = b/2;
    }
    r %= mod;
    return r;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(ll x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll compgcd(ll n, vector<ll> const &primes) 
{ 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<bool> &prime, vector<ll> &primes, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

void sieveGCD(ll lim, vector<ll> &tab, vector<ll> const &primes) {
    for(int  i = 1; i <= lim; i++) {
        tab[i] = i;
    }
    for(int i = 0; i<primes.size() && primes[i] <= lim; i++) {
        tab[primes[i]] = primes[i]-1;
        for(int j = 2; primes[i]*j <= lim; j++) {
            tab[primes[i]*j] = (tab[primes[i]*j]/primes[i])*(primes[i]-1);
        }
    }
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin >> a >> b;
    if(a <= b) {
        cout << "unsafe\n";
    } else {
        cout << "safe\n";
    }
    return 0; 
}

Measured memory_bytes: 18628
N = int(input())
xy = []
A = []
for i in range(N):
    Ai = int(input())
    xyi = []
    for j in range(Ai):
        xyi.append(list(map(int, input().split())))
    A.append(Ai)
    xy.append(xyi)

ans = 0

for i in range(2**N):
    bin_i = format(i, '0' + str(N) + 'b')
    flag = True
    for j in range(N):
        for k in range(A[j]):
            if bin_i[j] == '1' and xy[j][k][1] != int(bin_i[xy[j][k][0]-1]):
                flag = False
                break
        if not flag:
            break

    if flag is True:
        honest = bin_i.count('1')
        if honest > ans:
            ans = honest

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (ll i(a), _##i(b); i <= _##i; ++i)

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                                             \
  cerr << "\033[2;31mLine " << __LINE__ << ": \033[0;m";                       \
  FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  cerr << endl
#else
#define debug(...)
#endif

using namespace std;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = begin(c); it != end(c); ++it)
    os << (it == begin(c) ? "" : ", ") << *it;
  return os << ']';
}
using ll = long long;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int &x : a) cin >> x;
  const int INF = 1 << 30;
  vector<int> ans(n, INF);
  ans[0] = 0;
  for(int i = 1; i < n; ++i){
    for(int j = 1; j <= k && i - j >= 0; ++j){
      ans[i] = min(ans[i], ans[i - j] + abs(a[i] - a[i - j]));
    }
  }
  debug(ans);
  cout << ans[n - 1] << "\n";
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

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

    int count1 = 0;
    for(int i=x; i<n; i++){
        for(int j=0; j<m; j++){
            if(i==a[j]) count1++;
        }
    }
    int count2 = 0;
    for(int i=x; i>=0; i--){
        for(int j=0; j<m; j++){
            if(i==a[j]) count2++;
        }
    }
    int count = (count1 < count2)? count1: count2;
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 384
n,m = map(int, input().split())
def intm(x):
  return int(x)*-1
a = list(map(intm, input().split()))

import heapq

heapq.heapify(a)

for _ in range(m):
  x = heapq.heappop(a)
  x = int(x/2)
  heapq.heappush(a,x)
  
print(sum(a)*-1)

Measured memory_bytes: 14224
#include "bits/stdc++.h"

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	int n, count = 0, value = 1;
	cin >> n;
	VI a(n);
	IN(n, a);

	FOR(0, n)
	{
		if (a[i] == value)
		{
			count++;
			value++;
		}
	}

	if (count == 0)cout << "-1";
	else cout << n - count;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i = 0; i<N; ++i) {
    cin >> p[i];
  }
  
  int cnt = 0;
  for(int i = 0; i<N; ++i) {
    if (p[i] != i+1) cnt++;
  }
  
  if (cnt <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	vector<int> h(n);
	rep(i, n) cin >> h[i];

	int ans = 0;
	int t = 0;
	for(int i = 0; i < n-1; i++){
		if(h[i+1] <= h[i]){
			t++;
			ans = max(ans, t);
		}else{
			t = 0;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,d[11][11];

int main(){
	while(cin>>n){
		if(n==0)return 0;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>d[i][j];
		int ss=0;
		for(int i=0;i<n;i++){
			int s=0;
			for(int j=0;j<n;j++)s+=d[i][j];
			d[i][n]=s;
			ss+=s;
			s=0;
			for(int j=0;j<n;j++)s+=d[j][i];
			d[n][i]=s;
		}
		d[n][n]=ss;
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				int m=1,p=10;
				while(d[i][j]>=p){m++;p*=10;}
				for(int k=0;k<5-m;k++)cout<<" ";
				cout<<d[i][j];
			}
			cout<<endl;
		}
	}
}

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

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  ll left, right;
  right = b / x;
  left = a / x;
  ll ans;
  if (a % x == 0) ans = (right -left) + 1;
  else ans = (right - left);
  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>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ods;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

void solve(ll t)
{
    // cout<<"Case #"<<t<<":\n";
    ll r;
    cin>>r;
    ld PI=3.141592653589793;
    ld ans=2*PI*r;
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    ll tt=1;
    while(t--)
    {
        solve(tt);
        tt++;
    }
}     


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

using namespace std;

typedef long long ll; // ll  is 64bit same as double

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int K;
	string S;
	
	cin >> K >> S;
	
	if((int)S.length()<=K)
		cout << S << "\n";
	else {
		string ans = S.substr(0, K);
		for(int i=0; i<3; ++i){
			ans  +=  ".";			
		}
		cout << ans <<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 3648
class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), self.find(y)
        if x == y:
            return

        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    uf = UnionFind(size=N)
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        uf.unite(a, b)

    max_size = -1
    for i in range(N):
        if uf.find(i) == i:
            max_size = max(max_size, uf.get_size(i))
    print(max_size)


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, r[9], cl;

int main() {
	cin >> n;
	rep(i,n) {
		cin >> a;
		if (a>=3200) r[8]++;
		else r[a/400]++;
	}
	
	rep(i,8) if (r[i]>0) cl++;
	cout << max(cl,1) << " " << cl+r[8] << ln;
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

ll cal(ll r){
    return r*r*r*r*r;
}

int main(){
    int n; cin >> n;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    map<int,ll> mp;
    ll ans = 0;
    rip(i,n,0){
        if(mp.count(i-da[i])){
            ans += mp[i-da[i]];
        }
        if(mp.count(i+da[i])){
            mp[i+da[i]]++;
        }
        else{
            mp[i+da[i]] = 1;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  cout << C - min(A - B, C) << endl;
}




Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s, front = "", ending = ""; int n; cin >> s >> n;
	bool rev = false;
	while(n--) {
		int a; cin >> a;
		if(a == 1) {
			rev = !rev;
		}
		else {
			int b; char c; cin >> b >> c;
			if((b == 1 and rev) or (b == 2 and !rev)) ending += c;
			else front += c;
		}
	}
	reverse(front.begin(), front.end());
	string ans = front+s+ending;
	if(rev) reverse(ans.begin(), ans.end());
	println(ans);
}


Measured memory_bytes: 1300
a = []
b = []
calc = 0
j = 0
k = 0

n, m, l = map(int, input().split())

i = 0
while i < n:
    a.append(list(map(int, input().split())))
    i += 1

i = 0
while i < m:
    b.append(list(map(int, input().split())))
    i += 1

for i in range(n):
    for j in range(l):
        calc = 0

        for k in range(m):
            calc += a[i][k] * b[k][j]
        
        print("%s" % calc, end="")
        if j < l - 1:
            print(" ", end="")
        else:
            print("")



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

int main() {
    int N, K;
    cin >> N >> K;

    double res = 0.0;

    // 出た目をxとする。
    for (int x = 1; x <= N; x++) {
        double p = 1.0 / (double)N;  // 確率
        int X = x;
        while (X < K) {
            X *= 2;
            p *= 0.5;
        }
        res += p;
    }

    cout << std::fixed << std::setprecision(15);
    cout << res << endl;
}

Measured memory_bytes: 3760
#include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  while(cin>>s){
    int a=0,b=0;
    r(i,s.size()-2){
      if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I')a++;
      if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I')b++;
    }
    cout<<a<<endl<<b<<endl;
  }
}

Measured memory_bytes: 3148
//#include <cstdio>
//#include <fstream>
#include <iostream>
#include <map>
//#include <sstream>
//#include <string>
#include <vector>
#include <set>
#include <queue>          // std::priority_queue

//#define BUF_SIZE 16384

using namespace std;


class WeightedEdge {
public:
	int s_;
	int t_;
	int w_;
	WeightedEdge(int s, int t, int w) { s_ = s; t_ = t; w_ = w; }

	bool operator < (const WeightedEdge& p1) const {
		return this->w_ > p1.w_;
	}

	bool operator > (const WeightedEdge& p1) const {
		return this->w_ < p1.w_;
	}
};

int v_, e_;

vector<vector<WeightedEdge>> adjacency_list;
set<int> visited_nodes;

priority_queue<WeightedEdge> candidate_edge_queue;

vector<WeightedEdge> mst;

void read() {
	cin >> v_;
	cin >> e_;
	adjacency_list.resize(e_);

	for (int i = 0; i < e_; ++i) {
		int s, t, w;
		cin >> s >> t >> w;

		adjacency_list[s].emplace(adjacency_list[s].end(), s, t, w);
		adjacency_list[t].emplace(adjacency_list[t].end(), t, s, w);
	}

	visited_nodes.insert(0);
}

int build_mst() {
	int mst_edge_count = 0;
	int sum = 0;
	for (int mst_edge_count = 0; mst_edge_count < v_ - 1; ++mst_edge_count) {
		//if (mst_edge_count % 1000 == 0) {
		//	cout << "mst_edge_count = " << mst_edge_count << endl;
		//}

		for (auto s : visited_nodes) {
			//cout << "s = " << s << endl;
			auto l = adjacency_list[s];
			while (!l.empty()) {
				auto e = l[l.size() - 1];
				//cout << "current edge: " << e.s_ << " " << e.t_ << " " << e.w_ << endl;
				if (visited_nodes.count(e.t_) == 0) {
					//cout << "not visited, adding to the queue." << endl;
					candidate_edge_queue.emplace(e);
				}

				//cout << "vector size before: " << l.size() << endl;
				l.pop_back();
				//cout << "vector size after: " << l.size() << endl;
				adjacency_list[s] = l;
			}
		}

		for (int added = 0; added < 1;){
			WeightedEdge next_edge = candidate_edge_queue.top();
			candidate_edge_queue.pop();
			//cout << "next edge: " << next_edge.s_ << " " << next_edge.t_ << " " << next_edge.w_ << endl;
			if (visited_nodes.count(next_edge.t_) == 0) {
				visited_nodes.insert(next_edge.t_);
				sum += next_edge.w_;
				added = 1;
			}
		}
	}

	return sum;
}

//void show_adjacency_list() {
//	for (auto x : adjacency_list) {
//		cout << x.s_ << " " << x.t_ << " " << x.w_ << endl;
//	}
//}

void show_graph_nodes(set<int> graph) {
	for (auto n : graph) {
		cout << n << endl;
	}
}

int main() {
	read();
	cout << build_mst() << endl;
	return 0;
}

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

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0,s=a+b;
    ll t = n/s;
    ans += a*t;
    ll tt = n%s;
    ans += min(tt,a);
    cout<<ans;
}

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

	int N, M;
	cin >> N >> M;
	vecl(A)
		pairs(BC)
		fx(N) {
		vecpl(A)
	}
		fx(M) {
			int c, b;
			cin >> c >> b;
			pb(BC,make_pair(b,c))
	}
		

		sorts(BC)
			reverses(BC)
			sorts(A)
			int j = 0;
		fx(N) {
			if (j >= M) { break; }

			if (A.at(x) < BC.at(j).first) {
				A.at(x) = BC.at(j).first;
				BC.at(j).second--;
				if (BC.at(j).second<=0) {
					j++;
				}
			}
			else {
				break;
			}
		}
		ll ans = 0;
		fx(N) {
			ans += A.at(x);
		}
		ce(ans)

    return 0;
}



Measured memory_bytes: 2548
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int n;
	cin >> n;

	int x = 0, y = 0;
	FOR(i, 1, 100001) {
		x += i;
		if (n <= x) {
			x = i;
			break;
		}
	}

	for (; n; x--) {
		if (x <= n) {
			cout << x << endl;
			n -= x;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

ll RepeatSquaring(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RepeatSquaring(N, P / 2, M);
		return t * t % M;
	}
	return N * RepeatSquaring(N, P - 1, M);
}

long long gcd(long long a, long long b)
{
	long long tmp, r;
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll n;
	cin >> n;

	vector<vector<ll>> f(10, vector<ll>(10, 0));

	for (int i = 1; i <= n; i++)
	{
		int tmp = i;
		int fi = tmp % 10;
		while (tmp/10!=0)
		{
			tmp /= 10;
		}
		int en = tmp;
		f[fi][en]++;
	}
	ll ans = 0;

	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			ans += f[i][j] * f[j][i];
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
  public static void main(String[] args) throws Exception {
    String line = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    line = br.readLine();
    long len = line.length();
    long aCount[] = new long[26];
    long rev = 0;
    long answer = 1;
    // 各アルファベットの出現回数をカウント
    for (char chr: line.toCharArray()) {
      aCount[(chr - 'a')]++;
    }
    // 各アルファベットのペアの総数をカウント
    for (int i = 0; i < 26; i++) {
      long data = aCount[i];
      if (data > 1) {
        rev = rev + data * (data - 1) / 2;
      }
    }
    if (len > 1) {
      answer = answer + len * (len - 1) / 2;
    }
    System.out.println(answer - rev);
  }
}

Measured memory_bytes: 25516
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

fn main() {
    
    let inl = read_t_in_line::<i64>();
    let (q, h, s, d) = (inl[0], inl[1], inl[2], inl[3]);
    let n = read_t_in_line::<i64>()[0];

    let half = min(q * 2, h);
    let one  = min(half * 2, s);
    let two  = min(one * 2, d);
    println!("{}", (n / 2) * two + (n % 2) * one);

}


Measured memory_bytes: 4352
import java.util.Scanner;
 
/**
 * Created by zzt on 17-1-16.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char c = scanner.next().charAt(0);
        switch (c) {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                System.out.println("vowel");
                break;
            default:
                System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 9676
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string a, b;
    cin >> a >> b;
    
    if (a == "H" && b == "H"){
        cout << "H" << endl;
    } 
    else if (a == "H" && b == "D"){
        cout << "D" << endl;
    }
    else if (a == "D" && b == "H"){
        cout << "D" << endl;
    }
    else {
        cout << "H" << endl;
    }
}

Measured memory_bytes: 256