akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define readInt(x) scanf("%d", &x)
#define readStr(x) scanf("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 28;
const int MAX = 1e5 + 10;

int N, K;
int num[2 * MAX];

int main()
{
    cin >> N >> K;
    rep(i, N) {
        int n;
        cin >> n;
        num[n]++;
    }

    std::sort(begin(num), end(num));
    
    int start = 0;
    while (num[start] == 0) {
        start++;
    }

    int cnt = 0;
    for (int i = start; i < start + 2 * MAX - start - K; i++) {
        cnt += num[i];
    }
    write(cnt);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e6+5;
const ll inf=1e17;

ll ar[ms];


bool check(ll x,ll n,ll a,ll b)
{
    int i;
    ll r=0;
    ll y=0;
    for(i=1;i<=n;i++)
    {
        y=max(0ll,ar[i]-(b*x));
        r+=((y+a-1)/a);
        if(r>x)return 0;
    }
    return 1;
}


int main()
{
    idfc;


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

    for(i=1;i<=n;i++)cin>>ar[i];


    int l=1;
    int r=1e9;
    int mid;

    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid,n,a-b,b))
        {
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<l;
    return 0;
}

Measured memory_bytes: 4404
/*
E869120 は 
1円硬貨を A 枚と 500 円硬貨を無限枚持っています.
これらの硬貨だけを使うことによって, ちょうど 
N 円を支払うことができるかを判定しなさい.

制約
Nは 1 以上 10000 以下の整数
A は 0 以上 1000 以下の整数


*/


#include <iostream>
using namespace std;
 
int main() {
    int N, A;
    cin >> N >> A;
    int c = N % 500;
    if (c <= A) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  int N;
  long C,K;
  cin>>N>>C>>K;
  vector<long> T(N);
  for(int i=0;i<N;i++) cin>>T.at(i);
  sort(T.begin(),T.end());
  int count=1;//バスの数
  pair<long,long> bus=make_pair(1,*(T.begin())+K);//1台のバスに乗っている人数，制限時間
  for(int i=1;i<N;i++){
    if(T.at(i)<=bus.second & bus.first<C){
      bus.first++;
    }else{
      bus=make_pair(1,T.at(i)+K);
      count++;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 1024
a =[]
b = []
o = []
ab = []
xx =gets
until xx.nil?
 x = xx.chomp
 y = x.split(",")

 if y[1] == "A"
  a << y[0]
 elsif y[1] == "B"
  b << y[0]
 elsif y[1] == "O"
  o << y[0]
 elsif y[1] == "AB"
  ab << y[0]
 end
 xx = gets
end
puts a.length
puts b.length
puts ab.length
puts o.length


Measured memory_bytes: 6876
package main
 
import (
    "fmt"
)
 
func main() {
	var N,A,i int

    fmt.Scan(&N)
    count:= []int{}  
  	i=1
  	for i<=N {
      	count=append(count,0)
      	i++
  	}
  
	i=2
  	for i<=N{
      	fmt.Scan(&A)
      	count[A-1]=count[A-1]+1
      	i++
  	}
  
  	i=0
  	for i< len(count) {
      	fmt.Println(count[i])
      	i++
  	}
}

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


int main(){
	int l,r,d;
	cin>>l>>r>>d;
	int c=0;
	for(int i=l;i<=r;i++){
		if(i%d==0)c++;
	}
	cout<<c<<endl;
}

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

const int maxN = 505;
const int maxQ = maxN * maxN;

int N;
int p[maxN * maxN];
int d[maxN][maxN];
bool is[maxN][maxN];
int q[maxQ * 2];
int fi, la;

int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};

int main() {
  std::cin >> N;
  for (int i = 0; i < N * N; ++i) {
    std::cin >> p[i];
    p[i] -= 1;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      is[i][j] = true;
      d[i][j] = std::min(std::min(i, N - 1 - i), std::min(j, N - 1 - j));
    }
  }
  int res = 0;
  for (int k = 0; k < N * N; ++k) {
    int i = p[k] / N;
    int j = p[k] % N;
    res += d[i][j];
    is[i][j] = false;
    fi = la = maxQ;
    q[la++] = p[k];
    while (fi < la) {
      int x = q[fi++];
      int i = x / N;
      int j = x % N;
      for (int dk = 0; dk < 4; ++dk) {
        int ii = i + di[dk];
        int jj = j + dj[dk];
        if (ii < 0 || ii >= N || jj < 0 || jj >= N) {
          continue;
        }
        if (!is[i][j]) {
          if (d[ii][jj] > d[i][j]) {
            d[ii][jj] = d[i][j];
            q[--fi] = ii * N + jj;
          }
        } else {
          if (d[ii][jj] > d[i][j] + 1) {
            d[ii][jj] = d[i][j] + 1;
            q[la++] = ii * N + jj;
          }
        }
      }
    }
  }
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 6232
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <functional>

using namespace std;

template <class T>
class segment_tree {
    public:
    segment_tree(int n, function<T(const T&, const T&)> func, const T& init = T());
    ~segment_tree();
    void add(int x, const T& value);
    void update(int x, const T& value);
    T get(int x, int y) const; // [x, y)
    
    private:
    int size;
    function<T(const T&, const T&)> func;
    T init;
    T* data;
};

template <class T> segment_tree<T>::segment_tree(int n, function<T(const T&, const T&)> func, const T& init) : size(1 << (32 - __builtin_clz(n - 1))), func(func), init(init) {
    data = (T *)malloc(sizeof(T) * size * 2);
    for (int i = 0; i < size * 2; i++) data[i] = init;
}

template <class T> segment_tree<T>::~segment_tree() {
    free(data);
}

template <class T> void segment_tree<T>::add(int x, const T& value) {
    update(x, data[x + size] + value);
}

template <class T> void segment_tree<T>::update(int x, const T& value) {
    data[x += size] = value;
    while (x >>= 1) data[x] = func(data[x * 2], data[x * 2 + 1]);
}

template <class T> T segment_tree<T>::get(int x, int y) const {
    T vl = init, vr = init;
    for (x += size, y += size; x < y; x >>= 1, y >>= 1) {
        if (x & 1) vl = func(vl, data[x++]);
        if (y & 1) vr = func(data[--y], vr);
    }
    return func(vl, vr);
}

vector <pair<int, int>> v[100000];

int main() {
    int n, m, i, j;
    long long ans;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < m; i++) {
        int l, r, c;
        
        scanf("%d %d %d", &l, &r, &c);
        
        l--;
        r--;
        
        v[r].push_back(make_pair(l, c));
    }
    
    segment_tree <long long> s(n, [](long long x, long long y) { return min(x, y); }, 1e18);
    
    s.update(0, 0);
    
    for (i = 1; i < n; i++) {
        long long x = 1e18;
        
        for (j = 0; j < v[i].size(); j++) {
            int l = v[i][j].first, c = v[i][j].second;
            
            x = min(x, s.get(l, i) + c);
        }
        
        s.update(i, x);
    }
    
    ans = s.get(n - 1, n);
    if (ans == 1e18) ans = -1;
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int main(){
  int i,n,j,k;
  long long int s=0;
  cin>>n;
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
        for(k=1;k<=n;k++){
            s += gcd(gcd(i,j),k);
        }
    }
  }
  cout<<s<<endl;
  return 0;
}

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

int f(int n){
    if(n % 2 == 0) return n / 2;
    else return 3 * n + 1;
}

int main(){

    int in; cin >> in;
    set<int> s;
    s.insert(in);
    int a = in;
    for(int i = 2; i <= 1000101; i++){
        
        a = f(a);
        //cout << a << endl;

        if(s.find(a) != s.end()){
            cout << i << endl;
            break;
        }


        s.insert(a);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
int main() {
  char c;
  cin >> c;
  if(c == 'a'||c == 'i'||c == 'u'||c == 'e'||c == 'o')
    dunk ("vowel");
  else dunk ("consonant");
}


Measured memory_bytes: 256
import bisect
A,B,Q =list(map(int,input().split()))
s = []
t = []
for i in range(A):
    s.append(int(input()))
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    x=(int(input()))    
    s_index_af = bisect.bisect(s,x)
    if s_index_af == A:
        s_index_af -= 1
        s_index_bf = s_index_af
    else:
        s_index_bf = s_index_af -1

    t_index_af = bisect.bisect(t,x)
    if t_index_af == B:
        t_index_af -= 1
        t_index_bf = t_index_af
    else:
        t_index_bf = t_index_af -1
   
    jl = [s[s_index_bf]-x,s[s_index_af]-x]
    tl = [t[t_index_bf]-x,t[t_index_af]-x]

    jt = []
    jt.append(abs(jl[0])+abs(tl[0]-jl[0]))
    jt.append(abs(jl[0])+abs(tl[1]-jl[0]))
    jt.append(abs(jl[1])+abs(tl[0]-jl[1]))
    jt.append(abs(jl[1])+abs(tl[1]-jl[1]))

    jt.append(abs(tl[0])+abs(jl[0]-tl[0]))
    jt.append(abs(tl[0])+abs(jl[1]-tl[0]))
    jt.append(abs(tl[1])+abs(jl[0]-tl[1]))
    jt.append(abs(tl[1])+abs(jl[1]-tl[1]))

            
    print(min(jt))


Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<vector<pii> > vvpi;

const int maxn = 2e5;
const ll mod = 998244353LL;
const ll inf = 1e9;

vector<int> a[26], b[26];

int main() {
	int i, j, n, m;
	string s, t;
	cin >> s;
	cin >> t;
	n = s.length(), m = t.length();
	for(i = 0; i < n; ++i) {
		a[s[i] - 'a'].push_back(i);
	}
	for(i = 0; i < m; ++i) {
		b[t[i] - 'a'].push_back(i);
	}
	for(i = 0; i < 26; ++i) {
		bool x = (a[i].size() > 0), y = (b[i].size() > 0);
		if (!x and y) {
			cout << -1 << "\n";
			return 0;
		}
	}
	ll cur = -1;
	for(i = 0; i < m; ++i) {
		auto &v = a[t[i] - 'a'];
		if(cur == -1) {
			cur = v[0];
		} else {
			ll r = cur % n;
			ll q = cur/n;
			auto it = lower_bound(v.begin(), v.end(), r);
			if (it != v.end() and *it == r) {
				it++;
			}
			if (it == v.end()) {
				it = v.begin();
				q++;
			}
			cur = (*it) + q*n;
		}
		// cout << cur << endl;
	}
	cout << cur + 1 << endl;
	return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>

int main(void)
{
  int D,T,S;
  int num;
  
  scanf("%d %d %d",&D,&T,&S);
  
  num = S * T;
  
  if (num >= D) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  
  return 0;
} 

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


int main(){
  int N;
  cin >> N;
  vector<int> A(N*2);

  for(int ii=0; ii<N; ii++){
    cin >> A[ii];
  }
  for(int ii=0; ii<N; ii++){
    A[ii+N] = A[ii];
  }

  int ans = 0;
  for(int ii=0; ii<N; ii++){
    ans += (ii%2==0) ? A[ii] : -A[ii];
  }
  cout << ans;
  for(int ii=1; ii<N; ii++){
    ans = 2 * A[ii-1] - ans;
    cout << " " << ans;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2048
while True:
    try:
        xA,yA,xB,yB,xC,yC,xD,yD = map(float, raw_input().split())
        if abs((yB-yA)*(yD-yC) + (xB-xA)*(xD-xC)) < 1.e-12:
                print "YES"
        else:
            print "NO"
    except:
        break

Measured memory_bytes: 4228
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

string sub(long n) {
  if (n == 0) return "0";
  string s;
  while (n != 0) {
    if ((unsigned long)n % 4 == 0) {
      s = "00" + s;
    } else if ((unsigned long)n % 4 == 1) {
      s = "01" + s; 
    } else if ((unsigned long)n % 4 == 2) {
      s = "10" + s; n += 4;
    } else {
      s = "11" + s; n += 4;
    }
    n >>= 2;
  }
  
  int i = 0;
  while (i < s.size() && s[i] == '0') {
    ++i;
  }
  return s.substr(i);
}

int main() {
  long n;
  cin >> n;
  cout << sub(n) << endl;
}

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

int main()
{
	int N,i;
	cin >> N;
	int L[N];
	int sum = 0;
	for(i=0;i<N;++i){
		cin >> L[i];
		sum += L[i];
	}
	for(i=0;i<N;++i){
		if(L[i] >= sum - L[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			TreeMap<Long, Integer> map = new TreeMap<>(
					new Comparator<Long>() {
						public int compare(Long m, Long n) {
							return ((Long)m).compareTo(n)*(-1);
						}
					});
			for (int i = 0; i < n; i++) {
				long ai = in.nextLong();
				map.merge(ai, 1, Integer::sum);
			}

			List<Long> list = new ArrayList<>();
			for (Entry<Long, Integer> e : map.entrySet()) {
				long k = e.getKey();
				int v = e.getValue()/2;
				if (v == 1) {
					list.add(k);
				} else if (v >= 2) {
					list.add(k);
					list.add(k);
				}
			}

			if (list.size() < 2) {
				out.println(0);
			} else {
				out.println(list.get(0) * list.get(1));
			}
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 44880
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a+b+c>=22) cout<<"bust"<<endl;
  else cout<<"win"<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; 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();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-12;
const int maxn=(int) 100000+20;
const int maxm=(int) 1e6+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

void work()
{
    string S,T;
    cin >>S;
    T="FESTIVAL";
    for(int i=S.size()-1;~i;i--)
    {
        int x=i,y=0;
        while(x<S.size() && y<T.size())
        {
            if(S[x]!=T[y]) break;
            x++,y++;
        }

        if(y==T.size())
        {
            for(int k=0;k<i;k++) cout <<S[k]; cout <<endl;
            break;
        }
    }
}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 256
# N = int(input())
A, V = [int(i) for i in input().split()]
B, W = [int(i) for i in input().split()]
T = int(input())
if A < B:
    if A + V * T >= B + W * T:
        print("YES")
    else:
        print("NO")
elif A > B:
    if A - V * T <= B - W * T:
        print("YES")
    else:
        print("NO")



Measured memory_bytes: 9148
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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; }

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi x(n), y(n), h(n);
  int index;
  rep(i, n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] >= 1) index = i;
  }
  rep(px, 1001) rep(py, 101){
    int ph = h[index] + abs(x[index] - px) + abs(y[index] - py);
    bool ok = true;
    rep(i, n){
      int tmp = max(ph - abs(x[i] - px) - abs(y[i] - py), 0);
      if(tmp != h[i]) ok = false;
    }
    if(ok){
      printf("%d %d %d\n",px, py, ph);
      return 0;
    }
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
const int mod = 1000000007;
const int N = 1e5+5, M = N;
//=========================================

int h[N], dp[N];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    for(int i = 1; i <= n; ++i)
        cin >> h[i];

    dp[1] = 0;
    for(int i = 2; i <= n; ++i){
        //dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        dp[i] = 2 * 1e9;
        for(int j = i - 1; j >= max(i - k, 1LL); --j){
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }

    cout << dp[n] << endl;

    return 0;
}


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

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

  int ans = 1;
  rep(_, N) {
    if (ans * 2 < ans + K) {
      ans *= 2;
    }
    else {
      ans += K;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

bool good(int index, vector<int> &ans, string &s){
	int n = ans.size();
	if (ans[index] != -1) return false;
	if (index != 0){
		if (s[index-1] == '<' && ans[index-1] == -1) return false;
	}
	if (index != n-1){
		if (s[index] == '>' && ans[index+1] == -1) return false;
	}
	return true;
}

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size() + 1;
	vector<int> ans(n, -1);
	queue<int> possible;
	for (int i=0; i < n; ++i){
		if (good(i, ans, s)){
			possible.push(i);
			ans[i] = -2;
		}
	}
	while (possible.size()){
		int V = possible.front();
		possible.pop();
		int val = 0;
		if (V!=0) val = max(val, ans[V-1]+1);
		if (V!=n-1) val = max(val, ans[V+1]+1);
		ans[V] = val;
		//cout << V << " " << val << endl;
		for (int j=V-1; j <= V+1; j++){
			if (j >= 0 && j <= n-1 && good(j, ans, s)){
				possible.push(j);
				ans[j] = -2;
			}
		} 
	}
	ll an=0;
	for (int i=0;i<n;++i) an += ans[i];
	cout << an; 
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,Y;
  cin >> N >> Y;
  int a=-1,b=-1,c=-1;
  for (int i=0;i<N+1;i++){
    for (int j=0;j<N+1-i;j++){
      if (10000*i+5000*j+1000*(N-i-j)==Y){
        a=i,b=j,c=N-i-j;
        break;
      }
    }
    if (a!=-1){
      break;
    }
  }
  cout << a << ' ' << b << ' ' << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int) (x.size())

signed main() {
    int n; string s;
    cin >> n >> s;
    if (n >= 3200) {
        cout << s << "\n";
    } else {
        cout << "red\n";
    }
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int N, A, B;

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

    int sum = A * N;

    int ans = min(sum, B);

    cout << ans << endl;

    return 0;
}


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

int main () {
  int x;
  cin >> x;
  bool flag = false;
  
  while(true) {    
    for (int i = 2; i < x; i++) {
      if (x % i == 0) break;
      if (i == x - 1) flag = true;
    }
    if (flag or x == 2) {
      break;
    } else {
      x++;
    }
  }
  cout << x << endl;
}
    


Measured memory_bytes: 256
import queue
N=int(input())
G=[dict() for i in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1][b-1]=c
    G[b-1][a-1]=c
Q,K=map(int,input().split());K-=1
x=[0 for i in range(Q)]
y=[0 for i in range(Q)]
for i in range(Q):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
q=[]
q.append(K)
dist=[-1 for i in range(N)]
dist[K]=0
while(len(q)>0):
    r=q[-1]
    q.pop()
    for p in G[r]:
        if dist[p]!=-1:
            continue
        dist[p]=dist[r]+G[p][r]
        q.append(p)
for i in range(Q):
    print(dist[x[i]]+dist[y[i]])


Measured memory_bytes: 62456
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

string get_time(int t){
  t %= 60 * 24;
  if(6 * 60 <= t && t < 18 * 60) return "Day";
  else return "Night";
}
bool is_firstday(int t){
  t %= 7 * 60 * 24;
  t /= 60 * 24;
  return t == 0;
}
bool ok(int t, string weekday, string time){
  return (weekday == "All" || is_firstday(t)) && (time == "All" || get_time(t) == time);
}

int main(){
  int S, N, T, P, M;
  string weekday, time;
  while(cin >> S >> N >> T >> weekday >> time >> P >> M && M){
    double ans = 0;
    for(int st = 0; st < 24 * 60 * 7; st++){
      int t = st;
      int cnt = 0;
      for(int iter = 0; iter < M; iter++){
        if(ok(t, weekday, time) && ok(t + S, weekday, time)){
          cnt += N;
        }
        t += T;
        t %= 7 * 24 * 60;
      }
      ans = max(ans, 1.0 - pow(1.0 - 1.0 / P, cnt));
    }
    printf("%.12f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  ll a, b, k;
  cin >> a >> b >> k;

  if (a > k) {
    a -= k;
  }
  else {
    k -= a;
    a = 0;
    if (b > k) {
      b -= k;
    }
    else {
      k -= b;
      b = 0;
    }
  }

  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n == 0
  m = gets.to_i
  s = gets.chomp
  pn = "I" + "OI" * n

  cnt = 0
  idx = 0
  loop do
    idx = s.index pn, idx+1
    idx ? cnt += 1 : break
  end

  puts cnt
end

Measured memory_bytes: 10728
/**
 *    SATAR ALLAH
 *
**/
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()


int main()
{

    int n;

    scanf("%d",&n);

    int T[n];
    for(int i=0;i<n;i++)
        scanf("%d",&T[i]);

    int l=0,r=0;
   long long curr_sum=0,curr_xor=0,ans=0;
    while(l<n){

         while(r<n){

            if( (curr_sum+T[r])!= (curr_xor^T[r]) )
                break;
              curr_sum+=T[r];
              curr_xor=T[r]^curr_xor;

              r++;
         }
         curr_sum-=T[l];
         curr_xor^=T[l];

         ans+=(r-l);

         l++;

    }

     printf("%lld",ans);



    return 0;
}


Measured memory_bytes: 1024
W = H = 5
m = input()
for r in range(m):
	M = [map(int,raw_input().split()) for i in range(H)]
	A = [[0]*W for i in range(H)]
	B = [[0]*W for i in range(H)]
	ans = 1
	for h in range(H):
		L = 0
		for w in range(W):
			if M[h][w] == 1:
				L += 1
			else:
				L = 0
			A[h][w] = L
			B[h][w] = (B[h-1][w] if h > 0 else 0) + 1 if L > 0 else 0
			if L*B[h][w] > ans:
				a = L
				for hi in range(B[h][w]):
					a = min(a,A[h-hi][w])
					if a*B[h][w] <= ans:
						break
					ans = max(ans,a*(hi+1))
	print ans
	if r != m-1: raw_input()

Measured memory_bytes: 4292
import java.util.*;
public class Main{
	public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			String[][] list = new String[n][6];
			boolean[] a = new boolean[n];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < 6; j++) {
					list[i][j] = sc.next();
				}
			}
			for(int i = 0; i < n; i++) {
				IN:for(int j = i+1; j < n; j++) {
					if(a[i]) continue;
					for(int k = 0; k < 4; k++) {
							x(list[j]);
						for(int l = 0; l < 4; l++) {
							y(list[j]);
							for(int m = 0; m < 4; m++) {
								z(list[j]);
								if(c(list[i],list[j])) {
									a[j] = true;
									continue IN;
								}
							}
						}
					}
				}
			}
			int count = 0;
			for(int i = 0; i < n; i++) {
				if(a[i]) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
	
	static void x(String[] a) {
		String tmp = a[1];
		a[1] = a[3];
		a[3] = a[4];
		a[4] = a[2];
		a[2] = tmp;
	}
	static void y(String[] a) {
		String tmp = a[0];
		a[0] = a[3];
		a[3] = a[5];
		a[5] = a[2];
		a[2] = tmp;
	}
	static void z(String[] a) {
		String tmp = a[0];
		a[0] = a[1];
		a[1] = a[5];
		a[5] = a[4];
		a[4] = tmp;
	}
	static boolean c(String[] a, String[] b) {
		for(int i = 0; i < 6; i++) {
			if(!a[i].equals(b[i])) {
				return false;
			}
		}
		return true;
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node find(Node u,int k){
  while(u!=NIL && k != u->key){
    if(k < u->key)u = u->left;
    else u= u->right;
  }
  return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z -> key < x->key){
      x = x->left;
    } 
    else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }

  else if(z->key < y->key){
      y->left = z;
    }
  else y->right = z;
	
  }





void inorder(Node u) {  
  if(u != NIL){
    if(u->left != NIL){
      inorder(u->left);
      }
    printf(" %d",u->key);
      
    if(u->right != NIL){
      inorder(u->right);
      }
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u != NIL){
    if(u->left != NIL)preorder(u->left);
    if(u->right != NIL)preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com); 
    if(com[0] == 'f'){
      scanf("%d",&x);
      Node t = find(root, x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }
      else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }}
    return 0;
  }

Measured memory_bytes: 19364
N = int(input())
P = list(map(float, input().split()))

# dp[i][j] := i枚目まで投げて表がj枚の確率
dp = [[0] * (N + 1) for i in range(N + 1)]
dp[0][0] = 1

for i, p in enumerate(P):
    for j in range(N + 1):
        dp[i + 1][j] += dp[i][j] * (1 - p)
        if j + 1 < N + 1:
            dp[i + 1][j + 1] += dp[i][j] * p

print(sum(dp[-1][N // 2 + 1:]))


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

int main(){
  int n;
  cin >> n;
  int result = n;
  for(int i = 2; i <= sqrt(n); i++){
    if(n % i == 0){
      result = result / i * (i - 1);
      while(n % i == 0)
        n /= i;
    }
  }
  if(n > 1)
    result = result / n * (n - 1);
  cout << result << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int p, q, r; cin >> p >> q >> r;
    cout << p+q+r-max(p,max(q,r)) << endl;
    return 0;
}

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


int main()
{
  string s, t;
  cin >> s >> t;
  cout << 3 - (bool)(s[0] ^ t[0]) - (bool)(s[1] ^ t[1]) - (bool)(s[2] ^ t[2]) << endl;
  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, Q;
vector<ll> edges[300100];
ll c[300100];

void dfs(ll ix, ll carry, ll par) {
  c[ix] += carry;
  for (auto nx : edges[ix]) {
    if (nx == par)
      continue;
    dfs(nx, c[ix], ix);
  }
}

signed main() {
  cin>>N>>Q;
  rep(i,N-1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  rep(i,Q) {
    ll p, x;
    cin >> p >> x;
    p--;
    c[p] += x;
  }
  dfs(0, 0, -1);
  rep(i,N) {
    cout << c[i];
    if (i == N-1)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}


Measured memory_bytes: 26880
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S  = sc.next();
    String T  = sc.next();
    char[]ss = S.toCharArray();
    char[]tt = T.toCharArray();
    
    int cou = 0;
    for(int i=0; i<S.length(); i++){
        if(ss[i]!=tt[i]){
            cou++;
        }
    }
    	System.out.println(cou);
}
}

Measured memory_bytes: 42208
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

void run (void) {
  i32 a, b, c;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &a, &b, &c);
  puts (a == b && b == c ? "Yes":"No");
}

int main (void) {
  run ();
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;

    cin >> a >> b >> c >> d;


    if(a*b>c*d) cout << a*b;
    else cout << c*d;

    return 0;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll dp[2010][2010];
ll a[2010];
ll H;
ll n,l,r;



int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a, b ,c;
    cin >> a >> b >> c;
    ll p=c-a-b;
    p*=p;
    if((4*a*b)<p && (c-a-b)>=0)
        cout << "Yes\n";
    else
        cout<<"No\n";
    return 0;
}


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

int main()
{
	int p, q, r;
	cin >> p >> q >> r;

	int min = 300;
	if (p + q < min) {
		min = p + q;
	}
	if (p + r < min) {
		min = p + r;
	}
	if (q + r < min) {
		min = q + r;
	}

	cout << min << endl;

	return 0;
}

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

int num(string&, int&);
int fact(string&, int&);
int mul(string&, int&);
int expr(string&, int&);

int num(string &s, int &k) {
    int ret = 0;
    while ('0' <= s[k] && s[k] <= '9') {
        ret *= 10;
        ret += s[k] - '0';
        k ++;
    }
    return ret;
}

int fact(string &s, int &k) {
    int ret;
    if (s[k] == '(') {
        ret = expr(s, ++k);
        k ++;
    } else if (s[k] == '-') {
        ret = -num(s, ++k);
    } else if (s[k] == '+') {
        ret = num(s, ++k);
    } else {
        ret = num(s, k);
    }
    return ret;
}

int mul(string &s, int &k) {
    int ret = fact(s, k);
    while (1) {
        if (s[k] == '*') {
            ret *= fact(s, ++k);
        } else if (s[k] == '/') {
            ret /= fact(s, ++k);
        } else {
            break;
        }
    }
    return ret;
}

int expr(string &s, int &k) {
    int ret = mul(s, k);
    while (1) {
        if (s[k] == '+') {
            ret += mul(s, ++k);
        } else if (s[k] == '-') {
            ret -= mul(s, ++k);
        } else {
            break;
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    string s;
    while (n--) {
        cin >> s;
        int pos = 0;
        cout << expr(s, pos) << endl;
    }
    return 0;
}

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

using namespace std;


int main() {
    const int INF = 10000000;
    int N, M, R;
    int graph[200][200];
    int r[8];
    int route[8];
    int ans = INT_MAX;

    cin >> N >> M >> R;
    for (int i = 0; i < R; i++) cin >> r[i];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            graph[i][j] = INF;
        }
    }

    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a-1][b-1] = min(graph[a-1][b-1], c);
        graph[b-1][a-1] = min(graph[b-1][a-1], c);
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j]);
            }
        }
    }

    for (int i = 0; i < R; i++) {
        route[i] = i;
    }

    do {
        int sum = 0;
        for (int i = 0; i < R-1; i++) {
            int a = r[route[i]]-1;
            int b = r[route[i+1]]-1;
            sum += graph[a][b];
        }
        ans = min(ans, sum);
    } while (next_permutation(route, route+R));

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


Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] ans=new int[n];
		int k =0; 
		for(int i = 1; i<n; i++){
			if(s.substring(i-1,i+1).equals("AC")){
				k++;
			}
			ans[i]=k;
		}
		for(int i = 0; i<q; i++){
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			System.out.println(ans[r]-ans[l]);
		}
	}
}


Measured memory_bytes: 65132
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var r = n % 10;

            if(r == 2 || r == 4 || r == 5 || r == 7 || r == 9){
                Console.WriteLine("hon");
            }else if(r == 3){
                Console.WriteLine("bon");
            }else{
                Console.WriteLine("pon");
            }
        }
    }
}


Measured memory_bytes: 27392
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int euclid(int a, int b){
  int ta = max(a, b);
  int tb = min(a, b);
  int t = INF;
  while(t != 0){
    t = ta % tb;
    ta = tb;
    if(t != 0) tb = t;
  }
  return tb;
}
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  vec div_c = {(a - 1) / c, b / c}, div_d = {(a - 1) / d, b / d};

  int l = c * d / euclid(c, d);

  int ans = 0;
  ans += b - div_c[1] - div_d[1] + b / l;
  ans -= a - 1 - div_c[0] - div_d[0] + (a - 1) / l;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  string S;
  cin>>S;
  ll N=S.size();
  ll K;
  cin>>K;

  bool same=true;
  for(int i=1;i<N;i++){
    if(S[i]!=S[i-1]) same=false;
  }

  if(same){
    ll ans=K*N;
    cout<<ans/2<<endl;
    return 0;
  }

  if(S[0]==S[N-1]){
    int fir=0;
    while(S[fir]==S[0]) fir++;
    int las=N-1;
    while(S[las]==S[0]) las--;

    ll res=fir+(N-las-1);
    res/=2;
    ll ans=0;
    for(int i=fir+1;i<=las;i++){
      if(S[i]==S[i-1]){
        S[i]='*';
        ans++;
      }
    }

    ans*=K;
    ll p=0;
    for(int i=1;i<fir;i++){
      if(S[i]==S[i-1]){
        S[i]='*';
        p++;
      }
    }
    ll q=0;
    for(int i=las+1;i<N;i++){
      if(S[i]==S[i-1]){
        S[i]='*';
        q++;
      }
    }

    ans=ans+res*(K-1)+p+q;
    cout<<ans<<endl;
  }else{
    ll ans=0;
    for(int i=1;i<N;i++){
      if(S[i]==S[i-1]){
        S[i]='*';
        ans++;
      }
    }

    ans*=K;
    cout<<ans<<endl;
  }

  return 0;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif

const int MAXN = 100;
//#define int long long
const int INF = 1e9;

int n, m;
vector<vector<int>> g;

vector<int> used;

int cnt = 0;
void dfs(int v, int c){
	cnt++;
	used[v] = c;
	for (int i : g[v]){
		if (!used[i]) dfs(i, c);
	}
}

void solve(){
	cin >> n >> m;
	g.assign(n, vector<int> ());
	used.assign(n, 0);

	int a, b;
	for (int i = 0; i < m; i++){
		cin >> a >> b;
		a--, b--;
		g[a].eb(b);
		g[b].eb(a);
	}
	
	int ans = 0;
	vector<int> c;

	for (int i = 0; i < n; i++){
		if (!used[i]) {
			dfs(i, ans+1);
			ans++;
			c.eb(cnt);
			cnt = 0;
		}
	}

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

	int rans = c.back();
	cout << rans << '\n';
}

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

		solve();

    return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  int ans = 1, prev = s[0];
  rep(i, 1, n){
    if(prev != s[i]){
      prev = s[i];
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using mii = map<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

signed main() {
  int n;cin>>n;
  vi a(n);cin>>a;
  int c = 0;
  rep(i,n) c+=a[i];
  int d = round(c/1.0f/n);
  int ans = 0;
  rep(i,n) {
    ans += (a[i]-d)*(a[i]-d);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define INF 1000000000
#define M 1000000007

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

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

int main() {
	int N;
	int A[100001];
	long ans = 0;
	int m = 0;
	int i;
	
	scanf("%d", &N);
	for(i=1;i<=N;i++) {
		scanf("%d", &A[i]);
		if(A[i] % (m + 1) == 0) {
			ans += A[i] / (m + 1) - 1;
		} else {
			ans += A[i] / (m + 1);
		}
		if(m == 0) m = 1;
		else {
			if(A[i] == m + 1) m++;
		}
	}
	
	printf("%ld\n", ans);
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(0<=x-r && x+r<=w && 0<=y-r && y+r<=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
n=input()
S=['S 1','S 2','S 3','S 4','S 5','S 6','S 7','S 8','S 9','S 10','S 11','S 12','S 13']
H=['H 1','H 2','H 3','H 4','H 5','H 6','H 7','H 8','H 9','H 10','H 11','H 12','H 13'] 
C=['C 1','C 2','C 3','C 4','C 5','C 6','C 7','C 8','C 9','C 10','C 11','C 12','C 13']
D=['D 1','D 2','D 3','D 4','D 5','D 6','D 7','D 8','D 9','D 10','D 11','D 12','D 13']
cards=[S,H,C,D]
for i in range(n):
  cardlist=raw_input()
  if 'S' in cardlist:
    cards[0].remove(cardlist)
  if 'H' in cardlist:
    cards[1].remove(cardlist)
  if 'C' in cardlist:
    cards[2].remove(cardlist)
  if 'D' in cardlist:
    cards[3].remove(cardlist)
for j in range(4):
  for i in cards[j]:
    print i

Measured memory_bytes: 6416