akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
string s,t;

bool getAns() {
	forl(i,s.size()) if(s[i] != t[i]) return 0;
	return 1;
}

int main(void)
{
	fastio
	cin>>s;
	cin>>t;
	if(getAns()) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3656
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int k;
    cin>>k;
    vi v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    while(1){
        int a,b,c ;
        cin >> a >> b >> c ;
        if(a==b&&b==c&&c==-1) break ;
        if(a==-1||b==-1) cout << 'F' << endl ;
        else if(a+b>=80) cout << 'A' << endl ;
        else if(a+b>=65) cout << 'B' << endl ;
        else if(a+b>=50) cout << 'C' << endl ;
        else if(a+b>=30){
            if(c>=50) cout << 'C' << endl ;
            else cout << 'D' << endl ;
        }else cout << 'F' << endl ;
    }
}


Measured memory_bytes: 3088
import java.util.Scanner;

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

        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        int[] output = new int[10000];
        int i;
        for(i = 0; input != 0; i++){
            output[i] = input;
            input = scan.nextInt();
        }

        int j;
        for(j = 0; j < i; j++){
            System.out.println("Case " + (j+1) + ": " + output[j]);
        }
    }
}



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

int main() {
	map<char, string> S;
	cin >> S['a'] >> S['b'] >> S['c'];
	char turn='a', next;
	while(!S[turn].empty()){
	    next=S[turn][0];
	    S[turn].erase(S[turn].begin());
	    turn=next;
	}
	char win='A'-'a'+turn;
	cout << win << endl;
	return 0;
}


Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
PJ = [[] for _ in range(M)]
for _ in range(N):
	a,b = map(int, input().split())
	if M-a >= 0:
		PJ[M-a].append(b)

q = []
cnt = M-1
ans = 0
while cnt >= 0:
	for b in PJ[cnt]:
		heapq.heappush(q,-b)
	if len(q) > 0:
		src = heapq.heappop(q)
		ans += src
	cnt -= 1
print(-ans)

Measured memory_bytes: 18408
#include <iostream>
#include <vector>
#include <iomanip>
#include <math.h>

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

    std::vector<double> x(N);
    std::vector<double> y(N);

    for (int i = 0; i < N; i++)
    {
        std::cin >> x[i] >> y[i];
    }
    // for (int i = 0; i < N; i++)
    // {
    //     std::cout << x[i] << ", " << y[i] << std::endl;
    // }

    // solve
    // std::cout << "SOLVE" << std::endl;
    int fact_num = 1;
    for (int i = 2; i <= N; i++)
    {
        fact_num *= i;
    }
    int fact_num2 = 1;
    for (int i = 2; i <= N-1; i++)
    {
        fact_num2 *= i;
    }
    // std::cout << fact_num << ", " << fact_num2 << std::endl;

    double dist_sum = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            // std::cout << i << ", " << j << std::endl;
            // dist = sqrt( pow((x[i] - x[j]), 2) + pow((y[i] - y[j]), 2) );
            double dx = x[i] - x[j];
            double dy = y[i] - y[j];
            double dist = pow(dx * dx + dy * dy, 0.5);
            // std::cout << dist << std::endl;
            dist_sum += dist;

        }
    }

    // double ans = dist_sum * (double)fact_num2 * 2 / (double)fact_num;
    double ans = dist_sum * 2 / (double)N;
    std::cout << std::fixed << std::setprecision(10) << ans << std::endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int bubbleSort(int* A, int N);

int main(void){
	int n;
	scanf("%d",&n);
	
	int *num;
	num = (int *)malloc(sizeof(int)*n);
	if(num == NULL){
		printf("failure\n");
		exit(1);
	}
	
	//int num[100];
	int i,chnum;

	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}

	chnum=bubbleSort(num,n);

	printf("%d",num[0]);
	for(i=1;i<n;i++){
		printf(" %d",num[i]);
	}
	printf("\n%d\n",chnum);

	/*
	num[0]=1;
	printf("%d\n",num[0]);
	*/
	/*
	gets(num);
	gets(num+1);
	puts(num);
	puts(num+1);
	*/
	free(num);

	return 0;
}

int bubbleSort(int *num,int n){
	int esc,j,flag=1,chnum=0;
	while(flag){
		flag=0;
		for(j=n-1;j>0;j--){
			if(num[j]<num[j-1]){
				esc=num[j];
				num[j]=num[j-1];
				num[j-1]=esc;
				flag=1;
				chnum++;
			}
		}
	}
	return chnum;
}

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

#define int long long
#define vc vector<char>
#define vi vector<int>
#define vs vector<string>
#define si set<int>
#define pii pair<int,int>
#define SORT(c) sort(c.begin(),c.end())
#define SORTC(c, cmp) sort(c.begin(),c.end(),cmp)
#define mapii map<int,int>
#define pb push_back
#define F first
#define S second
#define rep(i, j, k) for (int i=j;i<k;i++)
#define repb(i, j, k) for (int i=j;i>=k;i--)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ar array

using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0)


const int mxN = 2e5;
int a[mxN];
int n;

void solve() {
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());
    int sum = 0;
    rep(i, 1, n) {
        sum += a[i / 2];
    }
    cout << sum;
}

int32_t main() {
    fast;

    int tt{1};
//    cin >> tt;
    while (tt--) {
        solve();
        cout << endl;
    }
    return 0;

}

Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <cctype>
#include <locale>

using namespace std;

int main(){
    string str, result;
    getline(cin, str); //空白文字含めて1行丸ごと取得したいときは、getline関数を使う
    // result = str;
    // cout << str << endl;
    locale l = locale::classic(); //touppser,tolowerクラスはlocaleを与えることで返り値がintからcharに変換できる
    for(int i = 0; i < str.size(); i++) {
        auto isLower = islower(str[i]); //stringを一文字ずつ小文字か判定
        // cout << (bool)islower(str[i]) << endl;
        if (isLower) { //小文字の場合、大文字に変換
            // cout << toupper(str[i],l);
            result += toupper(str[i],l); //stringの文字列連結は+演算子でいける
            // result.replace(i, i+1, toupper(str[i], l));
        } else { //大文字の場合、小文字に変換
            // cout << tolower(str[i],l);
            result += tolower(str[i]);
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
int main(void){
    int w[10],k[10],a;
    for(int i=0;i<10;++i){
        std::cin>>w[i];
    }
    for(int i=0;i<10;++i){
        std::cin>>k[i];
    }
    for(int i=0;i<9;++i){
        for(int j=i+1;j<10;++j){
            if(w[j]>w[i]){
                a=w[i];
                w[i]=w[j];
                w[j]=a;
            }
        }
    }
    for(int i=0;i<9;++i){
        for(int j=i+1;j<10;++j){
            if(k[j]>k[i]){
                a=k[i];
                k[i]=k[j];
                k[j]=a;
            }
        }
    }
    std::cout<<w[0]+w[1]+w[2]<<" "<<k[0]+k[1]+k[2]<<std::endl;
    return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> V(N);
    for(int i = 0; i<N; ++i){
        cin >> V[i];
    }

    ll ans = 0;
    for(int p = 0; p<=min(K,N); p++){
        for(int q = 0; p + q <= min(K,N); q++){
            vector<ll> w;
            ll a = 0;
            for(int i = 0; i < p; i++){
                w.push_back(V[i]);
                a += V[i];
            }
            for(int i = 0; i < q; i++){
                w.push_back(V[N-1-i]);
                a += V[N-1-i];
            }
            sort(w.begin(), w.end());

            for(int i = 0; i < min(K-q-p, (int)w.size()); i++){
                if(w[i] < 0){
                    a -= w[i];
                }
            }
            ans = max(ans, a);
        }
    }

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

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

int n, k, dp[1005][1005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	
 	cin >> n >> k;

 	for (int i = 1; i <= k; i++) {
 		dp[1][i] = i;
 	}

 	for (int i = 2; i <= n; i++) {
 		for (int j = 1; j <= k; j++) {
 			dp[i][j] = dp[i][j-1] + (dp[i-1][k] - (dp[i-1][j] - dp[i-1][j-1]));
 		}
 	}

 	cout << dp[n][k] << '\n';
 	
	return 0;
}

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


int main(){
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if(U==S){
    A--;
  }else{
    B--;
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    lli n;
    cin>>n;
    cout<<(n-2)*180<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int H, N;
  cin >> H >> N;
  int* A = new int[N];
  int sum=0;
  for(int i=0; i<N; i++){
	cin >> A[i];
	sum+=A[i];
  }

  //cout << sum << endl;
  if(H <= sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  delete[] A;
  return 0;
}


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

using namespace std;

int count(vector<vector<int>> &ban, int fromx, int tox, int fromy, int toy) {
    fromx--;
    fromy--;
    if (fromx >= tox || fromy >= toy)return 0;
    return ban[tox][toy] - ban[fromx][toy] - ban[tox][fromy] + ban[fromx][fromy];
}

int main() {
    int n, k;
    cin >> n >> k;

    vector<vector<int>> black(k + 1, vector<int>(k + 1));
    vector<vector<int>> white(k + 1, vector<int>(k + 1));
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= 2 * k;
        y %= 2 * k;

        bool isblack = c == 'B';
        if (x >= k) {
            x -= k;
            isblack = !isblack;
        }
        if (y >= k) {
            y -= k;
            isblack = !isblack;
        }

        if (isblack)black[x + 1][y + 1]++;
        else white[x + 1][y + 1]++;
    }

    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if (i > 0) {
                black[i][j] += black[i - 1][j];
                white[i][j] += white[i - 1][j];
            }
            if (j > 0) {
                black[i][j] += black[i][j - 1];
                white[i][j] += white[i][j - 1];
            }
            if (i > 0 && j > 0) {
                black[i][j] -= black[i - 1][j - 1];
                white[i][j] -= white[i - 1][j - 1];
            }
        }
    }

    int ret = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            ret = max(ret, count(black, 1, i, 1, j) + count(white, i + 1, k, 1, j) +
                           count(white, 1, i, j + 1, k) + count(black, i + 1, k, j + 1, k));
            ret = max(ret, count(white, 1, i, 1, j) + count(black, i + 1, k, 1, j) +
                           count(black, 1, i, j + 1, k) + count(white, i + 1, k, j + 1, k));
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define rrep(i, s, n) for (int i = (s); i > (n); i--)

int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, 0, N) cin >> H[i];
    rrep(j, N-1, 0)
    {
        int dif = H[j-1] - H[j];
        if(dif >= 2)
        {
            cout << "No" << endl;
            return 0;
        } 
        if(dif == 1) H[j-1]--;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
#define def infl
template<class V, int NV> struct SegTree { //[l,r)
	V comp(V& l, V& r) { return min(l, r); };

	vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
	V get(int x, int y, int l = 0, int r = NV, int k = 1) {
		if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
		auto a = get(x, y, l, (l + r) / 2, k * 2);
		auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
		return comp(a, b);
	}
	void update(int i, V v) {
		i += NV; val[i] = v;
		while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
	}
	void add(int i, V v) { update(i, val[i + NV] + v); }
	V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/











int N, M;
vector<pair<int, int>> Q[101010];
SegTree<ll, 1 << 17> st;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int l, r, c; cin >> l >> r >> c;
		Q[r].push_back({ l, c });
	}

	st.update(1, 0);
	rep(r, 1, N + 1) {
		fore(p, Q[r]) {
			int l = p.first;
			int c = p.second;
			st.update(r, min(st[r], st.get(l, r) + c));
		}
	}
	ll ans = st[N];
	if (ans == infl) ans = -1;
	cout << ans << endl;
}






Measured memory_bytes: 7680
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int r =0;
		for( int i=0 ; i<n ; i++ ) {
			a[i] = sc.nextInt();
			r ^= a[i];
		}

		for( int i=0; i<n ; i++ ) {
			if(i!=0) System.out.print(" ");
			System.out.print( r ^ a[i] );
		}
	}

}


Measured memory_bytes: 60244
#include <stdio.h>
#include <string.h>

int main() {
  char S[20];
  char T[21];
  scanf("%s",S);
  scanf("%s",T);
  int sizeS = strlen(S);
  int sizeT = strlen(T);
  int count = 0;
  if(sizeS>=1 && sizeS<=10 && sizeT==sizeS+1) {
    for(int i=0;S[i]!='\0';i++) {
      if(S[i]==T[i]) {
	count++;
      }
    }
    if(count==sizeS && T[sizeT-1]>=97 && T[sizeT-1]<=122) {
      printf("Yes");
    }else {
      printf("No");
    }
  }
  return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
long long n,m,i,l,r,mid,ans,sum;
struct subject{
	long long l,r,x;
	long long t1,t2;
}a[111111];
bool cmp(subject x,subject y){
	return x.t1>y.t1;
}
bool check(long long lim){
	int i;
	long long rm=lim%m,num=lim/m,sum=0,res;
	rep(i,n){
		if(rm>a[i].x) a[i].t2=a[i].x*a[i].l+(rm-a[i].x)*a[i].r;
		else a[i].t2=rm*a[i].l;
		if(num==0&&a[i].t2>=::sum) return 1;
	}
	if(num==0) return 0;
	sort(a+1,a+n+1,cmp);
	rep(i,num){
		sum+=a[i].t1;
	}
	if(rm==0) return sum>=::sum;
	res=sum;
	rep(i,n){
		long long tmp=sum+a[i].t2;
		if(i<=num) tmp+=a[num+1].t1-a[i].t1;
		res=max(res,tmp);
	}
	return res>=::sum; 
}
int main(){
	cin>>n>>m;
	rep(i,n){
		cin>>a[i].x>>a[i].l>>a[i].r;
		a[i].t1=a[i].x*a[i].l+(m-a[i].x)*a[i].r;
		sum+=a[i].x*a[i].l;
	}
	l=-1;ans=m*n;r=ans-1;
	while(l<r){
		mid=(l+r+1)/2;
		if(check(mid)){
			r=mid-1;
			ans=mid;
		}
		else l=mid;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7556
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f;
LL n, m, s, t, h, w,sum,ans,cnt, a[220000], b[220000];
int main() {
	cin >> n;
	cin >> str; cnt = 1;
	rep(i, str.size()) {
		b[str[i] - 'a']++;
	}
	rep(i, 30) {
		if (b[i])cnt *= (1+b[i]);
		cnt %= MOD;
	}
	cout << cnt - 1 << endl;
	return 0;
}


Measured memory_bytes: 1020
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
        var c = a[n - 1];
        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (Math.Abs(c-a[i]*2) < Math.Abs(c-a[ans]*2))
            {
                ans = i;
            }
        }
        WriteLine($"{c} {a[ans]}");
    }
}

Measured memory_bytes: 23008
#include <stdio.h>
int abs(int x){
	if(x<0)
		return -1*x;
	else
		return x;
}
int main(int argc, char *argv[])
{
	int a[3];
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(int i=0;i<3;i++)
		for(int j=0;j<2-i;j++)
			if(a[j]>a[j+1]){
				int t;
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
	int sum=0;
	sum+=(abs(a[0]-a[1]));
	sum+=(abs(a[1]-a[2]));
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int x;bool bad=false;
  for(int i=0;i<n;i++)
  {
  	cin>>x;
  	if(!(x&1)){if((x%3!=0) and (x%5 != 0)){bad=true;break;}}
  }
  if(bad)cout<<"DENIED";
  else cout<<"APPROVED";
}

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

using namespace std;

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

    long long sum = 0;
    for(int i = 0;i <= N;i++){
        if(i %3 == 0) {

        }
        else if(i % 5 == 0) {

        }
        else{
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
	int card[4][13];
	for(int i=0; i<4; i++){
		for(int j=0; j<13 ;j++){
			card[i][j]=0;
		}
	}
	int n;
	cin >> n ;
	for(int h=0; h<n ;h++){
		int num ;
		char mar ;
		cin>> mar >> num ;
		if(mar == 'S'){
			card[0][num-1]=1;
		}
		if(mar == 'H'){
			card[1][num-1]=1;
		}
		if(mar == 'C'){
			card[2][num-1]=1;
		}
		if(mar == 'D'){
			card[3][num-1]=1;
		}
	}
	for (int i=0; i<4 ; i++){
		for (int j=0 ; j<13 ; j++){
			if(card[i][j] == 0){
				if(i == 0){
				    cout<< "S " <<j+1 <<endl;
				}else if(i == 1){
				    cout<< "H " <<j+1 <<endl;
				    
				}else if(i == 2){
				    cout<< "C " <<j+1 <<endl;
				}else if(i == 3){
				    cout<< "D " <<j+1 <<endl;
				}
			}
		}
	}
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

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

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	cout << (n - 1) / 2 << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

struct UF {
    vector<int> v;

    UF(int n) : v(n, -1) {}

    int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (-v[x] < -v[y]) swap(x, y);
        v[x] += v[y];
        v[y] = x;
        return;
    }

    bool root(int x) { return v[x] < 0; }

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

    int size(int x) { return -v[find(x)]; }
};

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

int main() {
    int H, W;
    cin >> H >> W;
    string S[401];
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }

    UF uf(H * W);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int k = 0; k < 4; ++k) {
                int nx = j + d[k], ny = i + d[k + 1];
                if (nx < 0 or nx >= W or ny < 0 or ny >= H)continue;
                if (S[i][j] == S[ny][nx])continue;
                uf.unite(i * W + j, ny * W + nx);
            }
        }
    }

    map<int, pair<ll, ll>> mp;
    for (int l = 0; l < H * W; ++l) {
        auto &p = mp[uf.find(l)];
        int a = l / W, b = l % W;
        if ((a + b) % 2 == 0)p.first++;
        else p.second++;
    }

    ll ans = 0;
    for (auto m : mp) {
        ans += m.second.first * m.second.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9728
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A,B,C,D = map(int,input().split())
lcm = lcm(C,D)
print((B - A + 1) - ((B // D - (A - 1) // D) + (B // C - (A - 1) // C) - (B // lcm - (A - 1) // lcm)))

Measured memory_bytes: 5560
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> foldl' (\acc p -> uwrite p n acc) elems path `seq` n
    n          -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF (UnionFind (_, sizes)) i = uread i sizes

uwriteElem :: Int -> Int -> UnionFind -> UnionFind
uwriteElem i a (UnionFind (elem, sizes)) = UnionFind (uwrite i a elem, sizes)

uwriteSize :: Int -> Int -> UnionFind -> UnionFind
uwriteSize i a (UnionFind (elem, sizes)) = UnionFind (elem, uwrite i a sizes)

unionUF :: UnionFind -> Int -> Int -> (UnionFind, Int)
unionUF uf i j =
  let pi = findUF uf i
      pj = findUF uf j
      si = sizeUF uf pi
      sj = sizeUF uf pj
  in  if pi == pj
        then (uf, 0)
        else
          let sij = si + sj
          in  ( if si < sj
                then uwriteSize pi 0 $ uwriteSize pj sij $ uwriteElem pi pj uf
                else uwriteSize pj 0 $ uwriteSize pi sij $ uwriteElem pj pi uf
              , si * sj
              )

comb2 k = k * (k - 1) `div` 2

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = ufreeze $ (\(_, _, acc) -> acc) $ VU.foldr'
  go
  (group, 0, accursedUnutterablePerformIO $ VUM.replicate m 0)
  abs
 where
  go (a, b) (uf, k, acc) =
    let (!uf', !d) = unionUF uf a b
        prev       = if k == 0 then 0 else uread (k - 1) acc
    in  (uf', k + 1, uwrite k (prev + d) acc)

  nC2 = comb2 n

  group :: UnionFind
  group = UnionFind
    (uthaw $ VU.enumFromN 0 n, accursedUnutterablePerformIO $ VUM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nm  <- VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    (nm VU.! 1)
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  let solutions = solve (nm VU.! 0) (nm VU.! 1) abs
  let nC2       = comb2 $ nm VU.! 0

  mapM_ (print . (nC2 -) . (solutions VU.!)) [nm VU.! 1 - 2, nm VU.! 1 - 3 .. 0]
  print nC2


Measured memory_bytes: 32508
n = int(input())
s = len(str(n))
count = 0

if(s % 2 == 1):
  count += (n - 10 ** (s - 1)) + 1

for i in range(1, s):
  if(i % 2 == 1):
    count += (10 ** (i - 1)) * 9
print(count)




Measured memory_bytes: 2940
N,M = map(int,input().split())
A = list(map(int,input().split()))
border = sum(A)/(4*M)
count = 0
for i in range(N):
  if A[i]>=border:
    count += 1
    
if count >= M:
  print('Yes')
  
else:
  print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  long long S;
  scanf("%lld", &S);
  long long x1, x2, x3, y1, y2, y3;
  x1=0;
  y1=0;
  x2=1e9;
  y2=1;
  if (S<(long long)1e9){
    y3=0;
    x3=S;
  } else if (S==(long long)1e18){
    y3=1e9;
    x3=0;
  } else {
    y3 = S/(long long)1e9 + 1;
    x3 = 1e9-S%(long long)1e9;
  }

  printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);
  //std::cout << abs(x2*y3-x3*y2) << std::endl;
  return 0;
}


Measured memory_bytes: 384
x, k, d = map(int, input().split())
f = (k - int(x/d))//2
f2 = (k - int(x/d) + 1) // 2
if f > k:
    f = k
elif f < 0:
    f = 0
if f2 > k:
    f2 = k
elif f2 < 0:
    f2 = 0
print(min(abs(x + (2*f - k)*d), abs(x + (2*f2 - k)*d)))


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define var auto
#define MOD 1000000007


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


int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
    int n; cin>>n;
    ll sum = 0;
    int arr[n];
    for(int i = 0; i<n; i++)cin>>arr[i], sum += arr[i];
    int m; cin>>m;
    while(m--){
        int i, s; cin>>i>>s;
        i--;
        cout<<sum - arr[i] + s<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Ord (comparing)
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV

bsearch f (a,b)
    | a+1 == b = a
    | f m  = bsearch f (m,b)
    | True = bsearch f (a,m)
    where m = (a + (b-a)`div`2)

go n as cs j = (na+1) * (n-1 - nc)
    where na = bsearch (\i -> as UV.! i < j) (-1, n)
          nc = bsearch (\i -> cs UV.! i <= j) (-1, n)

main = do
    n <- readLn :: IO Int
    as <- UV.fromList.sort.unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    bs <- sort.unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    cs <- UV.fromList.sort.unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    print $ sum $ map (go n as cs) bs


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	ll N=in<ll>();
	auto P = enum_div(N);

	ll minD = 1<<30;
	for(auto& x:P){
		ll A=x,B=N/x;
		ll NA=0,NB=0;
		while(A){
			NA++;
			A/=10LL;
		}
		while(B){
			NB++;
			B/=10LL;
		}
		minD = min(minD,max(NA,NB));
	}
	
	out(minD);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int x,y,c=0,cx=0,cy=0;
  cin>>s>>x>>y;
  bool f=true,ff=false;
  vector<int> xx,yy;
  for(int i=0;i<s.size();i++){
    if(f){
      if(s[i]=='F') c++;
      else f=false;
    }else{
      if(ff){
        if(s[i]=='F') cx++;
        else{
          xx.push_back(cx);
          cx=0;
          ff=false;
        }
      }else{
        if(s[i]=='F') cy++;
        else{
          yy.push_back(cy);
          cy=0;
          ff=true;
        }
      }
    }
  }
  x=abs(x-c);
  if(ff) xx.push_back(cx);
  else yy.push_back(cy);
  vector<vector<bool>> dx(4010,vector<bool>(8010,false)),dy(4010,vector<bool>(8010,false));
  dx[0][0]=dy[0][0]=true;
  for(int i=0;i<xx.size();i++){
    for(int j=0;j<=8000;j++){
      if(dx[i][j]) dx[i+1][j+xx[i]]=dx[i+1][abs(j-xx[i])]=true;
    }
  }
  for(int i=0;i<yy.size();i++){
    for(int j=0;j<=8000;j++){
      if(dy[i][j]) dy[i+1][j+yy[i]]=dy[i+1][abs(j-yy[i])]=true;
    }
  }
  if(dx[xx.size()][x]&&dy[yy.size()][abs(y)]) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 10624
from collections import Counter

n, k = list(map(int, input().split()))
a = Counter(map(int, input().split()))
a = list(a.items())
a.sort(key=lambda x: x[1])
opt = len(a) - k
ans = 0
if opt > 0:
    for i in range(opt):
        ans += a[i][1]
print(ans)


Measured memory_bytes: 45424
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int A = 0;
    int B = 0;
    // int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &A, &B);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    
    if(A == B){
      /* 真の場合の処理 */
      printf("Yes");
    }else{
      /* 偽の場合の処理 */
      printf("No");
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    // printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main()
{
ll ans,n,x;
ans=0;
cin >> n>>x;
ll pa[51]={};
ll ban[51]={};
ll sum[51]={};
sum[0]=1;
pa[0]=1;
for(ll i = 1; i <51; i++){
    pa[i]=1+pa[i-1]*2;
    ban[i]=2+ban[i-1]*2;
    sum[i]=pa[i]+ban[i];
}
//cout << pa[n] << endl;
for(ll i = n; i >=0; i--){
    if(i==0){ans+=1;break;}
    if(sum[i]/2+1<x){
        ans+=pa[i-1]+1;
        x-=sum[i-1]+2;
    }
    else if(sum[i]/2+1==x){
        ans+=pa[i-1]+1;
        break;
    }
    else if(sum[i]/2==x){
        ans+=pa[i-1];
        break;
    }
    else{
        x-=1;
    }
  // cout <<i<<" " <<x<<" "<<ans << endl;
    if(x==0)break;
    
    
}
cout << ans << endl;
return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0 && (n/i)-1 > i){
            ans += n/i - 1;
        } 
    }
    cout << ans << endl;
    return 0;
}

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

int abs(int x){
	return x>0?x:-1*x;
}

int min(int a, int b){
	return a<b?a:b;
}

int max(int a, int b){
	return a>b?a:b;
}

int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d%d",&n,&k);
	int a[n],dp[n];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	dp[0] = 0;
	for(int i=1;i<n;i++){
		dp[i] = 1000000000;
		for(int j=max(0,i-k);j<i;j++){
			dp[i] = min(dp[i],dp[j]+abs(a[j]-a[i]));
		}
	}
	printf("%d\n", dp[n-1]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
int n,m;
struct edge
{
	int to,next;
}e[200005],*p[200005];
int cnt;
int head[100005];
void ins(int u,int v)
{
	cnt++;
	e[cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
	p[cnt]=&e[cnt];
}
long long dp[100005][2];
void dfs(int u,int fa)
{
	dp[u][1]=1;
	dp[u][0]=1;
	for(int i=head[u];i;i=p[i]->next)
	{
		int v=p[i]->to;
		if(v==fa) continue;
		dfs(v,u);
		dp[u][0]=MOD(dp[u][0]*(dp[v][0]+dp[v][1]));
		dp[u][1]=MOD(dp[u][1]*dp[v][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		ins(u,v);
		ins(v,u);
	}
	dfs(1,0);
	printf("%lld",MOD(dp[1][1]+dp[1][0]));
	return 0;
}



Measured memory_bytes: 10880
#include <stdio.h>

int sol(int,int);

int A[2001],m[2001];

int n;

int main(){
  int i,j,q;

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

  for(i=0;i<q;i++){
    if(sol(0,m[i]))printf("yes\n");
    else printf("no\n");
  }
 
  return 0;
}

int sol(int x, int y){

  if(A[x] == y)return 1;

  if(x+1  == n)return 0;

  if(sol(x+1,y-A[x]) || sol(x+1,y))return 1;
  return 0;
 }

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    int l[100] = { 0 };

    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> l[i];
    }
    sort(l, l+n);

    int sum = 0;
    for (int i=0; i<n-1; i++) {
        sum += l[i];
    }

    if (sum > l[n-1]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007

using namespace std;

bool cmp(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.second > right.second;
}

int main() {
    int n;
    string s,t;
    cin >> n >>  s;
    if(n%2==0){
    rep0(i,n/2){
        t+=s[0];s.erase(s.begin());
    }
    if(t==s){
        cout << "Yes";
        return 0;

    }
    }
    cout <<"No"; 
    
   //if(getchar()=='\n'&& getchar()=='\n') return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define PI acos(-1)
#define BMW_GTR ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef long long ll;
using namespace std;

//ll const n = 50005;

int main()
{
    BMW_GTR;

    int K;
    cin >> K;
    
    for(int i = 0; i < K; i++)
    {
        cout << "ACL";
    }

    return 0;    

}


Measured memory_bytes: 3608
#include <iostream>
#include <string.h>
using namespace std;

char s[100010];
char s1[100010];

int main()
{
    cin>>s;
    int l = strlen(s);
    if(l&1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<l;i++) s1[i] = s[l-i-1]; 
    for(int i=0;i<l;i++)
    {
        if(s1[i] == 'b') s1[i] = 'd';
        else if(s1[i] == 'd') s1[i] = 'b';
        else if(s1[i] == 'p') s1[i] = 'q';
        else s1[i] = 'p';
    }
    if(!strcmp(s1, s)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 384
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

N = int(input())
A = [int(i) for i in input().split()]
ans = (A[0] * A[1]) // gcd(A[0], A[1])

for i in range(N):
    ans = (A[i] * ans) // gcd(A[i], ans)

re_ans = 0
ans -= 1

for i in A:
    re_ans += ans % i

print(re_ans)


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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	vector<vector<long long>> memo(1000001);
	vector<bool> sosu(1000001,true);
	sosu.at(0)=false;sosu.at(1)=false;
	for(long long i=2;i<=1000000;i++){
		if(sosu.at(i)==false) continue;

		for(long long j=i*2;j<=1000000;j+=i){
			sosu.at(j)=false;
		}
	}

	long long n;
	cin>>n;
	vector<long long> v(n);
	set<long long> soinsu;
	map<long long,long long> zisyo;

	string ans="pairwise coprime";

	for(long long i=0;i<n;i++) cin>>v.at(i);
	sort(v.begin(),v.end());

	for(auto a:v){//cout<<endl<<a<<"の素因数たち: ";
		long long now=a;
		if(sosu.at(now)){//cout<<now;
			soinsu.insert(now);
			zisyo[now]++;
			memo.at(now).push_back(now);
			continue;
		}

		for(long long i=2;i*i<=now;i++){
//			if(memo.at(now).size()!=0){
//				for(auto b:memo.at(now)){//cout<<b<<" ";
//					zisyo[b]++;
//					memo.at(a).push_back(b);
//				}
//				break;
//			}

			if(now%i==0){//cout<<i<<" ";
				soinsu.insert(i);
				zisyo[i]++;
				memo.at(a).push_back(i);

				while(now%i==0) now/=i;
			}
		}

		if(now!=1){//cout<<now<<" ";
			soinsu.insert(now);
			zisyo[now]++;
			memo.at(a).push_back(now);
		}
	}

	for(auto it=soinsu.begin();it!=soinsu.end();it++){
		if(zisyo.at(*it)>=2) ans="setwise coprime";
	}

	long long hoge=v.at(0);
	for(long long i=1;i<n;i++){
		long long a=hoge;
		long long b=v.at(i);

		while(a%b!=0){
			long long c=a%b;
			a=b;
			b=c;
		}

		hoge=b;
	}

	if(hoge!=1) ans="not coprime";

	cout<<ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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


Measured memory_bytes: 85776
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
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);
}
int main()
{
    int N, K;
    cin >> N >> K;
    vll A(N), S(N + 1);
    S[0] = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
        S[i + 1] = (S[i] + A[i]) % K;
    }
    ll ans = 0;
    map<ll, ll> cnt; // cnt[x] := x == S[i]-i となるiの数
    for (int i = 0; i < N + 1; i++)
    {
        if (i >= K)
        {
            cnt[((S[i - K] - (i - K) % K)+K)%K]--;
        }
        ans += cnt[((S[i] - i) % K+K)%K];
        cnt[((S[i] - i) % K+K)%K]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

void Yn(bool z){cout<<(z?"Yes":"No")<<endl;/*exit(0);/**/}
lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7; //99844353;
const int N = 1e5;
int n, z[N];
void f(int a, int b){
  cout << a+1 << " " <<  b+1 << endl;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  if(pcnt(n)==1){
    Yn(false);
    return 0;
  }
  Yn(true);
  if(n%4==0){
    V<int> v;
    FOR(i, 0, n-1) v.pb(i);
    FOR(i, 0, 20) if((1<<i)&n) z[(1<<i)-1] = 1;
    sort(all(v), [](auto const& l, auto const& r) { return z[l]>z[r];});
    FOR(i, 0, sz(v)-1) f(v[i], v[i+1]);
    f(v.back(), v[0]+n);
    FOR(i, 0, sz(v)-1) f(v[i]+n, v[i+1]+n);
    f(v[0], n-1);
    f(v[pcnt(n)-1], n*2-1);
    return 0;
  }
  int m = (n+1)/4*4-1;
  FOR(i, 0, m-1) f(i, i+1);
  f(m-1, n);
  FOR(i, 0, m-1) f(i+n, i+1+n);
  if(n%4==3) return 0;
  f(0, m);
  f(m, m+1);
  f(0, m+n+1);
  f(m+n+1, m+n);
  if(n%4==1) return 0;
  f(1, m+2);
  f(m+n+1, m+n+2);
}

Measured memory_bytes: 3320