akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<long long> inp;
vector<pair<long long, long long> >anss;
signed main(){
	long long n;
	cin >> n;
	for(int i=0;i<n;i++){
		long long a;
		cin >> a;
		inp.push_back(a);
	}
	sort(inp.begin(),inp.end());
	long long mdn=inp[0];
	long long mdx=inp[inp.size()-1];
	for(int i=1;i<inp.size()-1;i++){
		if(inp[i]>=0){
			anss.push_back({mdn,inp[i]});
			mdn-=inp[i];
		}
		else{
			anss.push_back({mdx,inp[i]});
			mdx-=inp[i];
		}
	}
	cout << mdx-mdn<<endl;
	for(auto x: anss){
		cout << x.first << " " << x.second<<endl;
	}
	cout << mdx << " " << mdn;
}

Measured memory_bytes: 4336
#include <cstdio>
#include <cstdlib>

#define FOR(i, a, b) for(i=a; i<b; ++i)

using namespace std;

#define MAXN 100000
#define MAXX 1000000000

int sulover(int *nums, int numsSize, int start) {
	int b = -1;
	int a = abs(nums[0] - start);
	int tmp = a;
	int i;

	if (numsSize == 0)
		return 0;

	FOR(i, 1, numsSize) {
		b = abs(nums[i]-nums[i-1]);

		if (b%tmp == 0) {
			continue;
		}
		while (a!=b) {
			if (a>b) a = a-b;
			else b = b-a;
		}

		tmp = a;

	}

	return tmp;
}

int main() {
	int i,n,x;
	int a[MAXN] = {0};

	scanf("%d %d", &n, &x);

	FOR(i, 0, n) {
		scanf("%d", &a[i]);
	}

	printf("%d\n", sulover(a, n, x));
	return 0;
}



Measured memory_bytes: 512
import sys
input=sys.stdin.readline
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
C.sort()
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
print(ans)


Measured memory_bytes: 92644
#include<bits/stdc++.h>
#define SIZE(array) (sizeof(array)/sizeof((array)[0]))
using namespace std;

int main() {
    int N, M;
    cin >> N>>M;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin>>A[i];
    }
    map<int, int> m;
    int rui[N + 1] = {0};
    long res = 0;
    for (int i = 0; i < N; i++) {
        rui[i + 1] = (rui[i] + A[i]) % M;
    }
    for (int i = 0; i < N + 1; i++) {
        res += m[rui[i]]++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3968
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a,b;
    String s;
    a = sc.nextInt();
    while(!(s = new String(sc.next())).equals("?")){
      b = sc.nextInt();
      if(s.equals("+"))System.out.println(a+b);
      if(s.equals("-"))System.out.println(a-b);
      if(s.equals("/"))System.out.println(a/b);
      if(s.equals("*"))System.out.println(a*b);
      a = sc.nextInt();
    }
    sc.close();
  }
}



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


int main()
{
    int n,d,count=0;
    cin>>n>>d;
    while(n--)
    { long x,y;
        cin>>x>>y;
      long a=x*x;
      long b=y*y;
       double c=sqrt(a+b);
         if(c<=d)
           count++;
    }
    cout<<count;

}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s,t;
    cin>>s>>t;
    int n = (int)t.size();
    if(s == t.substr(0,n-1) and s.size()+1 == t.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W+1) for i in range(N+1)]
for i in range(1, N+1):
    for s in range(1, W+1):
        if w[i-1] <= s:
            dp[i][s] = max(dp[i][s], dp[i-1][s-w[i-1]] + v[i-1])
        dp[i][s] = max(dp[i][s], dp[i-1][s])

print(dp[N][W])


Measured memory_bytes: 120684
package main

import "fmt"

func main() {
	for {
		var x string
		fmt.Scan(&x)
		if x == "0" {
			break
		}

		ans := 0
		for i := 0; i < len(x); i++ {
			ans += int(x[i]-'0') % 10
		}
		fmt.Println(ans)
	}
}



Measured memory_bytes: 1148
#include<iostream>
using namespace std;
int main()
{
    int m,n;
    scanf("%d",&m);
    n=m%1000;
    if(n==0)
    {
        printf("0\n");
    }
    else
    {
        printf("%d\n",1000-n);
    }
    return 0;
}


Measured memory_bytes: 3824
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,q;
int find(int u,int v){
	while(u!=v){
		while(u>v)
			u= u%n<=1 ? u/n : u/n+1;
		while(v>u)
			v= v%n<=1 ? v/n : v/n+1;
	}
	return u;
}
int main(){
	scanf("%d%d",&n,&q);
	for(register int i=1;i<=q;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		if(n==1)printf("%d\n",min(u,v));
		else printf("%d\n",find(u,v));
	}
	return 0;
}	

Measured memory_bytes: 1280
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque> 
#include <algorithm>
 
using namespace std;
 
#define     lli                 long long int
#define     ulli                unsigned long long int

#define     ifor(st,lim)        for(int i=st;i<lim;i++)
#define     jfor(stt,llim)      for(int j=stt;j<llim;j++)
#define		Test(tt)			for(int test=1;test<=tt;test++)
#define		For(var,srt,nnd)	for(var=srt;var<nnd;var++)
#define		Rfor(var,srt,nnd)	for(var=srt;var>=nnd;var--)
 
#define     pb                  push_back
#define     mkp                 make_pair
 
#define     pi                  acos(-1)
#define     mod                 100000007
 
#define     Clear(var,val)      memset(var,val,sizeof(var));
#define     len(var)            var.length()
#define     vlen(vect)          (int)vect.size()
#define     line(ss)            getline(cin,ss);

#define		FIO					ios_base::sync_with_stdio(false);cin.tie(NULL)

#define		sclock				int start_s=clock()
#define		eclock				int end_s=clock()
#define		pclock				printf("\nRuntime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC)
 
/****************************** IO ************************************/
#define		ina(a)				scanf("%d",&a)
#define		inb(a,b)			scanf("%d %d",&a,&b)
#define		inc(a,b,c)			scanf("%d %d %d",&a,&b,&c)
#define		ins(chr)			scanf("%s",s)
#define		inlla(a)			scanf("%lld",&a)
#define		inllb(a,b)			scanf("%lld %lld",&a,&b)
#define		inllc(a,b,c)		scanf("%lld %lld %lld",&a,&b,&c)
 
#define		outa(a)				printf("%d",a)
#define		outlla(a)			printf("%lld",a)

#define		yn(b)				puts(b ? "YES" : "NO") 

#define		outar(ar,ln,c)		for(int i=0;i<ln;i++){printf("%d%c",ar[i],c);}

#define		outCase()			printf("Case %d:",test)
 
#define		blank				printf("\n")
/**********************************************************************/

int main()
{
    FIO;
/******************************* A ************************************/
	
	int n;
	cin >> n;
	
	int ans;
	
	ans=n/500;
	
	n-=ans*500;
	
	ans*=1000;
	
	n/=5;
	ans+=n*5;
	
	cout << ans << endl;
 	
	
/**********************************************************************/
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  string s, t;
  cin >> s >> t;

  t.erase(t.size()-1);

  cout << (s == t ? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){
	
	int n,m;cin >> n >> m;
	vector<pair<ll,ll>> v;
	int cou = -1;
	REP(i,m){
		int tmp;cin >> tmp;
		if(tmp % 2 == 0)v.PB(MP(0,tmp));
		else {
			v.PB(MP(cou,tmp));
			cou += 2;
		}
	}
	
	if(cou > 3){
		cout << "Impossible" << endl;
		return 0;
	}
	
	sort(ALL(v));
	
	vector<int> ans;
	REP(i,m){
		if(i == 0){
			if(v[i].SE != 1)ans.PB(v[i].SE-1);
			if(m == 1)ans.PB(1);
		}
		else if(i == m-1){
			ans.PB(v[i].SE+1);
		}
		else{
			ans.PB(v[i].SE);
		}
	}
	
	REP(i,m){
		cout << v[i].SE;
		if(i != m-1)cout << ' ';
		else cout << endl;
	}
	
	cout << ans.size() << endl;
	REP(i,ans.size()){
		cout << ans[i];
		if(i != ans.size() - 1)cout << ' ';
		else cout << endl;
	}
	
	
	
	return 0;
}


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

using namespace std;

const int NMax = 150;

int A[NMax][NMax];
int used[NMax];
int N, M;

int bkt (int x, int y)
{
    if (x >= N)
	{
        if (y < 2)
			return 0;
		int ans = 0;
		for (int i = 0; i < y; ++i)
		{
            int Min = INT_MAX;

            for (int j = 0; j < y; ++j)
				if (i != j)
					Min = min(Min, A[used[i]][used[j]]);

			ans = ans + Min;
		}

		return ans;
	}

	int ans = bkt(x + 1, y);
	int Ok = 0;

	for (int i = 0; i < y; ++i)
		if (!A[used[i]][x])
			Ok = 1;

	if (!Ok)
	{
        used[y] = x;
        ans = max(ans, bkt(x+1, y+1));
	}

	return ans;
}

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

	for (int i = 0; i < M; ++i)
	{
        int u, v, f;

        cin >> u >> v >> f;
		A[u-1][v-1] = A[v-1][u-1] = f;

	}

	int ans = bkt(0,0);
	cout <<ans <<'\n';
    return 0;
}



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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //write your code here
    int n;
		cin>>n;
		vector<double> v(n,0.0);
		rep(i,0,n)	cin>>v[i];
		vector<vector<double> > dp(n+1, vector<double> (n+1, 0 ));
		dp[0][0]=1;
		rep(i,1,n+1){
			rep(j, 0 , n+1){
				dp[i][j]= (1-v[i-1])*dp[i-1][j];
				if(j>0)
					dp[i][j]+= v[i-1]*dp[i-1][j-1];
			}
		}
		double ans =0;
		rep(i,(n+1)/2, n+1)
				ans+=dp[n][i];
		cout<<fixed<< setprecision(10)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 70784
#include <iostream>

int main(void)
{
    int N = 0;
    std::cin >> N;

    int min = 0xfffffff;
    int buf = 0;
    for(int i=0; i<N; i++){
        std::cin >> buf;
        int exp = 0;
        while(buf!=0){
            if(buf&1){
                break;
            }else{
                exp++;
                buf >>= 1;
            }   
        }   
        if(exp < min)min = exp;
    }   

    std::cout << min << std::endl;

    return 0;
}

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

typedef long long ll;
using namespace std;

int main (){
    int n,m;
    cin >> n >> m;
    int tp;
    int p[m];
    string tjud;
    bool jud[m];
    for (int i = 0; i < m; i++){
        cin >> tp >> tjud;
        p[i]=tp-1;
        if(tjud=="AC") jud[i]=true;
        else           jud[i]=false;
    }
    int wa[n]={};
    bool status[n]={};
    int count=0;
    int penalty=0;
    for (int i = 0; i < m; i++){
        if(jud[i]){
            if(!status[p[i]]){
                count++;
                status[p[i]]=true;
                penalty+=wa[p[i]];
            }
        }
        else{
            if(!status[p[i]]){
                wa[p[i]]++;
            }
        }
    }
    cout << count << " " << penalty << "\n";
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

ll a[N] ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll m1 , d1 , m2 , d2 ;
    cin >> m1 >> d1 >> m2 >> d2 ;
    if (d1 - d2 > 1) cout << 1 ;
    else cout << 0 ;
	    
    return (0) ;
}

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

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

    int min = 1;
    int count = 0;

    count = (N-1)/(K-1);
    if ((N-1)%(K-1)!=0) {
        count += 1;
    }

    cout << count;
    return 0;
}

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

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

    bool flag = false;
    for(int C = 1; C <= 3; C++)
        if(A*B*C % 2 != 0) flag = true;

    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
// #include <iostream>
// #include <string>
// #include <math.h>
// #include <map>
// #include <vector>
// #include <tuple>
// #include <algorithm>
// #include <queue>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;
int main(){
  int N;
  cin >> N;
  lli a[N];
  lli b[N];
  lli c[N-1];
  F(i, N){
    cin >> a[i];
  }
  F(i, N){
    cin >> b[i];
  }
  F(i, N-1){
    cin >> c[i];
  }
  lli sum = 0;
  F(i, N){
    lli tmp = a[i]-1;
    sum += b[tmp];
    if (i != 0 && a[i] == a[i-1] + 1){
      sum += c[a[i-1]-1];
    }
  }
  cout << sum << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const ll INF = 1e15;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), S(n + 1);
  REP(i, n) {
    cin >> a[i];
    --a[i];
  }

  S[0] = 0;
  REP(i, n) { S[i + 1] = (S[i] + a[i]) % k; }

  map<ll, ll> mp;
  ll ans = 0;
  queue<ll> que;
  REP(i, n + 1) {
    ans += mp[S[i]];
    ++mp[S[i]];
    que.push(S[i]);
    if (que.size() == k) {
      --mp[que.front()];
      que.pop();
    }
  }

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

Measured memory_bytes: 17536
#include<iostream>

using namespace std;

int main(){
	
	int kingaku[] = {6000,4000,3000,2000};

	for (int i = 0; i < 4; i++){
	int t,n;
	cin >> t >> n;
	cout << kingaku[t-1] * n << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

n=int(input())
a=list(map(int,input().split()))
a.append(a[-1])

ans=[]

gcd_left=[0]*n
gcd_right=[0]*n
for i in range(1,n):
    gcd_left[i]=gcd(gcd_left[i-1],a[i-1])
    gcd_right[n-i-1]=gcd(gcd_right[n-i],a[n-i])

ans=[]
for i in range(n):
    ans.append(gcd(gcd_left[i],gcd_right[i]))

print(max(ans))


Measured memory_bytes: 14524
#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;
  }
  
  if ((A+B)==(C+D)) {
    cout<<"Balanced"<<endl;
  }
  
  if ((A+B)<(C+D)) {
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

MOD = 10**9 + 7
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

MAX = n + 5
fact = [1] * (MAX + 1)  # i!
finv = [1] * (MAX + 1)  # (i!)^{-1}
iinv = [1] * (MAX + 1)  # i^{-1}
for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD

ele_id = (1, 0)
# dp[v][i] = (頂点vから出るi番目の有向辺に関する部分木のDPの値)
# dp[v][i] = (c, m)
# c = 頂点vから出るi番目の有向辺に関する部分木の塗り方の数
# m = 頂点vから出るi番目の有向辺に関する部分木の頂点数
dp = [[ele_id] * len(graph[i]) for i in range(n)]
ans = [ele_id] * n

add_func = lambda x: (x[0], x[1] + 1)


def merge_func(a, b):
    m = a[1] + b[1]
    dp_a = a[0] * finv[a[1]] % MOD
    dp_b = b[0] * finv[b[1]] % MOD
    c = (dp_a * dp_b % MOD) * fact[m] % MOD
    return (c, m)


def dfs1(v, v_p):
    dp_cum = ele_id
    for i, v_next in enumerate(graph[v]):
        if v_next == v_p:
            continue
        dp[v][i] = dfs1(v_next, v)
        dp_cum = merge_func(dp_cum, dp[v][i])
    return add_func(dp_cum)


def dfs2(v, v_p, dp_vp):
    for i, v_next in enumerate(graph[v]):
        if v_next == v_p:
            dp[v][i] = dp_vp

    dp_l = [ele_id] * (len(graph[v]) + 1)
    dp_r = [ele_id] * (len(graph[v]) + 1)
    for i in range(len(graph[v])):
        dp_l[i + 1] = merge_func(dp_l[i], dp[v][i])
    for i in reversed(range(len(graph[v]))):
        dp_r[i] = merge_func(dp_r[i + 1], dp[v][i])

    ans[v] = add_func(dp_l[-1])

    for i, v_next in enumerate(graph[v]):
        if v_next == v_p:
            continue
        dfs2(v_next, v, add_func(merge_func(dp_l[i], dp_r[i + 1])))


dfs1(0, -1)
dfs2(0, -1, ele_id)
for ans_i, _ in ans:
    print(ans_i)


Measured memory_bytes: 148316
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	std::vector<int> cnt(3);
	get(cnt[0], cnt[1], cnt[2]);

	std::sort(cnt.begin(), cnt.end());

	if (cnt[0] == 5 && cnt[1] == 5 && cnt[2] == 7) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
}


Measured memory_bytes: 3564
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
dyx=[(1,0),(-1,0),(0,1),(0,-1)]
from collections import deque
q=deque()
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue
        q.append((i,j))
        d=[[0]*w for _ in range(h)]
        while q:
            y,x=q.popleft()
            for dy,dx in dyx:
                ny,nx=y+dy,x+dx
                if ny==i and nx==j:
                    continue
                if 0<=ny<h and 0<=nx<w and d[ny][nx]==0 and s[ny][nx]==".":
                    d[ny][nx]=d[y][x]+1
                    q.append((ny,nx))
        for k in range(h):
            ans=max(ans,max(d[k]))
print(ans)


Measured memory_bytes: 48476
#include<iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  string moji,a;
  int K=0,U=0,P=0,C=0,A;
  cin>>moji;
  for(int i=0;i<moji.size();i++){
    a=moji.substr(i,1);
    if(a=="K")K++;
    if(a=="U")U++;
    if(a=="P")P++;
    if(a=="C")C++;
  }
  A=min(K,min(U,min(P,C)));
  cout<<A<<endl;
  return 0;
}

Measured memory_bytes: 1196
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N =sc.nextLong();
		
		double tmp = Math.sqrt(N);
		long tmp2 = (long)tmp;//少数切り捨て
		long tmp3=0;
		boolean flg =true;
		while(flg) {
			if(N%tmp2==0) {
				tmp3 = N/tmp2;
				flg=false;
			}else {
				tmp2--;
			}
		}
		long ans = (tmp2-1)+(tmp3-1);
		System.out.println(ans);

	}
}


Measured memory_bytes: 22612
from scipy.optimize import fmin
INF = 10**18
n = int(input())
# 0:static, 1:up, 2:down
xpoints = [[] for _ in range(3)]
ypoints = [[] for _ in range(3)]
for i in range(n):
    x, y, d = [item for item in input().split()]
    x = int(x); y = int(y)
    if d == "R":
        ypoints[0].append(y)
        xpoints[1].append(x)
    elif d == "L":
        ypoints[0].append(y)
        xpoints[2].append(x)
    elif d == "U":
        xpoints[0].append(x)
        ypoints[1].append(y)
    elif d == "D":
        xpoints[0].append(x)
        ypoints[2].append(y)
for i in range(3):
    xpoints[i].sort()
    ypoints[i].sort()

def f(t):
    if t < 0:
        return INF 
    max_x = max_y = -INF
    min_x = min_y = INF
    for i, a in enumerate([0, t, -t]):
        if not len(xpoints[i]) == 0:
            max_x = max(max_x, xpoints[i][-1] + a)
            min_x = min(min_x, xpoints[i][0] + a)
        if not len(ypoints[i]) == 0:
            max_y = max(max_y, ypoints[i][-1] + a)
            min_y = min(min_y, ypoints[i][0] + a)
    return (max_x - min_x) * (max_y - min_y)

ans = fmin(f, x0=10**8, ftol= 1e-9, disp=False)
print(f(ans[0]))

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

int main(){
   int t;
   long long a,b,pro;
   long long sq,res=0;
   cin>>t;
   while (t--) {
      cin>>a>>b;
      pro=a*b;
      sq=sqrt(pro);
      res=sq*2;
       if(sq*sq==pro)
       {
          res=res-2;

       }
       else if((pro-1)/sq==sq)
       {
           res--;
       }

       if(!(a==b&&b==sq))
       {
           res--;
       }


       cout<<res<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

int minI(int a, int b) { if (a < b) { return a; }return b; }
int maxI(int a, int b) { if (a > b) { return a; }return b; }

int main() {
	char S[100010];
	int len, ans;
	scanf("%s", S);
	len = strlen(S);
	
	ans = len;
	for (int i = 1; i < len; i++) {
		if (S[i] != S[i - 1]) {
			ans = minI(ans, maxI(i, len - i));
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, k;
int dis[2005][2005];
vector<int> G[2005];
bool vis[2005];
int over[2005];
void dfs(int root, int now, int prev, int d)
{
	dis[root][now] = d;
	for (int i = 0; i < G[now].size(); i++)
	{
		int v = G[now][i];
		if (prev == v) continue;
		dfs(root, v, now, d + 1);
	}
}
signed main()
{
	cin >> n >> k;
	for (int i = 0; i < n-1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 0; i < n; i++)
		dfs(i, i, -1, 0);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (dis[i][j] > k)
				over[i]++;
	int ret = 0;
	while(1)
	{
		int maxn = -1,maxnum = 0;
		for (int i = 0; i < n; i++)
		{
			if (vis[i]) continue;
			if (G[i].size() >= 2) continue;
			if (over[i] > maxnum)
			{
				maxnum = over[i];
				maxn = i;
			}
		}
		if (maxn == -1) break;
		ret++;
		for (int i = 0; i < n; i++)
		{
			if (dis[i][maxn] > k)
				over[i]--;
			if (dis[i][maxn] == 1)
				G[i].pop_back();
		}
		vis[maxn] = true;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 31872
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n, p;
	while(1){
		cin >> n >> p;
		if(n == 0 && p == 0) break;
		int i, count = 0;
		int a[n], P;
		for(i = 0;i < n;i++){
			a[i] = 0;
		}
		P = p;
		while(1){
			if(count == n){
				count = 0;
			}
			//cout << "count = " << count << endl;
			if(P > 0){
				a[count]++;
				P--;
				if(a[count] == p){
					break;
				}
				count++;
			}
			else if(P == 0 && a[count-1] != p){
				P = a[count];
				a[count] = 0;
				count++;
			}

			//printf("a[%d] = %d, count = %d, P = %d\n",count-1,a[count-1],count,P);
		}
		/*if(count == 0){
			count = n-1;
		}
		else if(count != 0){
			count = count - 1;
		}*/
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
ll n,i,c=0;
cin>>n;
ll a[n];
for(int j=0;j<n;j++)
cin>>a[j];
for(i=0;i<n-1;i++)
{
	while(a[i]>a[i+1])
	{
		a[i+1]++;
		c++;
	}
}
cout<<c<<endl;
}

Measured memory_bytes: 5144
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int at(ll h){
    if(h <= 1){
        return 1;
    }

    return at(h / 2) + at(h / 2) + 1;
}

int main()
{
    ll H;
    int c = 0;
    cin >> H;

    while(H >= 2){
        H /= 2;
        c++;
    }

    bitset<64> b;
    rep(i, c + 1){
        b.set(i);
    }

    cout << b.to_ullong() << endl;
}

Measured memory_bytes: 256
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define ff first
#define ss second
#define mkp make_pair    
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char> 
#define vll vector< pair<ll,ll> > 
#define pr pair<ll,ll>
#define mps map<string ,ll>
#define mpc map<char ,char>
#define mpl map<ll,ll>
#define tpl tuple<ll,ll,ll>
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
//	   cin>>t;
	      while(t--)
{



/*
01B0/**/
ll n,m,i;
string s;
cin>>s;
n=s.length();
vector <char> v;
ll d=0;
for(i=n-1;i>=0;i--)
{
	if(s[i]=='B')
	{
	d++;	
	continue;
	}
	if(d==0)
	{
		v.pb(s[i]);
	}
	else
	{   d--;
		continue;
	}	
}
fo(i,v.size())
cout<<v[v.size()-1-i];
ee;


}
return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::pair;
using std::set;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q;
ull a, b, c, x, y;
ull K, L, N, M;

int main()
{
	set<char> Set;
	char c;
	for (c = 'a'; c <= 'z'; ++c)Set.insert(c);
	while (cin >> c)
	{
		Set.erase(c);
		if (Set.empty())break;
	}
	if (Set.empty())cout << "None\n";
	else cout << *(Set.begin()) << '\n';
	return 0;
}


Measured memory_bytes: 256
import sys

def i2s():
    return sys.stdin.readline().rstrip()

def ii2ss(n):
    return [sys.stdin.readline() for _ in range(n)]

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def analyze(S):
    data = []
    i0 = 0
    s0 = S[0]
    sc = 0
    for i, s in enumerate(S):
        if s == s0:
            sc += 1
        else:
            data.append((i0, s0, sc))
            i0 = i
            s0 = s
            sc = 1
    data.append((i0, s0, sc))
    return data

def main(ss):
    N, K = sp2nn(ss[0])
    S = ss[1]
    data = analyze(S)
    cmax = 0
    
    for dl in range(len(data)):
        c = 0
        dw = K * 2
        if data[dl][1] == '1':
            dw += 1
        if dl + dw < len(data):
            c = data[dl+dw][0] - data[dl][0]
        else:
            c = N - data[dl][0]
        if cmax < c:
            cmax = c
    
    print(cmax)
main(ii2ss(2))

Measured memory_bytes: 14460
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    String s=sc.next();

    for (int i=0;i<s.length();i++) {
      int start=(int)s.charAt(i);
      int ans=start+n;
      if (ans<91) {
        System.out.print((char)ans);
      }else{
        System.out.print((char)(ans-26));
      }
    }

    System.out.println();

  }
}


Measured memory_bytes: 26196
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(s[k-1])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

static const int N = 100;
int n, m[N][N];
int tm, begT[N], endT[N];
bool visited[N];

int nxt(int u)
{
	for (int v = 0; v < n; ++v)
	{
		if (m[u][v] > 0 && !visited[v]) return v;
	}
	return -1;
}

void dfs_helper(int idx)
{
	stack<int> s;
	s.push(idx);
	begT[idx] = tm++;
	visited[idx] = true;

	while (!s.empty())
	{
		int u = s.top();
		int v = nxt(u);
		if (-1 == v)
		{
			s.pop();
			endT[u] = tm++;
			continue;
		}
		s.push(v);
		begT[v] = tm++;
		visited[v] = true;
	}
}

void dfs()
{
	tm = 1;

	for (int i = 0; i < n; ++i)
	{
		if (!visited[i]) dfs_helper(i);
	}

	for (int i = 0; i < n; ++i)
	{
		cout << i + 1 << " " << begT[i] << " " << endT[i] << endl;
	}
}

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

	for (int i = 0; i < n; ++i)
		visited[i] = false;

	for (int i = 0; i < n; ++i) {
		int u, d;
		cin >> u >> d;
		for (int j = 0; j < d; ++j)	{
			int v; cin >> v;
			m[u - 1][v - 1] = 1;
		}
	}

	dfs();

	return 0;
}

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

bool primeFlg[1000000];

void makePrime(){
  memset(primeFlg, true, sizeof(primeFlg));
  primeFlg[0] = primeFlg[1] = false;

  for(int i = 2; i * i <= 1000000; i++){
    if(primeFlg[i]){
      for(int j = i + i; j < 1000000; j += i){
        primeFlg[j] = false;
      }
    }
  }
}

int main(){
  int n;

  makePrime();

  while(cin >> n){
    int primeCount = 0;

    for(int i = 0; i <= n; i++){
      primeCount += primeFlg[i];
    }

    cout << primeCount << endl;
  }
}

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

int main() {
    int ans = 700;
    string S;
    cin >> S;
    for (int i = 0; i < 3; i++){
        if (S[i] == 'o'){
            ans += 100;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n,ans=0,lowest=2*100000+1;
    cin >> n;
    vint p(n);
    REP(i,n){
        cin >> p[i];
        if(lowest > p[i]){
            ans++;
            lowest = p[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n,ans=0;
	cin>>n;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	a.pb( (1<<20) - 1);
	ll lef = 0, rig = 0, cur = a[0];
	while(lef<n){
		if(rig<n-1 && (cur ^ a[rig+1]) == cur+a[rig+1]){
			rig++;
			cur = cur^a[rig];
		}
		else{
			ans += rig-lef+1;
			cur = cur^a[lef];
			lef++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main()
{
  string s;
  cin >> s;
  
  reverse(s.begin(), s.end());
  for (int i = 0; i < 4; i++)
  {
    reverse(divide[i].begin(), divide[i].end());
  }
  
  bool can = true;
  for (int i = 0; i < s.size();)
  {
    bool can2 = false;
    for (int j = 0; j < 4; j++)
    {
      string d = divide[j];
      if (s.substr(i, d.size()) == d)
      {
        can2 = true;
        i += d.size();
      }
    }
    if (!can2)
    {
      can = false;
      break;
    }
  }
  
  if (can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, M;
        cin >> N >> M;
        vector<int> cnt(N);

        rep(i, 0, M) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            cnt[a]++;
            cnt[b]++;
        }

        for (int i = 0; i < N; ++i) {
            if (cnt[i] % 2) {
                cout << "NO" << endl;
                return;
            }
        }
        cout << "YES" << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,x;
	cin>>k>>x;
	int i=x-k+1;
	int j=x+k-1;
	for(i;i<=j;i++)
	{
		if(i==x-k+1)
		cout<<i;
		else cout<<" "<<i;
	}
	cout<<endl;
	return 0;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	ll n, c, k;
	cin >> n >> c >> k;
	vector<ll> t(n);
	rep(i, n) cin >> t[i];
	
	sort(t.begin(), t.end());
	ll ans = 1;
	ll th = t[0] + k;
	ll tmpc = c - 1;
	for(int i = 1; i < n; ++i){
		if(0 < tmpc){
			if(t[i] <= th){
				tmpc--;
			}
			else{
				tmpc = c - 1;
				th = t[i] + k;
				ans++;
			}
		}
		else{
			tmpc = c - 1;
			th = t[i] + k;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(D <= A || B <= C) cout << 0 << endl;
    else cout << min(B, D) - max(A, C) << endl;
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    REP(i, 1005) {
        ll a = i * 0.08;
        ll b = i * 0.1;
        if (A == a && B == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 10;

int n, m, k;

int a[N][N], b[N][N];

void init() {
	for (int i = 0; i < N; i ++) {
		for (int j = 0; j < N; j ++) {
			b[i][j] = a[i][j];
		}
	}
}

int main() {

	FAST;

	cin >> n >> m >> k;
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < m; j ++) {
			char x;
			cin >> x;
			a[i][j] = (x == '.' ? 0 : 1);
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << (n + m)); i ++) {
		init();
		for (int j = 0; j < (n + m); j ++) {
			if (i & (1 << j)) {
				if (j < n) {
					for (int k = 0; k < m; k ++) {
						b[j][k] = 0;
					}
				}
				else {
					for (int k = 0; k < n; k ++) {
						b[k][j - n] = 0;
					}
				}
			}
		}
		int cnt = 0;
		for (int x = 0; x < n; x ++) {
			for (int y = 0; y < m; y ++) {
				cnt += b[x][y];
			}
		}
		if (cnt == k) ans ++;
	}
	cout << ans << '\n';
	return 0;
}

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int count = 0;
    for (int i = 0; i < N - 2; i++)
    {
        if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
            count++;
        }
    }
    cout << count << endl;
    

    return 0;
}

Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let it = s.trim().split_whitespace();
    let mut a: Vec<usize> = it.map(|s| s.parse().unwrap()).collect();
    for i in 0..2 {
        let v = std::cmp::min(a[i], a[2]);
        a[i] -= v;
        a[2] -= v;
    }
    println!("{} {}", a[0], a[1]);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int ans = (int)Math.log10(n)+1;
		for(int i=1; i<=Math.sqrt(n); i++) {
			if(n%i ==0) ans = (int)Math.min(ans, Math.log10(n/i)+1);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define ll long long
const int INF=1e9+7;

int main(){
#ifndef ONLINE_JUDGE
	freopen("C:\\Users\\User\\Documents\\input.txt","r",stdin);
#endif
	int T,i,j;
	
	int n,k;
	cin>>n>>k;
	vector<int> a(n+1),dp(n+1,INF);
	for(i=1;i<=n;++i){
	    scanf("%d",&a[i]);
	}
	dp[1]=0;

	for(i=1;i<n;++i){
	    for(j=i+1;j<=min(n,i+k);++j){
	        dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
	    }
	}
	printf("%d\n",dp[n]);

		
	return 0;
}

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

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

    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 0) {
        for (int i = 0; i < n / 2; i++) {
            if (s[i] != s[i + n / 2]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int>v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  
  vector<int>A(100000,0);
  for (int i = 0; i < n; i=i+2) {
    A.at(v.at(i)-1)++;
  }
  vector<int>a(100000,0);
   for (int i = 0; i < 100000; i++) {
    a.at(i) = A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  int F = -1;
  int S = -1;
  for (int i = 0; i < 100000; i++) {
    if (A.at(0) == a.at(i)){
      F = i+1;
    }
    else if (A.at(1) == a.at(i)){
      S = i+1;
    }
  }
    
  vector<int>B(100000,0);
  for (int i = 1; i < n; i=i+2) {
    B.at(v.at(i)-1)++;
  }
  vector<int>b(100000,0);
  for (int i = 0; i < 100000; i++) {
    b.at(i) = B.at(i);
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  
  int f = -1;
  int s = -1;
  for (int i = 0; i < 100000; i++) {
    if (B.at(0) == b.at(i)){
      f = i+1;
    }
    else if (B.at(1) == b.at(i)){
      s = i+1;
    }
  }

  if (F == f){
    if (A.at(0)-A.at(1) > B.at(0)-B.at(1)){
      cout << n - A.at(0) - B.at(1) << endl;
    }
    else {
      cout << n - A.at(1) - B.at(0) << endl;
    }
  }
  else {
    cout << n - A.at(0) - B.at(0) << endl;
  }
}
    

Measured memory_bytes: 5056
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
bool vis[200000+20];
mp robot[200000+20];
LL dp[200000+20],tree[8*200000+20];
int treen,reach[200000+20];
void change(int now,int val){
	now+=treen-1;
	tree[now]=val;
	now>>=1;
	while(now){
		tree[now]=max(tree[now<<1],tree[(now<<1)+1]);
		now>>=1;
	}
}
int query(int a,int b,int l=1,int r=treen+1,int now=1){
	if(r<=a||l>=b){
		return -INF;
	}
	if(r<=b&&l>=a){
		return tree[now];
	}
	int mid=(l+r)>>1;
	return max(query(a,b,mid,r,(now<<1)+1),query(a,b,l,mid,now<<1));
}
const int MOD=998244353;
LL dfs(int now){
	if(now>n) return 1ll;
	if(vis[now]) return dp[now];
	vis[now]=1;
	dp[now]=dfs(now+1);
	dp[now]+=dfs(reach[now]+1);
	dp[now]%=MOD;
	return dp[now];
}
int main(){
	fastio;
	memset(tree,-0x3f,sizeof(tree));
	cin>>n;
	treen=1<<(int)(ceil(log2(double(n))));
	rb(i,1,n)
		vis[i]=0;
	rb(i,1,n)
		cin>>robot[i].FIR>>robot[i].SEC;
	sort(robot+1,robot+1+n);
	rl(i,n,1){
		reach[i]=i;
		int l=i,r=n+1;
		while(l<r-1){
			int mid=(l+r)>>1;
			if(robot[mid].FIR-robot[i].FIR<robot[i].SEC){
				l=mid;
			}
			else{
				r=mid;
			}
		}
		if(l!=i)
		reach[i]=max(i,query(i,l+1));
		change(i,reach[i]);
	}
	cout<<dfs(1)<<endl;
	return 0;
}


Measured memory_bytes: 19968
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String n = sc.next();
			int max = 0;
			int tmp = 0;
			for (int i = 0; i < 3; i++) {
				if (n.charAt(i) == 'R') {
					tmp++;
				}
				max = Math.max(max, tmp);
				if (n.charAt(i) == 'S') {
					tmp = 0;
				}
			}
			System.out.print(max);
		}
	}
}

Measured memory_bytes: 35776
import sys
sys.setrecursionlimit(1<<30)

N = int(input())
def dfs(x):
    for y in Tree[x]:
        if Parent[x] != y:
            Parent[y] = x
            distance[y] += Web[min(x,y),max(x,y)]+distance[x]
            dfs(y)
Tree = [[] for i in range(N+1)]
Parent = [0]*(N+1)
Web = dict()
for i in range(N-1):
    a,b,w = map(int,input().split())
    Tree[a].append(b)
    Tree[b].append(a)
    Web[(min(a,b),max(a,b))] = w
distance = [0]*(N+1)
dfs(1)
for i in distance[1:]:
    if i%2 == 0:
        print(1)
    else:
        print(0)

Measured memory_bytes: 87360
import sys
input = sys.stdin.readline

n = int(input())
A = [int(x) for x in input().split()]
cnt = 0

def Merge(S, l, m, r):
    global cnt
    L = S[l:m] + [float('inf')]
    R = S[m:r] + [float('inf')]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            cnt += len(L) - 1 - i
            j += 1
    return

def MergeSort(S, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
    return

MergeSort(A, 0, n)
print(cnt)


Measured memory_bytes: 27592
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main()
{
	long long int n,i,a[100000],j=1,max=1,count=0,k;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n-1);
	int b[100000];
	for (i=0;i<n;i++)
	{
		b[a[i]]++;
	}
	for (i=1;i<n-1;i++)
	{
		if (b[i-1]+b[i]+b[i+1]>max)
		{
			max=b[i-1]+b[i]+b[i+1];
		}
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m,q;
  cin>>n>>m>>q;
  vector<int> v,w;
  int ans[n+1][n+1];
  for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) ans[i][j]=0;

  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    ans[l][r]++;
  }

  for(int i=0;i<=n;i++){
    for(int j=1;j<=n;j++){
      ans[i][j]+=ans[i][j-1];
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<=n;j++){
      ans[i][j]+=ans[i-1][j];
    }
  }
  for(int i=0;i<q;i++){
    int s,t;
    cin>>s>>t;
    cout<<ans[t][t]-ans[s-1][t]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
using namespace std;
int main(void)
{
  int a,b;
  int i=0;
  cin >> a >> b;
  int sum = 1;
  
  while(1)
  {

      if(sum >= b)
        break;
    i++;
    sum--;
    sum+=a;
    
  }
  
  cout << i;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int main()
{
  priority_queue<int> Q;
  priority_queue<int,vector<int>, greater<int> > P;
  int saidai,saisyo;
  int n;
  cin >>n;
  for(int i = 0;i < n;i++){
    saidai = 0;
    saisyo = 0;
    string a;
    cin >>a;
    for(int i = 0;i <a.size();i++){
      int b = a[i]-'0';
      Q.push(b);
      P.push(b);
    }
    for(int i = 1;i <=8;i++){
      saidai +=Q.top()*(pow(10.0,8-i));
      saisyo +=P.top()*(pow(10.0,8-i));
      Q.pop();
      P.pop();
  }
    cout <<saidai-saisyo<<endl;
  }
  return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	int a[n],b[n],j=n-1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[j]=a[i];
		j--;
	}
	int i=0;
	j=0;
	int max=INT_MIN,count=0;
	for(int i=0;i<n;i++){
		if(b[i+1]>=b[i])count++;
		else{
			if(count>=max)max=count;
			count=0;
		}
	}
	cout<<max;
	return 0;
	
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string S;
  cin >> S;
  bool ans = false;
  rep(i, 3) {
    if (S[i] == S[i + 1]) ans = true;
  }
  if (ans == false)
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
  return 0;
}


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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    while(true){
        int a,b,n=0,i,j,k;
        cin >> a >> b;
        if(a==0&&b==0){
            break;
        }
        for (i=1;i <= a; i++){
            for (j=i+1; j <= a;j++){
                for (k=j+1; k <= a; k++){
                    if(i+j+k==b)n++;
                }
            }
        }
        cout<<n<<'\n';
    }
}


Measured memory_bytes: 3208