akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int main() {
	int n;
	int ave = 0, dif = INF, ans=0;
	cin >> n;
	vi v(n);
	rep(i, n) {
		cin >> v[i];
		ave += v[i];
		v[i] *= n;
	}
	rep(i, n) {
		if (dif>abs(ave - v[i])) {
			dif = abs(ave - v[i]);
			ans = i;
		}
	}
	cout << ans << endl;
}


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

int main(){
  int N;
  cin>>N;
  int A[N+1];
  int B;
  long long total=0;
  
  for (int i=0;i<N+1;i++){
    cin>>A[i];
  }
  for (int i=0;i<N;i++){
    cin>>B; 
    if(B<=A[i]){
      total=total+B;
    }
    else {
      total=total+A[i];
      B=B-A[i];
        if(B>=A[i+1]){
          total=total+A[i+1];
          A[i+1]=0;
        }
      else{
        total=total+B;
        A[i+1]=A[i+1]-B;
      }
    }
  }
  cout<<total<<endl;
  return 0;
}

      
    
    
    

      
  



  

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

#define int long long
#define ll long long
#define pb push_back

main(){
    int n;
    string h;
    cin >> n >> h;
    if (h.size() <= n){
        cout << h;
    }
    else{
        for(int i = 0; i < n; i++){
            cout << h[i];
        }
        cout << "...";
    }
}


Measured memory_bytes: 3624
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
DIV = 998244353

L = [None] * K
R = [None] * K
for i in range(K):
  L[i],R[i] = map(int,readline().split())

dp = [0] * (N + 1)
sdp = [0] * (N + 1)
dp[1] = 1
sdp[1] = 1
  
for i in range(2, len(dp)):
  for j in range(K):
    li = max(i - R[j], 0)
    ri = i - L[j]
    if ri < 0:
      continue
    dp[i] += (sdp[ri] - sdp[li - 1])
    dp[i] %= DIV
  sdp[i] = sdp[i - 1] + dp[i]
  sdp[i] %= DIV
  
print(dp[N])

Measured memory_bytes: 24396
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
  int x, a, b; cin >> x >> a >> b;
  cout << (abs(a-x) < abs(b-x) ? "A" : "B");
  return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")

#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, K;
int A[200000], B[200000];

signed main(){
    scanf("%d%d", &N, &K);
    rep(i, N) scanf("%d", A+i);

    for(int k=0; k<K; k++){
        bool flg = false;
        vector<int> sum(N+1);
        rep(i, N){
            sum[max(0, i-A[i])]++;
            sum[min(N, i+A[i]+1)]--;
        }
        rep(i, N) sum[i] += (i>0 ? sum[i-1] : 0);
        
        rep(i, N){
            flg |= (A[i]!=sum[i]);
            A[i] = sum[i];
        }
        if(!flg) break;
    }
    rep(i, N) printf("%d ", A[i]);
}


Measured memory_bytes: 5392
#include <stdio.h>

int main(){
    int n;
    scanf("%d\n", &n);

    int p[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &p[i]);
    }
    
    int local_min = 1000000;
    int count = 0;
    for (int i = 0; i < n || p[i] > 1; ++i) {
        if (p[i] < local_min) {
            local_min = p[i];
            ++count;
        }
    }
    printf("%d\n", count);
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

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

int gcd( int a, int b ){
    if( b == 0 ) return a;
    else gcd( b, a % b );
}

signed main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int cd = c * d / gcd( c, d );

    a += ( a - 1 ) / cd - ( a - 1 ) / c - ( a - 1 ) / d;
    b += b / cd - b / c - b / d;

    cout << b - a + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const long long inf = pow(10, 18);

int main(){
    int N;
    cin >> N;
    vector<long long> a(N);

    long long ans = 1;
    for(int i=0; i<N; ++i){
        long long num;
        cin >> num;
        if(num == 0) ans = 0;
        a[i] = num;
    }

    if(ans != 0){
        for(int i=0; i<N; ++i){

        ans=ans*a[i];
		if(ans>inf || ans<=0)
		{
			cout<<"-1"<<endl;
			return 0;
		}
            // long long original_ans = ans;
            // ans = original_ans * a[i];

            // //check overflow
            // if( ans/a[i] != original_ans ){
            //     ans = -1;
            //     break;
            // }

            // if(ans > inf){
            //     ans = -1;
            //     break;
            // }
        }
    }

// 3
// 1000000000 1000000000 3

    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  double total = 0;
  rep(i, n) total += (double) 1.0000 / a[i];
  double ans = 1.0000 / total;
  cout << fixed << setprecision(10) << ans << '\n'; 
  return 0;
}

Measured memory_bytes: 3732
#include<iostream>

using namespace std;


class Goods{
public:
	int left;
	int right;
	int top;
	int bottom;
	char material;

	void check(int h, int w);
};

void Goods::check(int h, int w){
	if (w < left){
		left = w;
	}
	if (w > right){
		right = w;
	}
	if (h < top){
		top = h;
	}
	if (h > bottom){
		bottom = h;
	}
	return;
}


int main(){
	int N;	//データセット数
	int H;	//縦
	int W;	//横

	const int num = 7;	//材質数上限
	int m;	//登場材質数
	int g;
	char read;

	cin >> N;

	for (int n = 0; n < N; n++){
		m = 0;

		cin >> H >> W;

		Goods goods[num];
		int** image = new int*[H];
		
		for (int h = 0; h < H; h++){
			image[h] = new int[W];
			for (int w = 0; w < W; w++){
				cin >> read;
				
				if (read == '.'){
					image[h][w] = -1;
				}
				else{
					g = 0;
					while (g < m){
						if (read == goods[g].material){
							image[h][w] = g;
							goods[g].check(h, w);
							break;
						}
						g++;
					}
					if (g == m){
						image[h][w] = g;
						goods[m].material = read;
						goods[m].left = w;
						goods[m].right = w;
						goods[m].top = h;
						goods[m].bottom = h;
						m++;
					}
				}
			}
		}//読み取り終了


		//for (int h = 0; h < H; h++){
		//	for (int w = 0; w < W; w++){
		//		cout.width(2);
		//		cout << image[h][w];
		//	}
		//	cout << endl;
		//}

		//チェック
		bool** near = new bool*[m];	//手前にあるか(長方形だとしたときに, 行より列が手前ならtrue)
		for (g = 0; g < m; g++){
			near[g] = new bool[m];
			for (int g2 = 0; g2 < m; g2++){
				near[g][g2] = false;
			}
		}
		
		for (g = 0; g < m; g++){
			for (int h = goods[g].top; h <= goods[g].bottom; h++){
				for (int w = goods[g].left; w <= goods[g].right; w++){
					if (image[h][w] == -1){
						goto SUSPICIOUS;
					}
					else if(image[h][w] != g){
						if (near[g][image[h][w]] == false){
							near[g][image[h][w]] = true;
							for (int g2 = 0; g2 < m; g2++){
								near[g][g2] = (near[g][g2] || near[image[h][w]][g2]);
								near[g2][image[h][w]] = (near[g2][g] || near[g2][image[h][w]]);
							}
						}
					}
				}
			}//1材質あたりのチェック
		}//全アイテムチェック
		for (g = 0; g < m; g++){
			if (near[g][g] == true){
				goto SUSPICIOUS;
			}
		}
		cout << "SAFE" << endl;
		continue;
		
	SUSPICIOUS:
		cout << "SUSPICIOUS" << endl;
		continue;
		

	}//1データセット
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <complex>
#include <set>
#include <map>
#include <cmath>
using namespace std;


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

int main(){
	int H,W;
	while(cin >> H >> W && H ){
		vector<string> s(H);
		for(int i = 0 ; i < H ; i++) cin >> s[i];
		
		
		map<string,int> answer;
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				for(int d = 0 ; d < 8 ; d++){
					string wow;
					int done[20][20] = {};
					int x = j , y = i;
					while( done[y][x] == 0 ){
						wow += s[y][x];
						done[y][x] = true;
						answer[wow]++;
						x += dx[d];
						y += dy[d];
						x += W;
						y += H;
						x %= W;
						y %= H;
					}
				}
			}
		}
		int len = 0;
		for( map<string,int>::iterator it = answer.begin(); it != answer.end() ; it++){
			if( it->second < 2 || it->first.size() < 2 ) continue;
			len = max( len , (int)it->first.size() );
		}
		int flag = 0;
		for( map<string,int>::iterator it = answer.begin(); it != answer.end() ; it++){
			if( it->second < 2 || it->first.size() < 2 ) continue;
			if( len == it->first.size() ){
				cout << it->first << endl;
				flag = true;
				break;
			}
		}
		if(flag==0)cout << 0 << endl;
		
	}
}

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

int jyankenPoint(char x, int r, int s, int p) {
	if (x == 'r') return p;
	else if (x == 's') return r;
	else if (x == 'p') return s;
}
char jyankenMethod(char x) {
	if (x == 'r') return 'p';
	else if (x == 's') return 'r';
	else if (x == 'p') return 's';
}

int main() {

	int n, k, r, s, p; cin >> n >> k >> r >> s >> p;
	string t; cin >> t;

	int ans = 0;
	for (int startIndex = 1; startIndex <= k; startIndex++) {

		int num;
		if (startIndex <= n % k) num = n / k + 1;
		else num = n / k;

		string tmp_t; tmp_t += 'e';
		for (int i = 1; i <= num; i++) {
			tmp_t += t[startIndex + k * (i - 1) - 1];
		}

		vector<int> dp(num + 1, 0);
		vector<char> record_rsp(num + 1, 'e');

		for (int i = 1; i <= num; i++) {
			
			if (i != 1) {

				if (jyankenMethod(tmp_t[i]) == record_rsp[i - 1]) {
					dp[i] = dp[i - 1];
				}
				else {					
					dp[i] = dp[i - 1] + jyankenPoint(tmp_t[i], r, s, p);
					record_rsp[i] = jyankenMethod(tmp_t[i]);
				}

			}
			else { // i = 1
				dp[i] = jyankenPoint(tmp_t[i], r, s, p);
				record_rsp[i] = jyankenMethod(tmp_t[i]);
			}
			
		}

		ans += dp[num];
	
	}

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 896
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;
signed main()
{
    fastio;
    string s;
    cin>>s;
    if(s[s.size()-1]=='s')s+="es";
    else s+='s';
    cout<<s;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		dunk(1);
		return 0;
	}
	if ((h * w) % 2 == 0) {
		ll ans = h * w / 2;
		dunk(ans);
	}
	else {
		ll ans = (h * w + 1) / 2;
		dunk(ans);
	}
	return 0;
}


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

void rev_str(char *s){
    char tmp;

    tmp = s[0];
    s[0] = s[2];
    s[2] = tmp;
}

int main(void){
    char s[4];

    scanf("%s", s);

    if(strlen(s) == 2){
        printf("%s", s);
    }
    else{
        rev_str(s);
        printf("%s", s);
    }

    return 0;
}

Measured memory_bytes: 128
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
//#include "Header.h"
int main()
{
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;
}


Measured memory_bytes: 764
loopNum = gets
(1..loopNum.to_i).each do |i|
	arrstr = gets
	arr =  arrstr.split
	grpA, grpB = 0, 0
	(1..10).each do |j|
		if arr[j].to_i > grpA then
			grpA = arr[j].to_i
		elsif arr[j].to_i > grpB then
			grpB = arr[j].to_i
		elsif j == 10 then
			puts "YES"
		else
			puts "NO"
			break
		end
	end
end

Measured memory_bytes: 6104
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
using ll = long long;

ll solve(ll x, int *a, ll n){
  ll s = 0, t = 0;
  ll sum = 0;

  ll cnt = 0;
  while(true){
    while(t < n && sum <= x){
      sum += a[t++];
    }

    if(sum <= x) break;

    cnt += n-t+1;

    sum -= a[s++];
  }

  ll ans = (n+1) * n / 2 - cnt;

  return ans;
}

int main(){
  //ifstreac fin("in.txt");
  ll n, q; cin >> n >> q;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];

  for(int i=0; i<q; i++){
    ll x; cin >> x;
    cout << solve(x, a, n) << endl;
  }

  return 0;
}



Measured memory_bytes: 3480
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1, n-1):
    plist = [p[i-1], p[i], p[i+1]]
    plist.sort()
    plist.pop(2)
    plist.pop(0)
    if plist[0] == p[i]:
        cnt += 1
    else:
        continue
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int H, W;
int N;
int a[10010];
int ans[110][110];


void solve(){
	int k = 0;
	rep(i, 0, H){
		if(i%2 == 0){
			rep(j, 0, W){
				ans[i][j] = k+1;
				a[k]--;
				if(a[k] == 0) k++;
			}
		}
		else {
			repr(j, W, 0){
				ans[i][j] = k+1;
				a[k]--;
				if(a[k] == 0) k++;
			}
		}
	}
	rep(i, 0, H){
		rep(j, 0, W){
			cout << ans[i][j];
			if(j != W-1) cout << ' ';
		}
		cout << endl;
	}
}


signed main(){
	cin >> H >> W;
	cin >> N;
	rep(i, 0, N) cin >> a[i];

	solve();

	return 0;
}

Measured memory_bytes: 384
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x); 
        ll c=x/d;
      //  cout<<c<<endl;
        ll z=k-c;
        if(c>=k)
        {
            cout<<abs(x-k*d);
        }
        else
        {
            ll x1=x-c*d;
            ll x2=abs(x-(c+1)*d);
            if(x1<=x2)
            {
                if(z%2)
                {
                    cout<<x2;
                }
                else
                {
                    cout<<x1;
                }
            }
            else
            {
                if(z%2)
                {
                    cout<<x2;
                }
                else
                {
                    cout<<x1;
                }
            }
        }
    return 0;
}


Measured memory_bytes: 3648
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}


//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var s = next();
	if(s.indexOf("YAKI") == 0){
		myout("Yes");
	}else{
		myout("No");
	}
}


Measured memory_bytes: 30116
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000000
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
int getbit(int s, int i)
{ return (s >> i) & 1; }
int cntbit(int s)
{ return __builtin_popcountll(s); }
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{
    int n;
    cin>>n;
    ll a[n];
    map<ll,ll> mp,mp1;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
         cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
     mp[(i+1)-a[i]]++;
    }
    for(int i=0;i<n;i++)
    {
         mp[(i+1)-a[i]]--;
         if(mp[a[i]+(i+1)])
         {
              ans+=mp[a[i]+(i+1)];
         }
    }
    cout<<ans<<e;
}


Measured memory_bytes: 27936
import math

def C(n, k):
    return math.factorial(n) / math.factorial(k) / math.factorial(n - k)

n, p = map(int, raw_input().split())
a = [int(i) for i in raw_input().split()]
c0 = 0; c1 = 0
for i in a:
    if (i % 2 == 0):
        c0 += 1
    else:
        c1 += 1
        
ans = 0
for x in range(0, c0 + 1):
    for y in range(0, c1 + 1):
        if (y % 2 == p):
            ans += C(c0, x) * C(c1, y)
            
print ans

Measured memory_bytes: 2692
import java.util.*;

public class Main {
    public static final int CONSTRAINT = 1000000000;
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int maxNum = Math.max(x,y);
        int minNum = Math.min(x,y);
        
        GreatestCommonDivisor GCD = new GreatestCommonDivisor();
        System.out.println(GCD.getGCD(maxNum, minNum));
    }
}

class GreatestCommonDivisor{
    // int GCD;    //Greatest Common Divisor 
    public int getGCD(int maxNum, int minNum){
        if(minNum == 0){
            return maxNum;
        }else{
            return getGCD(minNum, (maxNum % minNum));
        }
    }
}


Measured memory_bytes: 26264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=110;
int a[N];
int main()
{
    int sum=0;
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
        a[i]+=a[i-1];
    }
    int minn=10000;
    for(int i=1;i<=n;i++)
    {
        minn=min(minn,abs(sum-a[i]-a[i]));
    }
    cout<<minn;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int n,pow[]={1,2,4,8,16,32,64};
int main()
{
	scanf("%d",&n);
	for(register int i=6; i>=0; --i)
	{
		if (pow[i]<=n)
		{
			printf("%d\n",pow[i]);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static long R { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            R = CR.GetLong();
            return 2 * Math.PI * R;
        }
    }
}


Measured memory_bytes: 18632
import java.util.Scanner;

/**
 * ABC043C
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        int[] a = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }

        int avg1 = 0;
        int avg2 = 0;
        avg1 = (int) Math.ceil((double) sum / N);
        avg2 = (int) Math.floor((double) sum / N);

        int cost1 = 0;
        int cost2 = 0;
        for (int i = 0; i < a.length; i++) {
            cost1 += (a[i] - avg1) * (a[i] - avg1);
            cost2 += (a[i] - avg2) * (a[i] - avg2);
        }

        System.out.println(Math.min(cost1, cost2));
        sc.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
using namespace std;

int main()
{
	string A,B,C;

	cin >> A >> B >> C ;
	cout << A[0] << B[1] << C[2] << endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io;

fn main() {
    let sin = io::stdin();

    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let _n = buf.trim().parse::<i32>();

    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let a: Vec<i64> = buf.split_whitespace()
        .map(|v| v.parse::<i64>().unwrap())
        .collect();
    let v_max = a.iter().max().unwrap();
    let v_min = a.iter().min().unwrap();
    let v_sum: i64 = a.iter().sum();

    println!("{} {} {}", v_min, v_max, v_sum);
}



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

const string YES = "Yes";
const string NO = "No";

void solve(long long N) {
    ll div = 0;
    rep(i, to_string(N).length()) { div += to_string(N)[i] - '0'; }
    if (N % div == 0) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3752
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int r; cin >> r;
  cout << r * r << endl;

  return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans,count=0,0
for i in range(n):
  a=list(map(int,input().split()))
  for i in range(m):
    ans+=a[i]*b[i]
  ans+=c
  if(ans>0):
    count+=1
  ans=0
print(count)

Measured memory_bytes: 3064
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

clear_list = [1] * N
start = 0
end = 0
ans_start = 0
ans_end = 0
    
for i in range(M):
    start, end  = [int(x) for x in stdin.readline().rstrip().split()]
    if ans_start == 0 or ans_start < start : 
        ans_start = start
    if ans_end == 0 or ans_end > end:
        ans_end = end

if ans_end - ans_start < 0:
    print(0)
else:
    print(ans_end - ans_start + 1 )


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

using namespace std;

int main() {
    int n,l;
    cin>>n>>l;
    string x[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    for(int i=0;i<n;i++){
        cout<<x[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
const long double Pi=acos(-1),e=2.718;
const int N=1e5+10,mod=3e7;
ll a[N],dp[N],n;
ll solve(int i){
    if(i>=n-1){
        if(i==n-1)return 0;
        else return oo;
    }
    ll &ret=dp[i];
    if(ret+1)return ret;
    ret = oo;
    if(i+1<=n)ret = min(ret,solve(i+1)+abs(a[i+1]-a[i]));
    if(i+2<=n)ret = min(ret,solve(i+2)+abs(a[i+2]-a[i]));
    return ret;
}
int main()
{
    memset(dp,-1,sizeof dp);
    FASTIO
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cout << solve(0) << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
map<pair<int,int> , int> memo;
int main() {
	int X,A,B;
	cin >> X >> A >> B;
	X -= A;
	int ans = 0;
	while(X >= 0){
		X -= B;
		if(X < 0){
			ans = X+B;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int k, n;
    cin >> k >> n;
    int shortest = k;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    for (int i=0; i<n; i++) {
        int dist;
        if (i==0) {
            dist = k - (a[0]+k - a[n-1]);
        }
        else {
            dist = k - (a[i] - a[i-1]);
        }
        if (dist < shortest) {
            shortest = dist;
        }
    }
    cout << shortest << endl;
	return 0;
}

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

int main(){
	int N;
	string S;
	cin >> N >> S;
	rep(i,S.size()) {
		S.at(i) += N;
		if (S.at(i) > 90) S.at(i) -= 26;
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define l first
#define r second
#define int long long

using namespace std;

const int maxn = 5e3 + 2, mod = 998244353, inf = 4e18;

signed a[maxn], b[201][maxn];
int t[maxn][maxn];
int x[maxn];
int n, m;

inline void inc(int r1, int c1, int r2, int c2, int vl) {
    r2 += 2; c2 += 2;
    ++r1; ++c1;
    t[r1][c1] += vl;
    t[r2][c2] += vl;
    t[r2][c1] -= vl;
    t[r1][c2] -= vl;
}

int stupid() {
    int ans = 0;
    for (int l = 0; l < n; l++) {
        for (int r = l; r < n; r++) {
            int can = 0;
            for (int j = 0; j < m; j++) {
                signed cm = 0;
                for (int k = l; k <= r; k++)
                    cm = max(cm, b[j][k]);
                can += cm;
            }
            ans = max(ans, can - (x[r] - x[l]));
        }
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    mt19937 gen(1323);
    uniform_int_distribution<int> dis(1, 10);
    for (int i = 0; i < n - 1; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++)
        x[i] = x[i - 1] + a[i - 1];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> b[j][i];
    for (int j = 0; j < m; j++) {
        stack<int> st;
        vector<int> sfm(n + 1);
        sfm[n] = n;
        for (int i = n - 1; i >= 0; i--) {
            while (!st.empty() && b[j][st.top()] < b[j][i])
                st.pop();
            sfm[i] = (st.empty() ? n - 1 : st.top() - 1);
            st.push(i);
        }
        while (!st.empty()) st.pop();
        for (int i = 0; i < n; i++) {
            while (!st.empty() && b[j][st.top()] <= b[j][i])
                st.pop();
            int l = (st.empty() ? 0 : st.top() + 1);
            int r = sfm[i];
            inc(l, i, i, r, b[j][i]);
            st.push(i);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            t[i][j] += t[i - 1][j] + t[i][j - 1] - t[i - 1][j - 1];
            if (i <= j) ans = max(ans, t[i][j] + x[i - 1] - x[j - 1]);
        }
    }
    cout << ans;// << " - " << stupid();
    return 0;
}


Measured memory_bytes: 199680
#include <bits/stdc++.h>
using namespace std;
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
typedef long long int ll;

int main(){
	ll n, k, a[100005], dp[100005];
	cin >> n >> k;
	ari;
	dp[n-1] = 0;
	// for( int i = 0 ; i < n ; i++ )
	// 	cout << a[i] << " ";
	// cout << endl;
	for( int i = n - 2 ; i > max(n - k - 2,(ll) -1) ; i-- ){
		dp[i] = 10000000000;
		for( int j = i + 1 ; j < n ; j++ ){
			dp[i] = min( dp[j] + llabs(a[i]-a[j]), dp[i]);
			// cout << min( dp[j] + llabs(a[i]-a[j]), dp[i]) << " ";
		}
		// cout << endl;
	}
	// for( int i = 0 ; i < n ; i++ )
	// 	cout << dp[i] << " ";
	// cout << endl;
	for( int i = n - k - 2 ; i > -1 ; i-- ){
		dp[i] = 10000000000;
		for( int j = i + 1 ; j < i + k + 1 ; j++ )
			dp[i] = min( dp[j] + llabs( a[i] - a[j]), dp[i]);
	}
	// for( int i = 0 ; i < n ; i++ )
	// 	cout << dp[i] << " ";
	// cout << endl;
	cout << dp[0] << endl;
	return(0);
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N;
    read(N);

    map<int,int> cnt[2];

    vector<int> a(N);
    rep(i, N) {
        read(a[i]);
        cnt[i & 1][a[i]] += 1;
    }

    vector<pii> x, y;
    i64 xsum = 0;
    i64 ysum = 0;
    for (auto e : cnt[0])  {
        x.emplace_back(e.second, e.first);
        xsum += e.second;
    }
    for (auto e : cnt[1]) {
        y.emplace_back(e.second, e.first);
        ysum += e.second;
    }

    sort(all(x), greater<>());
    sort(all(y), greater<>());

    x.emplace_back(0, -1);
    y.emplace_back(0, -1);

    i64 ans = LINF;
    rep(i, 2) rep(j, 2) {
        const i64 xcnt = x[i].first;
        const i64 xval = x[i].second;
        const i64 ycnt = y[j].first;
        const i64 yval = y[j].second;

        if (xval == yval) continue;
        chmin(ans, (xsum - xcnt) + (ysum - ycnt));
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 7672
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> v[N];
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll sm=0;
    while(1)
    {
        if(h1==h2)
        {
            if(m2>=m1)
            {
                sm+=m2-m1;
            }
            else
            {
                sm-=(m1-m2);
            }
            break;
        }
        h1=(h1+1)%24;
        sm+=60;
    }
    cout<<sm-k;
}

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

void Main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p, q, r;
    int tmp;
    for(int i=0; i<a; ++i){
        cin >> tmp;
        p.push_back(tmp);
    }
    for(int i=0; i<b; ++i){
        cin >> tmp;
        q.push_back(tmp);
    }
    for(int i=0; i<c; ++i){
        cin >> tmp;
        r.push_back(tmp);
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());

    if(p.size() > x){
        p.resize(x);
    }
   if(q.size() > y){
        q.resize(y);
    }

    vector<int> pq;
    for(auto i: p){
        pq.push_back(i);
    }
    for(auto i: q){
        pq.push_back(i);
    }
    sort(pq.begin(), pq.end(), greater<int>());

    vector<long> apq(1, 0);
    for(auto i: pq){
        apq.push_back(apq.back()+i);
    }
    vector<long> ar(1, 0);
    for(auto i: r){
        ar.push_back(ar.back()+i);
    }

    long sum = 0;
    for (int i = max<int>(0, x+y-r.size()); i <= pq.size(); i++)
    {
        long tmp = apq[i] + ar[x+y-i];
        if(sum < tmp){
            sum = tmp;
        }
    }
    
    cout << sum << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int N;
    cin >> N;
    vector<int> w(N);
    long long h[100010];


    // 無限大の値
    //const long long INF = 1LL << 60;

    for (int i = 0; i < N; ++i) cin >> h[i];

    // DP テーブル
    long long dp[100010];

    // DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    for (int i = 1; i < N; ++i) {
        changeMinimum(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) {
            changeMinimum(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
            changeMinimum(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }

    cout << dp[N - 1] << endl;

}

Measured memory_bytes: 2176
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())


def func(n):
    x = 0
    while(n > 0):
        x += n % 10
        n //= 10
    return x


a = 10**5
for i in range(1, n):
    j = n-i
    tmp = func(i)+func(j)
    a = min(tmp, a)
print(a)


Measured memory_bytes: 41068
import sys
def main():
    n,m = map(int, input().split())

    if n >= m:
        print(0)
        sys.exit()

    x = sorted(list(map(int, input().split())))
    y = sorted([x[i]-x[i-1] for i in range(m-1,0,-1)])[::-1]
    s = sum(y)

    print(s-sum(y[:n-1]))
    
if __name__=="__main__":
    main()

Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;

int tos(int h, int m, int s){
	return h * 3600 + m * 60 + s;
}

bool cmp(pii p1, pii p2){
	if(p1.se != p2.se) return p1.se < p2.se;
	return p1.fi < p2.fi;
}

int main(){
	int n;
	int h, m, s;
	pii p;
	while(cin>>n && n > 0){
		vector<pii> v;
		for(int i = 0; i < n; i++){
			scanf("%d:%d:%d", &h, &m, &s);
			p.se = tos(h, m, s);
			scanf("%d:%d:%d", &h, &m, &s);
			p.fi = tos(h, m, s);
			v.pb(p);
		}
		sort(all(v), cmp);
		vi u;
		u.pb(v[0].fi);
		for(int i = 1; i < v.size(); i++){
			for(int j = 0; j < u.size(); j++){
				if(u[j] <= v[i].se){
					u[j] = v[i].fi;
					break;
				}
				if(j == u.size() - 1) {
					u.pb(v[i].fi);
					break;
				}
			}
			sort(all(u));
		}
		cout<<u.size()<<endl;
	}
}

Measured memory_bytes: 1384
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

bool G[10][10];

int main() {
    int N, M; cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a][b] = G[b][a] = true;
    }

    vector<int> ord(N);
    for (int i = 0; i < N; ++i) ord[i] = i;

    int res = 0;
    do {
        if (ord[0] != 0) break;

        bool ok = true;
        for (int i = 0; i + 1 < N; ++i) {
            if (!G[ord[i]][ord[i+1]]) ok = false;
        }
        if (ok) ++res;
    } while (next_permutation(ord.begin(), ord.end()));

    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<vector<pair<int,int>>> a(n);
  for (auto &v : a) {
    int x; cin >> x;
    v.resize(x);
    for (auto &pr : v) cin >> pr.first >> pr.second, --pr.first;
  }
  int ans = 0;
  for (int i = 1; i < (1 << n); ++i) {
    int ok = 1;
    for (int j = 0; j < n; ++j) if (i >> j & 1) {
      for (auto &pr : a[j]) {
        ok &= (i >> pr.first & 1) == pr.second;
      }
    }
    if (ok) uax(ans, __builtin_popcount(i));
  }
  kek(ans);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

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

const long long INF = 1LL << 60;

long long h[100001];
long long dp[100001];

using namespace std;

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

  for(int i = 0; i < N; i++) cin >> h[i];

  for(int i = 0; i < 100001; i++) dp[i] = INF;

  dp[0] = 0;

  for(int i = 0; i < N; i++){
    for(int j = 1; j <= K; j++){
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }

  cout << dp[N - 1] << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
int main(){
    vector<int> A(3);
    REP(i, 3) cin >> A[i];
    sort(A.begin(), A.end());
    cout << (A[1]-A[0]) + (A[2]-A[1]) << endl;
    return 0;
}

Measured memory_bytes: 256