akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
using namespace std;
 
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
 
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> PP;
 
struct edge {
	int to, cost;
	edge(int t, int c) :to(t), cost(c) {}
};
 
int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
int ddx[] = { 1,1,1,0,-1,-1,-1,0 }, ddy[] = { 1,0,-1,-1,-1,0,1,1 };
 
ll mypow(ll x, ll n, ll m) {	//xのn乗をmで割った余り
	if (n == 0) return 1;
	if (n % 2 == 0) return mypow(x*x%m, n / 2, m);
	else return x*mypow(x, n - 1, m) % m;
}
 
//-----------------------------------------------------------------------------

int n,flg=-1,cnt,prv;

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

	cin>>n;
	
	REP(i,n) {
		int a;cin>>a;
		if(flg==-1) prv=a,flg=0;
		else {
			if(flg==0) {
				if(prv<a) flg=1;
				else if (prv>a) flg=2;
			}
			else if(flg==1) {
				if(prv>a) flg=0,cnt++;
			}
			else if(prv<a) flg=0,cnt++;
		}
		prv=a;
	}
	cout<<cnt+1<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias A = Tuple!(int, "no", string, "name", int, "value");

void main() {
    int n; scan(n);
    A[] a;
    for (int i = 0; i < n; i++) {
        string name;
        int value;
        scan(name, value);
        a ~= A(i + 1, name, value);
    }

    a.sort!((a, b) => a.name == b.name ? a.value > b.value : a.name < b.name);
    foreach (e; a) {
        writeln(e.no);
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	long count = 0;

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Card[] A = new Card[n];
		Card[] B = new Card[n];
		for (int i = 0; i < n; i++) {
			A[i] = B[i] = new Card(scanner.next().charAt(0), scanner.nextInt());
		}
		quicsort(A, 0, n - 1);
		meregsort(B, 0, n);
		boolean flag = true;
		for (int i = 0; i < n; i++) {
			if (A[i].pic != B[i].pic) {
				flag = false;
				break;
			}
		}
		System.out.println(flag ? "Stable" : "Not stable");
		for (int i = 0; i < n; i++) {
			System.out.println(A[i].pic + " " + A[i].num);
		}
	}

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

	}

	private void merge(Card[] b, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		Card[] L = new Card[n1 + 1];
		Card[] R = new Card[n2 + 1];
		for (int i = 0; i < n1; i++) {
			L[i] = b[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = b[mid + i];
		}
		L[n1] = new Card(' ', Integer.MAX_VALUE);
		R[n2] = new Card(' ', Integer.MAX_VALUE);

		int l = 0;
		int r = 0;
		for (int i = left; i < right; i++) {
			if (L[l].num <= R[r].num) {
				b[i] = L[l++];
			} else {
				b[i] = R[r++];
			}
		}
	}

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

	}

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

	class Card {
		char pic;
		int num;

		public Card(char pic, int num) {
			this.pic = pic;
			this.num = num;
		}

	}
}

Measured memory_bytes: 100672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double PI = acos(-1);

const ll maxv = 1e18;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	ll ans = 1;
	for (int i = 0; i < n; i++) {
		if (maxv / ans < a[i]) {
			cout << -1 << endl;
			return 0;
		}
		ans *= a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return (a/g*b);
}
int main() {
    int n,ans = 0;
    cin >> n;
    vector<int> p;
    for (int i = 0; i < n; ++i) {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    for (int i = 0; i < n; ++i) {
        if(p[i] == i+1 && i != n-1) swap(p[i],p[i+1]),ans++;
        else if(p[i] == i+1 && i == n-1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  int c,minc=999;
  for(int i=0;i<S.size()-2;i++){
    c=(S[i]-48)*100+(S[i+1]-48)*10+(S[i+2]-48);
    minc=min(abs(753-c),minc);
  }
  cout<<minc<<endl;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int main()
{
  int N;
  scanf("%d", &N);
  vector< double > t(N);
  vector< double > v(N);
  REP(i, N) {
    scanf("%lf", &t[i]);
  }
  REP(i, N) {
    scanf("%lf", &v[i]);
  }

  // 全体のT秒を求める
  int T = 0;
  REP(i, N) {
    T += t[i];
  }
  
  vector< double > maxV(2 * T + 1, (double)INF);

  // maxのスピードをv[i]で初期化
  int nowT = 0;
  REP(i, N) {
    REP(ti, t[i]) {
      int t1 = nowT + ti * 2;
      int t2 = nowT + ti * 2 + 1;
      maxV[t1] = min(maxV[t1], v[i]);
      maxV[t2] = min(maxV[t2], v[i]);
      // debug(t1);
      // debug(t2);
    }
    nowT += t[i] * 2;
    maxV[nowT] = min(maxV[nowT], v[i]);
  }
  // debug(T);
  // debug(nowT);

  // 0秒とT秒は0(静止)
  maxV[0] = maxV[T * 2] = 0.0;
  
  // 0.5秒間隔で時間軸を扱う

  /*
  REP(i, 2 * T + 1) {
    printf("%.1f: %f\n", 0.5 * (double)i, maxV[i]);
  }
  */
  
  

  // 前から比較
  REP(ti, 2 * T + 1) {
    maxV[ti + 1] = min(maxV[ti + 1], maxV[ti] + 0.5);
  } 
  
  /*  
  REP(i, 2 * T + 2) {
    printf("%.1f: %f\n", 0.5 * (double)i, maxV[i]);
  }
  */
  
  
  // 後ろから比較
  RREP(ti, 2 * T + 1) {
    maxV[ti] = min(maxV[ti], maxV[ti + 1] + 0.5);
  }

  // 前から比較
  REP(ti, 2 * T + 1) {
    maxV[ti + 1] = min(maxV[ti + 1], maxV[ti] + 0.5);
  }

  
  // 後ろから比較
  RREP(ti, 2 * T + 1) {
    maxV[ti] = min(maxV[ti], maxV[ti + 1] + 0.5);
  }

  
  double ans = 0.0;
  REP(i, 2 * T + 1) {
    // (上底 + 下底) * 高さ / 2
    ans += (maxV[i] + maxV[i + 1]) * 0.5 / 2.0;
  }

  printf("%.4f\n", ans);


  /*  
  REP(i, 2 * T + 1) {
    printf("%.1f: %f\n", 0.5 * (double)i, maxV[i]);
  }
  */
  
  
  
  
  

  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
   int N,M;
   cin >> N >> M;
   vector<pair<ll,ll>> pair(N);
   for(int i = 0; i < N; i++){
       cin >> pair.at(i).first;
       cin >> pair.at(i).second;
   }
   sort(pair.begin(),pair.end());
   ll ans = 0;
   int cnt = 0;
   while(M != 0){
       if(M <= pair.at(cnt).second){
           ans += pair.at(cnt).first * M;
           M = 0;
       }
       else{
           ans += pair.at(cnt).first * pair.at(cnt).second;
           M -= pair.at(cnt).second;
           cnt++;
       }
   }
   cout << ans << endl;
}

Measured memory_bytes: 1792
def main1(N, A):
    dic = {}
    res = ""
    for i in range(0, N):
        dic[A[i]] = i+1
    for i in range(1, N+1):
        res += " {}".format(dic[i])
    print(res[1:])

def main2(N, A):
    lst = list()
    res = ""
    for i in range(0, N):
        lst.append({"rank":A[i], "No":i+1})
    lst.sort(key = lambda x:x["rank"])
    for i in range(0, len(lst)):
        res += " {}".format(lst[i]["No"])
    print(res[1:])

N = int(input())
A = list(map(int, input().split()))
main1(N, A)
#main1(3,[2,3,1])#3 1 2
#main1(5,[1,2,3,4,5])#1 2 3 4 5
#main1(8,[8,2,7,3,4,5,6,1])#8 2 4 5 6 7 3 1


Measured memory_bytes: 20700
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
ll ans;
int i,j,k,n,m,c1,c2,a[210001];
int main(){
	while (scanf("%d%d%d",&n,&c1,&c2)!=EOF){
		for (i=1;i<=n;i++) scanf("%d",&a[i]);
		for (ans=0,i=1;i<n;i++) ans+=min((ll)c1*(ll)(a[i+1]-a[i]),(ll)c2);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#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 ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<pair<Int, Int>> vp(N);
        for (int i = 0; i < N; ++i) {
            cin >> vp[i].first;
            vp[i].second = i + 1;
        }

        sort(all(vp));
        for (int i = 0; i < N; ++i) {
            cout << vp[i].second << " ";
        }
        cout << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define E 1e-18
#define ll long long
#define int long long
#define db double
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}

int const N=1e5+3;
int top,n,m,cnt,sta[N];
struct point{
	db x,y;
    point operator - (point A) const{return (point){x-A.x,y-A.y};}
    point operator + (point A) const{return (point){x+A.x,y+A.y};}
    void print(){printf("%.10lf %.10lf\n",x,y);}
}A,B,C,D,c[N],p1[N],p2[N];

point operator *(db x,point A){return (point){x*A.x,x*A.y};}
db CJ(point A,point B){return A.x*B.y-B.x*A.y;}//叉积 
db DJ(point A,point B){return A.x*B.x+A.y*B.y;}//点积 
db dis(point A){return sqrt(A.x*A.x+A.y*A.y);}//向量长度 
bool cmp(point A,point B){return (CJ(A,B)>0 || CJ(A,B)==0 && dis(A)<dis(B));}//按极角排序 
point CGL_1_A(point A,point B,point C){//点在直线上的投影点
	db d=dis(B-A);
	return (A+(DJ(C-A,B-A)/d/d*(B-A)));
}
point CGL_1_B(point A,point B,point C){//点关于直线的对称点
	point P=CGL_1_A(A,B,C);
	return (C+2*(P-C));
}
int CGL_1_C(point A,point B,point C){//向量的位置关系(向量AC和向量AB) 
    if (CJ(B-A,C-A)>0) return 1;//逆时针 
    if (CJ(B-A,C-A)<0) return 2;//顺时针 
    if (DJ(C-A,B-A)<0) return 3;//方向相反
	if (dis(C-A)>dis(B-A)) return 4;//方向相同 AC>AB
	if (dis(C-A)<=dis(B-A)) return 5;//方向相同 AB>AC
}
int CGL_2_A(point A,point B,point C,point D){//判断直线平行、垂直
	if (CJ(B-A,D-C)==0) return 2;//平行 
	if (DJ(B-A,D-C)==0) return 1;//垂直 
	return 0;//相交 
}
int CGL_2_B(point A,point B,point C,point D){//判断线段是否有交
	if (min(A.x,B.x)>max(C.x,D.x) || min(C.x,D.x)>max(A.x,B.x) || min(A.y,B.y)>max(C.y,D.y) || min(C.y,D.y)>max(A.y,B.y)) return 0;//快速排斥实验(两个矩形是否相交)
	return CJ(B-A,C-A)*CJ(B-A,D-A)<=0 && CJ(D-C,A-C)*CJ(D-C,B-C)<=0;//跨立实验
}
point CGL_2_C(point A,point B,point C,point D){//求直线交点
	point p1=CGL_1_A(A,B,C),p2=CGL_1_A(A,B,D);//求C、D在AB上的投影点 
	db d1=dis(C-p1),d2=dis(D-p2);//三角形的相似比 
	if (CJ(B-A,C-A)*CJ(B-A,D-A)<0) return (C+(d1/(d1+d2)*(D-C)));
	else if (d1<d2) return (D+d2/(d2-d1+E)*(C-D));
	else return (C+d1/(d1-d2+E)*(D-C));
}
db Distance(point A,point B,point C){//点到线段的距离 
	point P=CGL_1_A(A,B,C);//C在AB上的投影点 
	if (P.x>=min(A.x,B.x) && P.x<=max(A.x,B.x) && P.y>=min(A.y,B.y) && P.y<=max(A.y,B.y)) return dis(P-C);//投影点在线段上 
	return min(dis(A-C),dis(B-C));//两个端点到C的最小值 
}
db CGL_2_D(point A,point B,point C,point D){//线段到线段的距离
	point P=CGL_2_C(A,B,C,D);//求直线交点 
	if (P.x>=min(A.x,B.x) && P.x<=max(A.x,B.x) && P.y>=min(A.y,B.y) && P.y<=max(A.y,B.y) && P.x>=min(C.x,D.x) && P.x<=max(C.x,D.x) && P.y>=min(C.y,D.y) && P.y<=max(C.y,D.y)) return 0;//线段有交点 
	return min(Distance(A,B,C),min(Distance(A,B,D),min(Distance(C,D,A),Distance(C,D,B))));
}

signed main(){
	for (int q=read();q;q--){
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y);
		printf("%.10lf\n",(CGL_2_D(A,B,C,D)));
	}
	return 0;
} 


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

int main(){

 
  int A,B;
  cin>>A>>B;

  double org=A*12.5;
	
  int start=floor(org)-1;
	
  int flag=0;
  while(1){

    if( floor(start*0.08)==A && floor(start*0.1)==B){flag=1;break;}

    if( floor(start*0.08)>A || floor(start*0.1)>B )break;
    
    start++;
    
    
  }

	
  if(flag==1)cout<<start<<endl;
  else cout<<-1<<endl;
  
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main () {
	int H, W;
	cin >> H >> W;
	vs A(H);
	int count = 0;
	REP(i, H) {
		cin >> A[i];
		REP(j, W) {
			if (A[i][j] == '#') {
				count++;
			}
		}
	}

	if (count == H + W - 1) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

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

int main(){
    int n,m; cin>>n>>m;
    vector<int> p(m);
    vector<string> s(m);
    rep(i,m) cin>>p.at(i)>>s.at(i);
    vector<pair<bool,int>> sum(n);
    rep(i,n){
        sum.at(i).first = false;
        sum.at(i).second = 0;
    }
    rep(i,m){
        if(s.at(i)=="AC"){
            sum.at(p.at(i)-1).first=true;
        }else if(sum.at(p.at(i)-1).first==false){
            sum.at(p.at(i)-1).second++;
        }
    }
    int ac_sum=0;
    int penalty_sum = 0;
    rep(i,n){
        if(sum.at(i).first==true){
            ac_sum++;
            penalty_sum += sum.at(i).second;
        }
    }

    cout << ac_sum << " " << penalty_sum << endl;
}


Measured memory_bytes: 6912
"use strict";

function main(input) {
  input = input.trim().split("\n");
  const N = parseInt(input[0]);
  const S_arr = input[1].split("");
  let ans = 0;
  for (let i = 0; i < N; i++) {
    if (S_arr[i] === "A") {
      if (S_arr[i + 1] === "B") {
        if (S_arr[i + 2] === "C") {
          ans++;
        }
      }
    }
  }
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 30556
#include <stdio.h>
#include <string.h>
 
int main(void) {
    char s[128], p[128], *i;
    char ss[256];
    if (fgets(s, sizeof(s), stdin) == NULL) return 1;
    if (fgets(p, sizeof(p), stdin) == NULL) return 1;
    if ((i = strchr(s, '\n')) != NULL) *i = '\0';
    if ((i = strchr(p, '\n')) != NULL) *i = '\0';
    strcpy(ss, s);
    strcat(ss, s);
    puts(strstr(ss, p) != NULL ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 2112
// Problem : B - FizzBuzz Sum
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

int main()
{
	int n;cin>>n;
	ll sum=0;
	rep(i,1,n){
		if(i%3 && i%5) sum+=i;
	}
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int l=max(a,c);
  int r=min(b,d);
  if(l>=r)puts("0");
  else printf("%d\n",r-l);
  return 0;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for i in range(Q)]
ans = 0

for A in combinations_with_replacement(range(M), N):
    temp = 0
    for abcd in ABCD:
        if A[abcd[1]-1]+1 == A[abcd[0]-1]+1 + abcd[2]:
            temp += abcd[3]
    if temp > ans:
        ans = temp
print(ans)

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

int main(void){
    int N; cin >> N;
    double ans;
    for(int i = 1; i <= 9; i++){
        ans = (double)N /i;
        if(ans - (N/i) == 0.0 && ans < 10){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    long long int A, B, C, K;
    long long int ans = 0;
    cin >> A >> B >> C >> K;
    ans += min(A, K);
    K = max((long long int)0, K-A-B);
    ans -= K;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define fec(i,a) for(__typeof a.begin() i=a.begin();i!=a.end();++i)
#define For(i,u) for(int i=H[u];i;i=nxt[i])
#define re(i,a,b) for (int i=a;i<b;++i)
#define si(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
template<class T> inline void read(T&x){char c;bool fu=0;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x*=-1;}
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z) {read(x,y);read(z);}
typedef long long ll;
typedef pair<int,int> pii;
const int N=111111;
//head
map<pii,bool> ma,m2;
int H,W;
pii a[N];
int n;
ll ans[10];
int main() {
	read(H,W);read(n);
	rep(i,1,n)read(a[i].X,a[i].Y),ma[a[i]]=1;
	ans[0]=(H-2ll)*(W-2ll);
	rep(_,1,n){
		int x=a[_].X,y=a[_].Y;
		rep(i,max(1,x-2),min(x,H-2))
			rep(j,max(1,y-2),min(y,W-2))if(!m2[mp(i,j)]){
				int cc=0;
				rep(k,0,2)rep(l,0,2)if(ma[mp(i+k,j+l)])++cc;
				ans[cc]++;
				m2[mp(i,j)]=1;
			}
	}
	rep(i,1,9)ans[0]-=ans[i];
	rep(i,0,9)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 213504
n,m=map(int,input().split())
A=list(map(int,input().split()))
all=int(0)
for i in range(n):
    all+=A[i]
cnt=int(0)
for i in range(n):
    if A[i]>=all/4/m:
        cnt+=1
if cnt>=m:
    print("Yes")
else:
    print("No")

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

int main(){
    int n;
    while(cin>>n && n!=0){
        int* A=new int[n];
        int* S=new int[n+1];
        S[0]=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            S[i+1]=A[i]+S[i];
        }

        int maxsum=A[0];
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n+1;++j){
                maxsum=((S[j]-S[i])>maxsum?(S[j]-S[i]):maxsum);
            }
        }

        cout<<maxsum<<"\n";
        delete[] A;
        delete[] S;
    }
}

Measured memory_bytes: 3116
n=int(input())
s=input()
b=[0 for i in range(n)]
tmp=0
for i in range(n-1,-1,-1):
    if s[i]=="#":
        tmp+=1
    b[i]=tmp
w=[0 for i in range(n)]
tmp=0
for i in range(n):
    if s[i]==".":
        tmp+=1
    w[i]=tmp
tmp=0
ans=float("inf")
for i in range(n):
    tmp=n-(w[i]+b[i])
    if tmp<ans:
        ans=tmp
print(ans)

Measured memory_bytes: 18744
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 301


bool solve(){
  int n, w[SIZE];
  bool dp[SIZE][SIZE];

  scanf("%d", &n);
  if(n == 0) return 0;

  for(int i=0;i<n;i++) scanf("%d", w+i);
  
  memset(dp, 0, sizeof(dp));
  
  for(int i=0;i<n;i++) dp[i][i] = true;

  for(int x=2;x<=n;x+=2){
    for(int l=0;l+x<=n;l++){
      int r = l + x;
      
      // if(l >= 2 && abs(w[l-2] - w[l-1]) <= 1) dp[l-2][r] = true;
      // if(r <= n-2 && abs(w[r] - w[r+1]) <= 1) dp[l][r+2] = true;

      if(abs(w[l] - w[r-1]) <= 1) dp[l][r] |= dp[l+1][r-1];

      for(int i=l+1;i<r;i++){
        dp[l][r] |= dp[l][i] && dp[i][r];
      }
    }
  }

  int dp2[SIZE] = {};
  
  for(int i=0;i<n;i++){
    for(int j=i+2;j<=n;j++){
      if(dp[i][j]) dp2[j] = max(dp2[j], dp2[i] + (j-i));
    }
    dp2[i+1] = max(dp2[i+1], dp2[i]);
  }
  
  printf("%d\n", dp2[n]);
  return true;
}

int main(){
  while(solve());
  
  return 0;
}



Measured memory_bytes: 3276
#include <cstdio>
#include <string>
#include <set>
#include <iostream>
using namespace std;
int main(){
  int n,type;
  string s[10];
  set<string>data;
  while(cin >> n >> type && n||type){
    for(int i = 0;i<n;i++) cin >> s[i];
    if(type==2) for(int i=0;i<n;i++)
               for(int j=0;j<n;j++)
                 if(i!=j) data.insert(data.end(),s[i]+s[j]);
    if(type==3) for(int i=0;i<n;i++)
               for(int j=0;j<n;j++)
                 for(int k=0;k<n;k++)
                   if(i!=j&&i!=k&&j!=k) data.insert(data.end(),s[i]+s[j]+s[k]);
    if(type==4) for(int i=0;i<n;i++)
               for(int j=0;j<n;j++)
                 for(int k=0;k<n;k++)
                   for(int l=0;l<n;l++)
                     if(i!=j&&i!=k&&i!=l&&j!=k&&j!=l&&k!=l) data.insert(data.end(),s[i]+s[j]+s[k]+s[l]);
    cout << data.size() << endl;
    data.clear();
  }
}

Measured memory_bytes: 1456
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2000;
int n,k;
vector<int> lnk[N+5];
vector< pair<int,int> > edg;
void DFS(int u,int pre,int dep,int &del_tot) {
	if(dep>k/2) del_tot++;
	for(int i=0; i<lnk[u].size(); i++) {
		int v=lnk[u][i];
		if(v==pre) continue;
		DFS(v,u,dep+1,del_tot);
	}
}
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1; i<n; i++) {
		int u,v;
		scanf("%d%d",&u,&v);
		lnk[u].push_back(v);
		lnk[v].push_back(u);
		edg.push_back(make_pair(u,v));
	}
	int ans=(1<<30);
	if(k%2) {
		k--;
		for(int i=0; i<edg.size(); i++) {
			int u=edg[i].first,v=edg[i].second;
			int resu=0,resv=0;
			DFS(u,v,0,resu);
			DFS(v,u,0,resv);
			ans=min(ans,resu+resv);
		}
	} else {
		for(int i=1; i<=n; i++) {
			int res=0;
			DFS(i,0,0,res);
			ans=min(ans,res);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,y,z,c=0;
	cin>>n>>x>>y;
	for(int i=0;i<n-2;i++){
		cin>>z;
		if(x>y && z<y){
			c++;
		}
		else if(y>x && z>y){
			c++;
		}
		x=y;y=z;
	}
	cout<<c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 2e5 + 10;
map<int,int> g[N];


int temp = 0;
int vis[N];

void dfs(int node)
{
    vis[node] = 1;
    
    for(auto x : g[node])
        if(vis[x.F] == 0) dfs(x.F);
        
    temp++;
}

void solve()
{
   int n,m;
    cin >> n >> m;
    
    int u,v;
    
    f(i,m)
    {
        cin >> u >> v;
        g[u][v] = g[v][u] = 1;
    }
    
    int res = 0;
    
    for(int i=1;i<=n;i++)
    {
        if(vis[i] == 1) continue;
        temp = 0;
        dfs(i);
        res = max(res,temp);
    }
    
    cout <<res;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

int main(int argc, char const* argv[])
{
	int n, m, l;
	cin >> n >> m >> l;
	int a[100][100] = {{}};
	int b[100][100] = {{}};
	long c[100][100] = {{}};

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

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

	for (int i=0; i<n; i++) {
		for (int j=0; j<l; j++) {
			for (int k=0; k<m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
			cout << c[i][j]; 
			if (j == l-1) continue;
			cout << " ";
		}
		cout << endl;
	}
	return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<ll> vSize;

    UnionFind(ll N) : par(N), vSize(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++)
        {
            par[i] = i;
            vSize[i] = 1;
        }
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        vSize[ry] += vSize[rx];
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x){    // データxが属する木の頂点数を得る
        ll rx = root(x);
        return vSize[rx];
    }
};

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> p(N);
    REP(i, N)
    {
        cin >> p[i];
        p[i]--;
    }

    UnionFind uf(N);
    REP(i, M)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }
    ll ans = 0;
    REP(i, N)
    {
        if (uf.same(i, p[i]))
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 100000000000000
class WarshallFloyed{
public:
	int V; //????????°
	ll D[256][256]; //i??????j???????????????D[i][j]
	WarshallFloyed(){}
	WarshallFloyed(int _V){
		V = _V;
	}
	void init(){
		for(int i = 0; i < V; ++i){
			for(int j = 0; j < V; ++j){
				if(i == j){
					D[i][j] = 0;
				}
				else{
					D[i][j] = INF;
				}
			}
		}
	}
	bool addEdge(int from,int to,ll cost){
		if(D[from][to] != INF)return false;
		D[from][to] = cost;
		return true;
	}
	bool getShortestPath(){
		for(int k = 0; k < V; ++k){
			for(int i = 0; i < V; ++i){
				for(int j = 0; j < V; ++j){
					D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
				}
			}
		}
		return true;
	}
	bool isNegativeCycle(){
		for(int i = 0; i < V; ++i){
			if(D[i][i] < 0){
				return true;
			}
		}
		return false;
	}

	void print(){
		for(int i = 0; i < V; ++i){
			for(int j = 0; j < V; ++j){
				if(D[i][j] >= 1e9*2) printf("INF%c",j==V-1?'\n':' ');
				else printf("%lld%c",D[i][j],j==V-1?'\n':' ');
			}
		}
	}
};

class Belman{
public:
	struct edge{
		ll from,to,cost;
		edge(){}
		edge(ll _from, ll _to, ll _cost){
			from = _from;
			to = _to;
			cost = _cost;
		}
	};
	long long d[10001];
	edge graph[10001];
	int V,E;
	int idx;
	Belman(){}
	Belman(int _V,int _E){
		V = _V;
		E = _E;
		idx = 0;
	}
	bool init(){
		for(int i = 0; i < 10001; ++i){
			d[i] = INF;
			graph[i] = edge(0,0,0);
		}
	}
	bool addEdge(ll from, ll to, ll cost){
		graph[idx] = edge(from,to,cost);
		idx++;
		return true;
	}
	int getShortestPath(ll start){
		d[start] = 0;
		int cnt = 0;
		while(true){
			bool update = false;
			for(int i = 0; i < E; ++i){
				edge e = graph[i];
				if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					update = true;
				}
			}
			if(!update)break;
			if(cnt == V-1)return -1;
			cnt++;
		}
		return 0;
	}
	void print(){
		for(int i = 0; i < V; ++i){
			printf("%lld%c",d[i],i == V-1?'\n':' ');
		}
	}
};

struct UnionFind{
    int N,par[1000],sz[1000];
    UnionFind(){
        N=1000;
        for(int i = 0; i < N; ++i){
            par[i] = i;
            sz[i] = 1;
        }
    }
    int find(int x){
        return x == par[x] ? x : par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        if(sz[x] < sz[y]) swap(x,y);
        par[y] = x;
        sz[x] += sz[y];
        sz[y] = 0;
    }
    int getSize(int x){
        return sz[find(x)];
    }
};

int main(){
	ll v,e;
	cin >> v >> e;
	ll r;
	cin >> r;
	Belman B = Belman(v,e);
	B.init();
	for(int i = 0; i < e; ++i){
		ll a,b,c;
		cin >> a >> b >> c;
		B.addEdge(a,b,c);
	}
	if(B.getShortestPath(r) == -1){
		puts("NEGATIVE CYCLE");
	}
	else{
		for(int i = 0; i < v; ++i){
			if(B.d[i] != INF)printf("%d\n",B.d[i]);
			else puts("INF");
		}
	}
	return 0;
}

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

typedef long long ll;

const int MAXN = 1e4 + 5;

int N;
int a[MAXN], b[MAXN];
ll sum, mn;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", a + i);
	for (int i = 0; i < N; i++)
		scanf("%d", b + i);
	
	for (int i = 0; i < N; i++) {
		int c = b[i] - a[i];
		sum += c;
		if (c > 0)
			mn += (c - 1) / 2 + 1;
	}
	
	puts(mn <= sum ? "Yes" : "No");
	
	return 0;
}

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

int main() {
  char a;
  cin>>a;
  
  if(a=='A'){
    cout<<"T"<<endl;
  }
  if(a=='C'){
    cout<<"G"<<endl;
  }
  if(a=='G'){
    cout<<"C"<<endl;
  }
  if(a=='T'){
    cout<<"A"<<endl;
  }
  
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}

ll inverse(ll n)
{
	return exp(n,MOD-2);
}
ll LIM=6010;
v64 factorial(LIM,1);

void solve()
{
//Read Comments below main
	ll n,x,y;
	cin>>n>>x>>y;
	vv64 dp(n+1,v64(n+1,0));
	v64 counter(n+1,0);
	for (ll i=1; i<=n; i++)
	{
		for (ll j=i+1; j<=n; j++)
		{
			// if (j<=x)
			// {
			// 	counter[j-i]++;
			// }
			// else if (i>=y)
			// {
			// 	counter[j-i]++;
			// }
			// else if (j>=x && i<=x)
			// {
			// 	ll d=min(j-i,x-i + 1 + y-j);
			// 	counter[d]++;
			// }
			// else if (j>=x && i>=x)
			// {
			// 	ll d=min(j-i,i-x + 1 + y-j);
			// 	counter[d]++;
			// }
			// else if (j>=y && i>=x && i<=y)
			// {
			// 	ll d=min(j-i,abs(i-x)+1+abs(y-j));
			// 	counter[d]++;
			// }
			// else
			// {
			// 	cout<<i<<" "<<j<<endl;
			// 	assert(1<0);
			// }
			int d=min(abs(i-j),abs(x-i)+1+abs(y-j));
			counter[d]++;
		}
	}
	for (ll i=1; i<n; i++)
		cout<<counter[i]<<endl;;
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
int n, k, h[100000], dp[100000];
int calc(int i) {
	if(i == n - 1) return 0;
	if(dp[i] != -1) return dp[i];
	int res = INT_MAX;
	for(int j = 1; j <= k; j++) {
		if(i + j > n - 1) break;
		res = min(res, calc(i + j) + abs(h[i] - h[i + j]));
	}
	return dp[i] = res;
}
int main() {
	R(n, k);
	for(int i = 0; i < n; i++) R(h[i]);
	memset(dp, -1, sizeof(dp));
	int ans = calc(0);
	W(ans);
	return 0;
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int k, a, b;
	cin >> k >> a >> b;

	int x = (a + k - 1) / k * k;
	if (a <= x && x <= b) cout << "OK\n";
	else cout << "NG\n";	
}

Measured memory_bytes: 3636
import collections
s = set()
N = int(input())
count = []*(10**9+1)
ma1 = 0
ma2 = 0
A = list(map(int,input().split()))
a = collections.Counter(A)
b = sorted(a.items(),reverse = True)

for i in b:
  if ma1 == 0 and i[1] > 1:
    ma1 = i[0]
    if i[1] > 3:
      ma2 = i[0]
  elif ma1 != 0 and i[1] > 1:
    ma2 = i[0]
  if ma1 > 0 and ma2 > 0:
    break
  
print(ma1*ma2)
    

Measured memory_bytes: 21412
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X, mod = mapint()
doubling = [[i*i%mod for i in range(mod)]]
accu = [doubling[0][:]]

for i in range(40):
    tmp1 = [None]*mod
    tmp2 = [None]*mod
    for j in range(mod):
        tmp1[j] = doubling[-1][doubling[-1][j]]
        tmp2[j] = accu[-1][doubling[-1][j]] + accu[-1][j]
    doubling.append(tmp1)
    accu.append(tmp2)
now = X
ans = X
for i in range(40):
    if (N-1)>>i&1:
        ans += accu[i][now]
        now = doubling[i][now]
print(ans)

Measured memory_bytes: 198176
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    string a,b;
    cin>>a>>b;
    size_t m =a.length(), n = b.length();
    int dp[m+1][n+1];
    for (size_t i = 0 ; i <= m; i++) {
        dp[i][0] = 0;
    }
    for (size_t i = 0 ; i <= n; i++) {
        dp[0][i] = 0;
    }
    int ans = 0;
    string ansstr = "";
    for (size_t i = 1 ; i <= m; i++) {
        for (size_t j = 1 ; j <= n; j++) {
            ans = 0;
            if (a[i-1] == b[j-1]) {
                ans = 1 + dp[i-1][j-1];
            }
            ans = max(ans, dp[i-1][j]);
            ans = max(ans, dp[i][j-1]);
            dp[i][j] = ans;
        }
    }
    size_t temp = ans, i = m, j = n;
    while(temp > 0){
        while (dp[i][j] == temp) {
            i--;
        }
        i++;
        while (dp[i][j] == temp) {
            j--;
        }
        j++;
        temp--;
        ansstr.push_back(a[i-1]);
        i--;
        j--;
    }
    int l = ans;
    for (i = 0 ; i < l; i++) {
        std::cout << ansstr[l-i-1];
    }
    std::cout << endl;
    return 0;
}



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


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

    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
    }
    ll s_min,s_max;
    ll g_min,g_max;
    ll num;
    ll min_sum = -1e15;
    typedef map<ll,ll> mp;
    vector<mp> dp_0(N),dp_1(N);
    dp_0[0][0]=0;
    dp_0[0][1]=min_sum;
    dp_1[0][1]=A[0];
    dp_1[0][0]=min_sum;
    
    for(ll i=1;i<N;i++){
        s_min = max(0ll,N/2-(N-i+1)/2);
        s_max = min(N/2,(i+1)/2);
        g_min = max(0ll,N/2-(N-(i+1)+1)/2);
        g_max = min(N/2,(i+2)/2);
        // cout<<i+1<<"回目"<<"\n";
        // cout<<s_min<<" "<<s_max<<"\n";
        // cout<<g_min<<" "<<g_max<<"\n";
        num = g_min;
        while(num<=g_max){
            // dp_0の更新
            if(s_max>=num){
                dp_0[i][num] = max(dp_0[i-1][num],dp_1[i-1][num]);
                // cout<<0<<i<<" "<<num<<"\n";
                // cout<<dp_0[i][num]<<"\n";
            }else{
                dp_0[i][num] = min_sum;
            }
            
            // dp_1の更新
            if(s_min<=num-1){
                dp_1[i][num] = dp_0[i-1][num-1]+A[i];
                // cout<<1<<i<<" "<<num<<"\n";
                // cout<<dp_1[i][num]<<"\n";
            }else{
                dp_1[i][num] = min_sum;
            }
            ++num;
        }
    }

    ll ans = max(dp_0[N-1][N/2],dp_1[N-1][N/2]);
    cout<<ans<<"\n";
    
	return 0;
}

Measured memory_bytes: 73424
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a.cpp"

int main() {
  char c;
  cin >> c;
  if ('A' <= c and c <= 'Z') {
    puts("A");
  } else {
    puts("a");
  }
}


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

int main() {
  int A,B,C,D,L,R;
  cin >> A >> B >> C >> D;
  L=A+B;R=C+D;
  if(L>R){
    cout << "Left" << endl;
  }
  else if(L==R){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

ll n, a, b;

signed main() {

    cin >> n >> a >> b;

    if(a > b) swap(a, b);
    
    if(a%2 == b%2) {
        cout << abs(a-b)/2 << endl;
    }
    else {
        cout << min(a-1, n-b) + 1 + (b-a-1)/2 << endl;
    }


  
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  string str;
  cin >> str;
  for(int i=0;i<12;i++){
    cout <<str[i];
    if(i==3)cout <<' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<bool> b(n, false);
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int a;
            cin >> a;
            b[--a] = true;
        }
    }
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(!b[i]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3196
import java.util.*;
import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toMap;

public class Main {

    public static void main(String[] args) {

        Scanner Input = new Scanner(System.in);
        int N = Input.nextInt();
        HashMap<String, Integer> HM = new HashMap();

        for (int I = 0; I < N; I++) {
            String S = Input.next();
            if (!HM.containsKey(S)) {
                HM.put(S, 0);
            }
        }
        System.out.println(HM.size());
    }
}


Measured memory_bytes: 24916
#include<stdio.h>
int main(void)
{
    int S,s,m,h;
    
    scanf("%d",&S);
    h=S/3600;
    m=S%3600/60;
    s=S%3600%60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}


Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

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

Measured memory_bytes: 3648
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  set<int> s;
  s.insert(A);
  s.insert(B);
  s.insert(C);
  if (s.size() == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
def solve():
    # 解説放送を実装
    # 区切る問題
    N, M = [int(x) for x in input().split(" ")]
    X = [int(x) for x in input().split(" ")]

    if M == 1:
        print(0)
        return

    X.sort()
    distance = []
    for i in range(0, len(X)-1):
        distance.append(X[i+1] - X[i])
    
    distance.sort()

    ans = 0
    for i in range(0, len(distance)-(N-1)):
        ans += distance[i]
    
    print(ans)



if __name__ == "__main__":
    solve()

Measured memory_bytes: 13840