akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = 1000000007;
ll powmod(ll n, ll k, ll m) {
  if (k == 0) return 1;
  ll t = powmod(n, k / 2, m);
  t = (t * t) % m;
  if (k % 2 == 1)
    t = (t * n) % m;
  return t;
}
int main() {
  int n;
  cin >> n;
  //vector<ll> a(n), b(n);
  map<pair<ll, ll>, int> vct;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    if (g != 0) {
      a /= g;
      b /= g;
    }
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    if (a == 0 || b == 0) {
      a = abs(a);
      b = abs(b);
    }
    vct[make_pair(a, b)]++;
  }
  ll prod = 1;
  ll zerov = 0;
  auto end = vct.end();
  for (auto it = vct.begin(); it != end; ++it) {
    if (it->second == 0) continue;
    pair v = it->first;
    if (v.first == 0 && v.second == 0) {
      zerov += it->second;
      it->second = 0;
      continue;
    }
    ll sum = (powmod(2, it->second, mod)) % mod;
    ll tmp = v.first;
    v.first = v.second;
    v.second = -tmp;
    if (v.first < 0) {
      v.first *= -1;
      v.second *= -1;
    }
    if (v.first == 0 || v.second == 0) {
      v.first = abs(v.first);
      v.second = abs(v.second);
    }
    auto p = vct.find(v);
    if (p != end) {
      sum = (sum + (powmod(2, p->second, mod) - 1) % mod) % mod;
      p->second = 0;
    }
    it->second = 0;
    prod = (prod * sum) % mod;
  }
  prod--;
  if (prod < 0) prod += mod;
  prod = (prod + zerov) % mod;
  cout << prod << endl;
  return 0;
}

Measured memory_bytes: 16136
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a%b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}


int main() {
    int n;
    cin >> n;
    vector<long long> t(n);
    rep(i, 0, n) {
        cin >> t[i];
    }

    long long ans = 1;
    rep(i, 0, n) {
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
function f(n,m,a)
    all=0
    for i=1:n
        all += a[i]
    end
    h=all/(4*m)
    for i=1:n
        if a[i] >= h
            m -= 1
            if m == 0
                print("Yes")
                exit()
            end
        end
    end
    print("No")
end
        
#n,m=parse.(Int,split(readline()))
#a=parse.(Int,split(readline()))
n,m=[parse(Int,i) for i in split(readline())]
a=[parse(Int,i) for i in split(readline())]
f(n,m,a)


Measured memory_bytes: 163600
#include<cstdio>
#include<cmath>
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		long long a,b,c;
		scanf("%lld%lld",&a,&b);
		c=int(sqrt(a*b));
		if(c*(c+1)<a*b)
			printf("%lld\n",2*c-1);
		else if(c*c==a*b){
			if(a==b)
				printf("%lld\n",2*c-2);
			else
				printf("%lld\n",2*c-3);
		}
		else
			printf("%lld\n",2*c-2);
	}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

bool foo() {
    int64_t n;
    cin >> n;
    vector<int> A(n), a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    vector<pair<int, int>> e((n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        e[i * 2 + 0] = { a[i], b[i] };
        e[i * 2 + 1] = { b[i], a[i] };
    }
    sort(e.begin(), e.end());

    bool r = true;

    std::function<int(int, int)> f = [&](int i, int parent) {
        auto p0 = lower_bound(e.begin(), e.end(), pair<int, int>{ i, 0 });
        auto p1 = lower_bound(e.begin(), e.end(), pair<int, int>{ i + 1, 0 });
        if (parent >= 0 && p1 - p0 == 1) {
            return A[i];
        }
        int64_t s = 0;
        int m = 0;
        for (auto it = p0; it != p1; it++) {
            int j = it->second;
            if (j == parent) continue;
            int t = f(j, i);
            s += t;
            m = max(m, t);
        }
        int64_t g = A[i] * 2 - s;
        if (parent < 0) {
            if (p1 - p0 == 1) {
                if (s != A[i]) r = false;
            } else {
                if (g != 0) r = false;
                if (0 < m - (s - m)) r = false;
            }
            return 0;
        }
        if (g < 0 || g < m - (s - m) || g > A[i]) r = false;
        return (int)g;
    };
    f(0, -1);
    return r;
}

int main() {
    cout << (foo() ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 12288
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

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

ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g) * b;
}

int main(){
	int N;
    cin >> N;
    int A[N];
    ll result = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        result +=A[i];
    }

    result -= N;

    cout << result << endl;

}


Measured memory_bytes: 256
def f(x):
    a,b=0,0
    for e in x:
        if e>a: a=e
        elif e>b: b=e
        else: return 0
    return 1

n=input()
for i in range(n):
    D = map(int, raw_input().split())
    print ["NO","YES"][f(D)]

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

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

int main(){
    int a,b,c,d,ans=0;
    cin>>a>>b>>c>>d;
    vector<int>t(10000);
    t[a]++;
    t[b]--;
    t[c]++;
    t[d]--;
    for(int i=0;i<1000;i++){
        t[i+1]+=t[i];
    }
    for(int i=0;i<1000;i++){
        if(t[i]==2){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    int n, m;
    cin>>n>>m;
    map<int, vector<pair<int, int> > > mp;
    rep(i, m){
        int a, b;
        cin>>a>>b;
        --a;//県の名前を0indexedにする
        mp[a].push_back(pair<int,int>(b, i));//年，idxの順に格納している
    }
    rep(i, n){
        sort(mp[i].begin(), mp[i].end());
        //for(auto p : mp[i]) cout<<p.first<<", "<<p.second<<endl;
    }
    vector<string> v1(m);
    vector<string> v2(m);
    rep(i, n){
        int num=1;
        for(auto p : mp[i]){
            /*県のidxを格納*/
            string str1=to_string(i+1);
            reverse(str1.begin(), str1.end());
            while((int)(str1.length())<6) str1.push_back('0');
            reverse(str1.begin(), str1.end());
            v1[p.second]=str1;
            /*何番目にできたかを格納している*/
            string str2=to_string(num);
            reverse(str2.begin(), str2.end());
            while((int)(str2.length())<6) str2.push_back('0');
            reverse(str2.begin(), str2.end());
            v2[p.second]=str2;
            num++;
        }
    }
    rep(i, m){
        cout<<v1[i]<<v2[i]<<endl;
    }
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<bool> a(n);
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		a[i] = x == y;
	}

	bool ans = false;
	for (int i = 0; i + 2 < n; i++)
		if (a[i] && a[i + 1] && a[i + 2]) ans = true;

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin >> n;
  int sum=0;
  int i=0;
  while(n>=sum){
    sum+=++i;
  }
  if(sum == n){
    for(int j=1; j<=i;j++){
      cout << j << endl;
    }
  }else{
    for(int j=1; j<=i; j++){
      if(j == sum-n){
        continue;
      }
      cout << j << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] H = new int[N];
		boolean ok = true;
		for(int i = 0; i < N; i++)
			H[i] = sc.nextInt();
		for(int i = 1; i < N; i++) {
			if(H[i] > H[i-1])
				H[i]--;
			if(H[i] < H[i-1])
				ok = false;
		}
		System.out.println(ok ? "Yes" : "No");

	}

}


Measured memory_bytes: 48624
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

class UnionFind {
private:
	int n, s;
	vector<int> t;
	vector<vector<int>> v;
public:
	UnionFind(int arg_n = 0) { init(arg_n); }
	void init(int arg_n) {
		n = s = arg_n;
		t.clear();
		v.clear();
		inc(i, n) { t.PB(i); v.PB({ i }); }
	}
	int get_n() { return n; }
	int size() { return s; }
	int id(int x) { return t.at(x); }
	const vector<vector<int>> & get_v() const { return v; }
	bool unite(int x, int y) {
		x = id(x);
		y = id(y);
		if(x == y) { return false; }
		if(v[x].size() < v[y].size()) { swap(x, y); }
		for(auto & e: v[y]) { v[x].PB(e); t[e] = x; }
		v[y].clear();
		s--;
		return true;
	}
	bool same(int x, int y) { return (id(x) == id(y)); }
	const vector<int> & operator[](int x) { return v[id(x)]; }
	friend ostream & operator<<(ostream & os, const UnionFind & uf) {
		inc(i, uf.n) { os << i << ": "; for(auto & e: uf.v[i]) { os << e << " "; } os << "\n"; }
		return os;
	}
};

// ---- ----

int n, m;

int main() {
	cin >> n >> m;
	UnionFind uf(n);
	inc(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		uf.unite(x, y);
	}
	
	cout << SI(uf) << endl;
	
	return 0;
}


Measured memory_bytes: 10032
def comb(n, x)
  if x != 2
    result = 0
    for i in ((n - (x - 1) * 9) < 0 ? 0: (n - (x - 1) * 9))..(n > 9 ? 9: n)
      result += comb(n - i, x - 1)
    end
    return result
  else
    return (n < 9 ? (n + 1): (19 - n))
  end
end
while (n = gets)
  puts comb(n.to_i, 4)
end

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

using lli=long long int;
int main(){
  int N;
  std::cin >> N;

  std::vector<lli> A_arr(N);
  for(int i = 0; i < N; i++) std::cin >> A_arr[i];

  int sign = 1;
  lli min_A = std::pow(10,10);
  lli sum_A = 0;
  for(int i = 0; i < N; i++){
    if(A_arr[i] < 0) sign *= -1;
    min_A = std::min(min_A, std::abs(A_arr[i]));
    sum_A += std::abs(A_arr[i]);
  }

  if(sign == 1) std::cout << sum_A << std::endl;
  else std::cout << sum_A-2*min_A << std::endl;

  return 0;
}



Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(200000)

n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
q,k = map(int,input().split())
k -= 1
#kからの距離
tree = [[] for _ in range(n)]
for a,b,c in l:
    a -= 1
    b -= 1
    tree[a].append([b,c])
    tree[b].append([a,c])

bit = [0 for _ in range(n)]
depth = [0 for _ in range(n)]
def dfs(v,d=0):
    bit[v] = 1
    depth[v] = d
    for j,k in tree[v]:
        if bit[j]==0:
            dfs(j,d+k)
dfs(k)

for _ in range(q):
    x,y = map(int,input().split())
    x-= 1
    y-= 1
    print(depth[x] + depth[y])


Measured memory_bytes: 183224
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

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

    int n, a[200001];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n % 2 == 0) {
        for (int i = n - 1; i >= 1; i-=2) cout << a[i] << ' ';
        for (int i = 0; i <= n - 2; i+=2) cout << a[i] << ' ';
    }
    else {
        for (int i = n - 1; i >= 0; i -= 2) cout << a[i] << ' ';
        for (int i = 1; i <= n - 1; i += 2) cout << a[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int n,c[5][5],a[5]={},b[5]={},max=0,diff[5][5]={},count=0;
	REP(i,3)REP(j,3){
		cin>>c[i][j];
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<2;j++){
			diff[i][j]=c[i][j+1]-c[i][j];
			DEB(diff[i][j])END
		}
	}
	for(int i=0;i<2;i++){
		if(diff[i][0]==diff[i+1][0]&&diff[i][1]==diff[i+1][1]){
			count++;
		}
	}
	if(count==2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}
//diff[3][2]

Measured memory_bytes: 256
a = []
for i in range(10):
    a.append(int(input()))

for i in range(3):
    maximum = 0
    index = i
    for j in range(i, 10):
        if a[j] > maximum:
            maximum = a[j]
            index = j
    temp = a[i]
    a[i] = a[index]
    a[index] = temp
    print(maximum)



Measured memory_bytes: 5600
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string S;
	cin >> S;
	int L = S.length();
	for (int i = 0; i + 1 < L; ++i) {
		if (S[i] == S[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}


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

using namespace std;

vector<int> preprocess(string S){
    int n = S.size();
    vector<int> v(n + 1, 0);
    for (int i = 0; i != n; ++i){
        v[i + 1] = v[i] + ((S[i] == 'A') ? 1 : 2);
    }
    return v;
}


inline bool can_transform(int a, int b, int c, int d, const vector<int> &vS, const vector<int> &vT){
    return (vS[b] - vS[a - 1] - vT[d] + vT[c - 1]) % 3 == 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    auto vS = preprocess(S);
    auto vT = preprocess(T);
    int q;
    cin >> q;
    while (q--){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << (can_transform(a, b, c, d, vS, vT) ? "YES\n" : "NO\n");
    }
    return 0;
}

Measured memory_bytes: 1744
using System;
using System.Collections.Generic;

class Prog{
    static void Main(string[] args){
        var a = Console.ReadLine();
        var list = new List<string>();
        list.Add("SUN");
        list.Add("MON");
        list.Add("TUE");
        list.Add("WED");
        list.Add("THU");
        list.Add("FRI");
        list.Add("SAT");
        for(int i = 0;i < 7;i++){
            if(list[i]　== a ){
                Console.WriteLine(7-i);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#define A 1
#define G 2
#define C 3
#define T 4

typedef long long ll;

const int MOD = 1e9 + 7;
const int N_MAX = 105;
const int AGCT[] = {A, G, C, T};

using namespace std;

ll memo[N_MAX][5][5][5][5] = {0};
int N;

ll dfs(int i, int c1, int c2, int c3, int c4) {
    if (c2 == A && c3 == G && c4 == C) return 0;
    if (c2 == A && c3 == C && c4 == G) return 0;
    if (c2 == G && c3 == A && c4 == C) return 0;
    if (c1 == A && c3 == G && c4 == C) return 0;
    if (c1 == A && c2 == G && c4 == C) return 0;
    if (i == N) return 1;

    if (memo[i][c1][c2][c3][c4] > 0) {
        return memo[i][c1][c2][c3][c4];
    }

    for (auto c : AGCT) {
        memo[i][c1][c2][c3][c4] =
            (memo[i][c1][c2][c3][c4] + dfs(i + 1, c2, c3, c4, c)) % MOD;
    }

    return memo[i][c1][c2][c3][c4];
}

int main() {
    cin >> N;

    cout << dfs(0, T, T, T, T) << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll p[a],q[b],r[c];
	for(i=0;i<a;i++)
	cin>>p[i];
	for(i=0;i<b;i++)
	cin>>q[i];
	for(i=0;i<c;i++)
	cin>>r[i];
	sort(p,p+a,greater<>());
	sort(q,q+b,greater<>());
	sort(r,r+c,greater<>());
	ll ans=0;
		vector<ll> v;
	for(i=0;i<x;i++)
	{
	ans+=p[i];
	v.pb(p[i]);
    }
	for(i=0;i<y;i++)
	{
	ans+=q[i];
	v.pb(q[i]);
    }
    sort(v.begin(),v.end());
    ll k=0;
    for(i=0;i<c;i++)
    {
		if(r[i]>v[k])
		{
			ans-=v[k];
			ans+=r[i];
			k++;
		}
	}
	cout<<ans;
cout<<"\n"; 
 } 
}


Measured memory_bytes: 4852
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())



int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> board(h);
	cin >> board;

	vector<vector<int>> dp(h, vector<int>(w, w*h*2));
	dp[h - 1][w - 1] = 0;
	for (int i = h - 1; i >= 0; i--)
	{
		for (int j = w - 1; j >= 0; j--)
		{
			if (i + 1 < h)
				dp[i][j] = min(dp[i][j], dp[i + 1][j] + (board[i][j] != board[i + 1][j]));
			if (j + 1 < w)
				dp[i][j] = min(dp[i][j], dp[i][j+1] + (board[i][j] != board[i][j+1]));
		}
	}
	int ans = 0;
	int x = dp[0][0] + 1;
	if (board[0][0] == '#')
		ans = x - (x / 2);
	else
		ans += x / 2;
	cout << ans;
//	cout << min(dp[0][0]/2,dp[0][0] - (dp[0][0] / 2));
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()
#include <string.h>         // memcpy()

#define MAX_N 100000
#define SENTINEL 2000000000
#define swap(x, y) { card_t t = x; x = y; y = t; }

typedef struct card_tbl
{
	char mark;
	int val;
} card_t;

card_t l[MAX_N / 2 + 2], r[MAX_N / 2 + 2];

int
partition(card_t a[], int p, int r)
{
	int j;

	int x = a[r].val;
	int i = p - 1;
	for (j = p; j < r; ++j)
	{
		if (a[j].val <= x)
		{
			i++;
			swap(a[i], a[j]);
		}
	}

	swap(a[i + 1], a[r]);
	return i + 1;
}

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

void
merge(card_t a[], int left, int mid, int right)
{
	int k;

	const int n1 = mid - left;
	const int n2 = right - mid;
	memcpy(l, &a[left], sizeof(card_t) * n1);
	memcpy(r, &a[mid], sizeof(card_t) * n2);
	l[n1].val = SENTINEL, r[n2].val = SENTINEL;

	int i = 0, j = 0;
	for (k = left; k < right; ++k)
	{
		if (l[i].val <= r[j].val)
			a[k] = l[i++];
		else
			a[k] = r[j++];
	}
}

void
mergesort(card_t a[], int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergesort(a, left, mid);
		mergesort(a, mid, right);
		merge(a, left, mid, right);
	}	
}

int
main(int argc, char** argv)
{
	card_t a[MAX_N];
	card_t b[MAX_N];
	int n, i;

	scanf("%d\n", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%c %d\n", &a[i].mark, &a[i].val);
		b[i].mark = a[i].mark;
		b[i].val = a[i].val;
	}

	quicksort(a, 0, n - 1);
	mergesort(b, 0, n);

	for (i = 0; i < n; ++i)
	{
		if (a[i].mark != b[i].mark)
			break;
	}

	if (i >= n)
		printf("Stable\n");
	else
		printf("Not stable\n");

	for (i = 0; i < n; ++i)
		printf("%c %d\n", a[i].mark, a[i].val);

	return 0;
}

Measured memory_bytes: 2968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;
    int n = 0;
    int tmp = 0;
    rep(i,s.size()){
        if(s[i]!='A'&&s[i]!='C'&&s[i]!='G'&&s[i]!='T') tmp=0;
        else ++tmp;
        n = max(n,tmp);
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    q = q << 2;
    h = h << 1;
    if (d < (q << 1) && d < 2 * h && d < 2 * s) {
        if (n & 1) {
            cout << (n >> 1) * d + min(min(q, h), s);
        }
        else {
            cout << (n >> 1) * d;
        }
    }
    else if (s < h && s < q) {
        cout << s * n;
    }
    else if (h < q) {
        cout << h * n;
    }
    else {
        cout << q * n;
    }
}


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

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

    sort(l.begin(), l.end());

    int ans = 0;
    for(auto i = l.rbegin(); i < l.rbegin() + k; i++){
        ans += *i;
    }

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

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

int count,i;

void selectionSort(int x[], const int m)
{
  int minj,j,tmp;
  
  for(i=0;i<m;i++) {
    minj = i;
    for(j=i;j<m;j++) {
      if(x[j] < x[minj]) {
	    minj = j;
      }
    }
    if(minj != i) {
        tmp = x[i];
        x[i] = x[minj];
        x[minj] = tmp;
        count++;
    }
  }
}

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

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

  selectionSort(a,n);

  for(i=0;i<n;i++) {
    printf("%d",a[i]);
    if(i < n-1) {
      putchar(' ');
    }
    else {
        printf("\n");
    }
  }
  printf("%d\n",count);

  return(0);
}


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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int e = c/b + (c%b != 0);
	int f = a/d + (a%d != 0);
	if (e <= f)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3620
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

int n;
vector<pi> g[100005];

int size[100005];

lint res;

const int INF=5e8;
int mn=INF;
void rec(int v,int p){
  size[v]=1;
  for(auto e:g[v]){
    if(e.fr!=p){
      rec(e.fr,v);
      size[v]+=size[e.fr];
    }
  }
}
int root=-1;
void rec2(int v,int p){

  int mxch=0;
  for(auto e:g[v]){
    if(e.fr!=p){
      rec2(e.fr,v);
      int a=size[e.fr];
      int b=n-a;
      if(a==b){
        mn=e.sc;
      }
      res+=e.sc*(lint)min(a,b)*2;
      chmax(mxch,a);
    }
  }
  chmax(mxch,n-size[v]);
  if(mxch<=n/2 && mn==INF){
    root=v;
    for(auto e:g[v]){
      chmin(mn,e.sc);
    }
  }
}
int main(){
#ifdef LOCAL_REDIR
  freopen("/home/hog/Dropbox/pg/working/in.txt","r",stdin);
#endif
  cin>>n;
  REP(i,n-1){
    int a,b,c;scanf("%d%d%d",&a,&b,&c);--a;--b;
    g[a].pb({b,c});
    g[b].pb({a,c});
  }

  rec(0,-1);
  rec2(0,-1);
  res-=mn;
  cout<<res<<endl;

  return 0;
}






Measured memory_bytes: 14080
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    String[] sn = n.split("",0);
    int sum = 0;
    for(int i = 0;i < sn.length;i++){
      sum += Integer.parseInt(sn[i]);
    }
    int ans = Integer.parseInt(n) % sum;
    if(ans == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B,C,D,E;
  cin>>A>>B>>C>>D>>E;
  
  int A_=A;
  int B_=B;
  int C_=C;
  int D_=D;
  int E_=E;
  
  while(true){
    if(A_%10==0){
      break;
    }
    A_++;
  }
  while(true){
    if(B_%10==0){
      break;
    }
    B_++;
  }
  while(true){
    if(C_%10==0){
      break;
    }
    C_++;
  }
  while(true){
    if(D_%10==0){
      break;
    }
    D_++;
  }
  while(true){
    if(E_%10==0){
      break;
    }
    E_++;
  }
  
  int x=max(A_-A,B_-B);
  int y=max(C_-C,D_-D);
  int z=max(x,y);
  int w=max(z,E_-E);
  
  cout<<A_+B_+C_+D_+E_-w<<endl;
}

Measured memory_bytes: 3428
#include<cstdio>

int main() {
	int n1, n2, t, cnt = 0;
	scanf("%d", &n1);
	int A[n1];
	for (int i = 0; i < n1; i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &n2);
	for (int i = 0; i < n2; i++) {
		scanf("%d", &t);
		for (int j = 0; j < n1; j++) {
			if (t == A[j]) {
                            cnt += 1;
                            break;
                        }
		}
	}
	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  bool ok = false;
  char c;
  
 for (c = 'a' ; c <= 'z'; c++ ) {
   ok = false;
  for (int i = 0; i < S.size(); i++) {
    if(S.at(i) == c){
      ok = true;
      break;
    }
  }
    if(ok == false){
    break;
    }
 }
  
  if(ok == false){
  	cout << c << endl;
  }else {
    cout << "None" << endl;
  }

}

Measured memory_bytes: 3728
import java.util.*;
import java.lang.Math;


public class Main
{
	
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int j,flag;
		double n,k;
		n=sc.nextDouble();
		k=sc.nextDouble();
		double i = (Math.log(n)/Math.log(k));
		j=(int)(Math.floor(i)+1);
		System.out.println(j);
		
		
		
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	if ((s[0] == s[1] && s[0] == s[2]) || (s[3] == s[1] && s[3] == s[2]))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
  int count=0;
  int N;
  cin>>N;
  vector<int>P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  for(int i=1;i<N-1;i++){
  if(P[i-1]>P[i] ^ P[i+1]>P[i]){
  count++;
  }
  }
  cout<<count;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;

const int M=1e5+5;
int n,m;
struct Node
{
	int a,b;
	void read()
	{
		scanf("%d%d",&a,&b);
		a=m-a+1;
	}
	bool operator<(const Node &B) const
	{
		return a<B.a;
	}
}node[M];

priority_queue<int,vector<int>,greater<int> > qu;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		node[i].read();
	sort(node,node+n);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		qu.push(node[i].b);
		ans+=node[i].b;
		if((int)qu.size()>node[i].a)
		{
			ans-=qu.top();
			qu.pop();
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1660
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
// const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

const int maxn = 1e6 + 100;
const ll INF = 999999999999;
ll dis[maxn][3];
bool vis[maxn][3];
vector<int> G[maxn];
struct node {
    int id;
    int dis;
};
int n, m, S, T;
queue<node> q;

void dij(int S) {
    for (int i = 1; i <= n + 100; ++i) {
        for (int j = 0; j < 3; ++j) {
            dis[i][j] = INF;
            vis[i][j] = 0;
        }
    }
    dis[S][0] = 0;
    q.push({S, 0});
    while (!q.empty()) {
        node rt = q.front();
        q.pop();
        int u = rt.id;
        int L = rt.dis;
        if (vis[u][L]) continue;
        for (auto v : G[u]) {
            int nowL = (L + 1) % 3;
            if (dis[v][nowL] > dis[u][L] + 1) {
                dis[v][nowL] = dis[u][L] + 1;
                q.push({v, nowL});
            }
        }
    }
}

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    n = read(), m = read();
    int u, v;
    for (int i = 1; i <= m; ++i) {
        u = read(), v = read();
        G[u].push_back(v);
    }
    S = read(), T = read();
    dij(S);
    if (dis[T][0] == INF) puts("-1");
    else cout << dis[T][0] / 3 << endl;
    return 0;

    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 34048
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;
int main(){
	vector<int> K,W;
	int o;
	for(int i=0;i<10;i++){
		cin>>o;
		K.push_back(o);
	}
	for(int i=0;i<10;i++){
		cin>>o;
		W.push_back(o);
	}
	
	sort(K.begin(),K.end());
	sort(W.begin(),W.end());
	cout<<K[7]+K[8]+K[9]<<" "<<W[7]+W[8]+W[9]<<endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010

bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}

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

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    ll n,c=0;
    cin >> n;
    ll x[n],y[n];
    for (ll i=0;i<n;i++){
        cin >> x[i];
        y[i]=x[i];
    }
    sort(x,x+n);
    for (ll i=0;i<n;i++){
        if (x[i]!=y[i])c++;
    }
    if (c==2 || c==0)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
// Written By Mahtab Tanim
#include<bits/stdc++.h>
using namespace std;
#define MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
#define End return 0
#define ll long long int
#define mp make_pair
#define pb push_back
#define ull unsigned long long int
#define pi acos(-1)
#define forn(i,a,b) for (int i=a;i<=b;i++)
int main()
{
    int w;
    cin>>w;
    string s;
    map<string,int> x;
    for(int i=0;i<w;i++)
    {
        cin>>s;
        x[s]++;
    }
    int count= x.size();
    cout<<count<<endl;
End;
}


Measured memory_bytes: 19116
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  ll n;
  scanf("%lld",&n);

  char name[100];
  int count = 0;
  int tmp;
  while(n > 0){
    tmp =  n % 26;
    if(tmp == 0) tmp = 26;
    name[count] = 'a' + tmp -1;
    ++count;
    if(n % 26 == 0 && n / 26 == 1) break;
    n -= 1;
    n /= 26;
  }

  for(int i = count-1; i >= 0; --i){
    printf("%c",name[i]);
  }

  return 0;
}


Measured memory_bytes: 1660
#include <iostream>

using namespace std;

int main() {
    int x, y, f;
    string ans = "No";
  	cin >> x >> y;
	for (int i = 0; i < x+1; i++){
		f = 4*i + 2*(x-i);
      	if (f == y) ans = "Yes"; 
    }
    cout << ans << endl;
  return 0;
}

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

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

const long long INF=1LL<<60;

long long h[100010];
long long dp[100010];


int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;++i) cin>>h[i];

    for(int i=0;i<100010;++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]<<"\n";    
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>

using namespace std;

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

  int n = (int)s.size();
  map<char, vector<int> > m;

  for (int i = 0; i < n; ++i) m[s[i]].push_back(i);
  if (m.size() == 1) {
    puts("0");
    return 0;
  }
  int ans = (int)1e9;

  for (auto c: m) {
    int prev = 0;
    int ma = c.second[0];
    for (auto e: c.second) {
      ma = max(e - prev - 1, ma);
      prev = e;
    }
    ma = max(n - 1 - c.second.back(), ma);
    ans = min(ans, ma);
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll mod = 7 * 17 * (1 << 23) + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d >> s, a--, b--, c--, d--;
	for (int i = a + 1; i <= c; i++) {
		if ((s[i] & s[i - 1]) == '#')
			return cout << "No", 0;
	}
	for (int i = b + 1; i <= d; i++) {
		if ((s[i] & s[i - 1]) == '#')
			return cout << "No", 0;
	}
	if (c < d) {
		return cout << "Yes", 0;
	}
	for (int i = max(1, b); i+1<=n && i <= d; i++) {
		if ((s[i] == s[i - 1] && s[i] == s[i + 1]) && s[i] == '.')
			return cout << "Yes", 0;
	}
	cout << "No";

	return 0;
}


Measured memory_bytes: 592
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	a, _, _, _, e, k := readInt(), readInt(), readInt(), readInt(), readInt(), readInt()
	if e-a > k {
		fmt.Println(":(")
	} else {
		fmt.Println("Yay!")
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
//07-4 ????????????????????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;

    int card[200] = {};
    for(int i=0; i<200; i++){
        card[i] = i+1;
    }

    for(int i=0; i<m; i++){
        int k;
        cin >> k;
        if(k==0){//??????????????£?????????
            int front[100] = {};
            int back[100] = {};
            for(int l=0; l<n; l++){
                front[l] = card[l];
            }
            for(int l=0; l<n; l++){
                back[l] = card[n+l];
            }
            
            for(int l=0; l<n; l++){
                card[l*2] = front[l];
                card[l*2+1] = back[l];
            }
        }
        else{//?????????
            int front[200] = {};
            int back[200] = {};
            for(int l=0; l<k; l++){
                front[l] = card[l];
            }
            for(int l=0; l<2*n-k; l++){
                card[l] = card[k+l];
            }

            for(int l=0; l<k; l++){
                card[2*n-k+l] = front[l];
            }
        }
    }

    for(int i=0; i<2*n; i++){
        cout << card[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int test,x;
int vis[15],turn,L,R,A,B;
map <int,int> a,b;
int main(){
	ios_base::sync_with_stdio(0);
	cin>>test;
	while(test--){
		memset(vis,0,sizeof(vis));
		a.clear();
		b.clear();
		for(int i=1;i<=6;i++){
			cin>>x;
			x--;
			vis[x]=1;
			a[x]++;
		}
		vis[6]=1;
		for(int i=0;i<13;i++){
			if(vis[i]==0){
				b[i]++;
			}
		}
		turn=0;
		L=5;
		R=7;
		A=B=6;
		while(1){
			if(turn==0){
				if(a[L]==1 || a[R]==1) A--;
				if(a[L]==1 && a[R]==1){
					if(a[0]==1) a[L]--, L--;
					else a[R]--, R++;
				}
				else if(a[L]==1 && a[R]==0) a[L]--, L--;
				else if(a[L]==0 && a[R]==1) a[R]--, R++;
				if(A==0) break;
			}
			else{
				if(b[L]==1 || b[R]==1) B--;
				if(b[L]==1 && b[R]==1){
					if(b[0]==1) b[L]--, L--;
					else b[R]--, R++;
				}
				else if(b[L]==1 && b[R]==0) b[L]--, L--;
				else if(b[L]==0 && b[R]==1) b[R]--, R++;
				if(B==0) break;
			}
			turn^=1;
		}
		cout<<((turn==0) ? "yes\n" : "no\n");
	}
}



Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
    void run() {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println((x-a)%b);
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

//Write From this Line

int main()
{
	 char a ;
	 cin >>  a ;
		 a ++ ;
		 cout << a << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(a, b) << " " << max(0LL, a + b - n) << endl;

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
         ll n,a,b,ans;
         cin>>n>>a>>b;
         ll x=b-a;
 if(x%2==0){
         ans=x/2;
         cout<<ans<<endl;}
         else{
             ll y=min(n-b,a-1);
             ll z=(x-1)/2 + 1;
             cout<<y+z<<endl;
         }
     }

Measured memory_bytes: 256