akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long
int h,n;
int a[2000],b[2000];
int dp[1001][10001];
int f(int i,int left)
{
	if(left<=0)
		return 0;
	if(i==n)
	{
		if(left==0)
			return 0;
		return 1e18;
	}
	if(dp[i][left]!=-1)
		return dp[i][left];
	return dp[i][left]=min({f(i+1,left),b[i]+f(i,left-a[i]),b[i]+f(i+1,left-a[i])});
}
int32_t main()
{
    cin>>h>>n;
    for(int i=0;i<n;i++)
    	cin>>a[i]>>b[i];
    memset(dp,-1,sizeof(dp));
    cout<<f(0,h);
}

Measured memory_bytes: 79360
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string.h>
 
#define Optimize ios_base::sync_with_stdio(false); cin.tie(0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define iter(a) a.begin(), a.end()
using namespace std;

const long long INF = 2e9;
 
int main() {
	Optimize
 
	int n, k;
	cin >> n >> k;
	vector<long long> v(n), dp(n, INF);
	for (auto& i : v) {
		cin >> i;
	}
	dp[0] = 0;
	dp[1] = abs(v[0]-v[1]);
	for (int i = 2; i < n; i++) {
		for (int j = max(0, i - k); j <= i - 1; j++) {
			dp[i] = min(dp[i], dp[j] + abs(v[i]-v[j]));
		}
	}
	cout << dp[n-1] << '\n';
 
	return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  int n;
  cin >> n;

  vector<int> dp(100010);
  dp[0] = 0;
  for(int n = 1; n <= 100000; ++n){
    dp[n] = INT_MAX;
    int power = 1;
    while(power <= n){
      dp[n] = min(dp[n], dp[n - power] + 1);
      power *= 6;
    }
    power = 1;
    while(power <= n){
      dp[n] = min(dp[n], dp[n - power] + 1);
      power *= 9;
    }
  }

  cout << dp[n] << endl;

}


Measured memory_bytes: 640
# include <iostream>
# include <math.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int h[n+1];

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

    int C[n+1];
  
    C[1]=0;
    C[2] = abs(h[2]-h[1]);
    for(int i=3 ;i<=n;i++)
    {
        C[i] = min( C[i-1]+abs(h[i-1]-h[i]) , C[i-2] + abs(h[i]-h[i-2])  );
    }
    cout << C[n];

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC116 {
	class ABC116_B {
		static void Main(string[] args) {
			var S = int.Parse(Console.ReadLine());
			var n = S;
			var A = new List<int>() { n };
			while(true) {
				if(n % 2 == 0) {
					n = even(n);
				} else {
					n = odd(n);
				}
				if(A.Contains(n)) {
					break;
				}
				A.Add(n);
			}
			Console.WriteLine(A.Count() + 1);
		}

		private static int even(int n) {
			return n / 2;
		}

		private static int odd(int n) {
			return 3 * n + 1;
		}
	}
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

struct UnionFind{
  vint d;
  UnionFind(int n = 0) : d(n,-1) {}

  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x,int y){
    return find(x) == find(y);
  }

  int size(int x){
    return -d[find(x)];
  }
};

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  vint deg(100005);
  vvint to(100005,vint(0));
  UnionFind uf(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n){
    int ans = uf.size(i) - 1 - deg[i];
    for(int u:to[i]){
      if(uf.same(i,u)){
        ans--;
      }
    }
    printf("%d%c",ans,i==n-1?'\n':' ');
  }
}

Measured memory_bytes: 6784
#include<stdio.h>
int main(){
  int n,k;
  int i=0;
  
  scanf("%d %d",&n,&k);
  
  int d=n;
  
  while(d>0){
    d=d/k;
    i++;
  }
  printf("%d\n",i);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long double a,b;cin>>a>>b;
  cout<<(ll)(a*b)<<endl;
  return 0;
}


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

#define MAXN 123123
#define INF 0x3f3f3f3f

long long int n, w, weight[102], value[102], memo[102][MAXN];

long long int knap(int i, int carry){
    if(carry>w) return -INF;
    if(i==n) return 0;
    if(memo[i][carry]!=-1) return memo[i][carry];

    return memo[i][carry] = max(knap(i+1, carry), knap(i+1, carry+weight[i])+value[i]);
}

int main(){
    cin >> n >> w;

    for(int i=0;i<n;i++){
        cin >> weight[i] >> value[i];
    }

    memset(memo, -1, sizeof memo);

    cout << knap(0, 0) << endl;
}


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

string S;

int main(){
    cin >> S;
    REP(i, S.length())cout << "x";
    cout << endl;
    return 0;
}

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

int main() {
  int k; cin >> k;
  if (k == 1) {
    cout << 1 << '\n';
    cout << 1 << '\n';
    return 0;
  }
  int n = (k + 3) / 4 * 2;
  cout << n << '\n';
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) cout << ' ';
      int x;
      if (i % 2 == 0) {
        x = (i + j) % n + 1;
      } else {
        x = (i + j) % n + n + 1;
      }
      if (x > k) {
        x -= n;
      }
      cout << x;
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define MOD (ll)(998244353)
#define MAX (ll)(1e5 + 4)
#define INF (ll)(1e17)
using namespace std;
using ll =  long long;
using ld = long double;


int main () {
	int n;
	cin >> n;
	map<pair<int, int>, int> ma;
	for (int i = 1; i <= n; i++) {
		int x = i % 10;
		int xx = i;
		while (xx > 9) {
			xx /= 10;
		}
		ma[make_pair (x, xx)]++;
	}
	ll ans = 0;
	for (auto x : ma) {
		ans += x.second * 1LL *  (ma[make_pair (x.first.second, x.first.first)]);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 256
class String
    def contract!
        0 while gsub!(/\+\-|\-\+/, "")
        0 while gsub!(/\+([A-Z])/) { (?A.ord + ($1.ord - ?A.ord + 1) % 26).chr }
        0 while gsub!(/\-([A-Z])/) { (?A.ord + ($1.ord - ?A.ord + 25) % 26).chr }
        0 while gsub!(/\[([^\[\]]+?)\]/) { $1.scan(/[-+]*[A-Z?]/).reverse.join }
    end
end

loop do
    s = gets.chomp
    break if s == ?.
    s.contract!

    k = s.count(??)
    if k == 0
        puts s
    else
        e = s.dup
        puts e.gsub(/([\-\+]*)\?/, ?A)
    end
end

Measured memory_bytes: 9100
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

using Val = array<array<LL, 2>, 2>;

int N;
LL K;
Val dp[114];
string S;

const LL INF = 1LL << 50; 

Val Merge(Val a, Val b) {
  Val ret;
  rep(i, 2) {
    rep(j, 2) {
      ret[i][j] = INF;
    }
  }

  rep(i, 2) {
    rep(j, 2) {
      rep(k, 2) {
        rep(l, 2) {
          if (S[0] == S[N-1] && k == 0 && l == 0) continue;
          if (a[i][k] == INF || b[l][j] == INF) continue;
          MN(ret[i][j], a[i][k]+b[l][j]);
        }
      }
    }
  }
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> S;
  cin >> K;
  N = S.size();
  rep(i, N) {
    rep(j, 2) {
      rep(k, 2) {
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] = 0;
  dp[0][1][1] = 1;
  reps(i, 1, N) {
    rep(j, 2) {
      rep(k, 2) {
        rep(l, 2) {
          if (k == l && S[i] == S[i-1]) continue; 
          MN(dp[i][j][l], dp[i-1][j][k] + l);
        }
      }
    }
  }

  Val ans;
  Val m = dp[N-1]; 
  rep(i, 2) {
    rep(j, 2) {
      ans[i][j] = 0;
    }
  }
  rep(i, 32) {
    if (K >> i & 1) {
      ans = Merge(ans, m);
    }
    m = Merge(m, m);
  }

  LL p = INF;
  rep(i, 2) {
    rep(j, 2) {
      MN(p, ans[i][j]);
    }
  }
  cout << p << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    int answer = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x.at(i);
        answer += min(2 * x.at(i), 2 * (k - x.at(i)));
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
def solve(i,m,n,a)
    if m == 0
        return true
    end
    if i >= n
        return false
    end
    #m-a[i]→i番目の要素を使う
    res = solve(i+1,m,n,a) || solve(i+1,m-a[i],n,a)
        return res
end

n = gets.to_i
a = gets.split(" ").map(&:to_i)
q = gets.to_i
m = gets.split(" ").map(&:to_i)
i = 0
k = 0

    while k < q
        if solve(0,m[k],n,a)
            puts "yes"
        else
            puts "no"
        end
    k +=1
    end


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

using namespace std;

int gcd(int p, int q) {
    if (p % q == 0)return q;
    return gcd(q, p % q);
}

int main()
{
    long long k;
    cin >> k;

    int out = 0;
    
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                out += gcd(a, gcd(b, c));
            }
        }
    }

    cout << out;

    return 0;
}



Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long

typedef pair<lint, lint> P;
bool cmpx(const P& l, const P& r){
    return (l.first < r.first);
}
bool cmpy(const P& l, const P& r){
    return (l.second < r.second);
}


int main(){
    int n, k; cin >> n >> k;
    vector<P> p;
    rep(i, n){
        lint x, y; cin >> x >> y;
        p.push_back(make_pair(x, y));
    }
    sort(all(p), cmpx);

    ulint ans = 1e9*1e10;
    rep(i, n - 1){
        vector<P> tmp; tmp.push_back(p[i]);
        for(int j = i + 1; j < n; j++){
            tmp.push_back(p[j]);
            if(tmp.size() < k) continue;
            sort(all(tmp), cmpy);
            ulint r = 1e10;
            rep(l, tmp.size() - k + 1){
                r = min(r, (ulint)(tmp[l+k-1].second - tmp[l].second));
            }
            ans = min(ans, r * (ulint)(p[j].first - p[i].first));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
		int a,b,d,r;
		double f;
		scanf("%d %d",&a,&b);
		d=a/b;
		r=a%b;
		f=a;
		f=f/b;
		printf("%d %d %lf\n",d,r,f);
		return 0;
}



Measured memory_bytes: 2700
#include <stdio.h>
#include <string.h>
char t[1510];
int main(){
	int i;
	int n;
	int ans;
	int al[26]={0};
	while(gets(t)){
		n=strlen(t);
		for(i=0;i<n;i++){
			if(!isalpha(t[i])) continue;
			al[tolower(t[i])-'a']++;
		}
	}
	for(i=0;i<26;i++){
		printf("%c : %d\n",'a'+i,al[i]);
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define SIZE 10
using namespace std;
typedef long long ll;

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

	int N;
	int i,j;
	int answer;
	int counter=0;
	ll tmp;
	ll sum=1;
	double ave;
	vector<ll> given;

	cin >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		if(tmp==0){
			cout << 0 << endl;
			return 0;
		}
		given.push_back(tmp);
	}

	for(i=0;i<N;i++){
		if(sum*given[i]<sum){
			cout << -1 << endl;
			return 0;
		}
		sum*=given[i];
	}

	if(sum>1000000000000000000){
		cout << -1 << endl;
	}else{
		cout << sum << endl;
	}

	return 0;
}



Measured memory_bytes: 4248
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int n;
string s[M];
ll ans=0,ans1=1,ans2=1;
ll cnt[5]={};
bool f[5][5][5]={};
void dfs(int num1,int num2,int num3){
	if(num3==5)return;
	if(!f[num1][num2][num3])ans+=cnt[num1]*cnt[num2]*cnt[num3];
	f[num1][num2][num3]=true;
	dfs(num1,num2,num3+1);
	dfs(num1,num2+1,num3+1);
	dfs(num1+1,num2+1,num3+1);
	return;
}

int main(){
	cin>>n;
	rep(i,0,n){
		cin>>s[i];
		if(s[i][0]=='M')cnt[0]++;
		if(s[i][0]=='A')cnt[1]++;
		if(s[i][0]=='R')cnt[2]++;
		if(s[i][0]=='C')cnt[3]++;
		if(s[i][0]=='H')cnt[4]++;
	}
	dfs(0,1,2);
	print(ans);
}

Measured memory_bytes: 6144
let dbg = Printf.printf "[debug]%s"

let max_num = 1_000_000_000

let id = fun x -> x
let tuple2 x y = (x,y)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n

let (++^) n m = n ++ (m-1)

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)

let solve n _ codes samples =
  let dp = Array.make_matrix (n+1) 256 max_int in
  dp.(0).(128) <- 0;
  List.iteri (fun i s ->
      List.iter (fun j ->
          List.iter (fun c ->
              let m = if j+c > 255 then 255
                else if j+c < 0 then 0
                else j+c in
              dp.(i+1).(m) <-
                min dp.(i+1).(m) (if dp.(i).(j) <> max_int then dp.(i).(j) + (m-s) *(m-s) else max_int)
            ) codes
        ) (0 ++ 255)
    ) samples;
  Array.fold_left min max_int dp.(n)

let () =
  let rec aux () =
    let (n, m) = scan "%d %d" tuple2 in
    if n = 0 && m = 0 then ()
    else
      begin
        let codes = scan_lines m "%d" id in
        let samples = scan_lines n "%d" id in
        Printf.printf "%d\n" @@ solve n m codes samples;
        aux ()
      end
  in
  aux ()



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

n = int(input())
a = list(map(int,input().split()))
a.sort()

res = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if a[i] + a[j] > a[k] and a[i] != a[j] and a[j] != a[k]:
                res += 1

print(res)

Measured memory_bytes: 67968
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

int main(){
          string s;
          cin >> s;
          REP(i,4)  cout << s[i];
          cout << " ";
          FOR(i,4,12)         cout << s[i];
          cout << endl;
          return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Long> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			long a = sc.nextLong();
			list.add(a);
		}
		while(m > 0) {
			Collections.sort(list);
			Collections.reverse(list);
			long tmp = list.get(0);
			tmp = tmp >> 1;
			for(int i = 0; i < list.size(); i++) {
				long val = list.get(i);
				if(val >= tmp && m > 0) {
					val = val >> 1;
					list.set(i, val);
					m--;
				}
			}
		}
		long ans = 0;
		for(Long e : list) {
			ans += e;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 63096
N, K = map(int, input().split())
d = list()
A = list()
for _ in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

sunukeList = [0] * N
for holder in A:
    for sunuke in holder:
        sunukeList[sunuke-1] += 1

count = 0
for sunuke in sunukeList:
    if sunuke == 0:
        count += 1
print(count)


Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i = 0;
	ll ans, a, b = 1, k;
	string s;
	cin >> s >> k;
	while (i < s.size() - 1 && s[i] == s[i + 1])
		i++;
	a = i + 1;
	if (a == s.size()) {
		ans = a * k;
		ans >>= 1;
		cout << ans << "\n";
		return 0;
	}
	ans = a >> 1;
	for (; i < s.size() - 1; i++) {
		if (s[i] == s[i + 1])
			b++;
		else {
			ans += b >> 1;
			b = 1;
		}
	}
	ans += b >> 1;
	ans *= k;
	if (s[0] == s[s.size() - 1]) {
		ans -= ((a >> 1) + (b >> 1)) * (k - 1);
		ans += ((a + b) >> 1) * (k - 1);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N,M;
	cin >> N >> M;
	set<int> A,B;
	for(int i=0;i<M;++i){
		int a,b;
		cin >> a >> b;
		if( a > b ){
			swap(a,b);
		}
		if( a == 1 ){
			A.insert( b );
		}
		if( b == N ){
			B.insert( a );
		}
	}
	set<int>::iterator itr,end;
	itr = A.begin();
	end = A.end();
	bool flag = false;
	for(;itr!=end;++itr){
		if( B.find( *itr ) != B.end() ){
			flag = true;
			break;
		}
	}
	if( flag ){
		cout << "POSSIBLE" << endl;
	}else{
		cout << "IMPOSSIBLE" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 9600
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans0 = sum(a)
for i in range(n):
    if b[i] > a[i]:
        a[i+1] -= b[i]-a[i]
        a[i] = 0
        if a[i+1] < 0:
            a[i+1] = 0
    elif b[i] <= a[i]:
        a[i] -= b[i]
ans1 = sum(a)
print(ans0-ans1)

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

int main()
{
  ll n;
  cin >> n;
  
  ll h[n];
  rep(i,n) cin >> h[i];
  
  ll ans = 0, maxans = 0;
  for(ll i = 0; i < n; i++)
  {
    for(ll j = i; j < n-1; j++)
    {
      if(h[j] >= h[j+1])
      {
        ans++;
      }
      else 
      {
        break;
      }
    }
    if(ans > maxans){
      maxans = ans;
    }
    if(maxans >= n-i)
      break;
    ans = 0;
  }
  
  cout << maxans << endl;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll w, h, n;
  cin >> w >> h >> n;
  vll x(n), y(n), a(n);
  for (ll i = 0; i < n; i++) cin >> x[i] >> y[i] >> a[i];

  ll ans = h * w;
  vector<vll> grid(h, vll(w, 1));
  for (ll i = 0; i < n; i++) {
    ll u = 0, d = h - 1, l = 0, r = w - 1;
    if (a[i] == 1) r = x[i] - 1;
    else if (a[i] == 2) l = x[i];
    else if (a[i] == 3) u = h - y[i];
    else d = h - y[i] - 1;

    for (ll j = u; j <= d; j++) {
      for (ll k = l; k <= r; k++) {
        if (grid[j][k] == 1) {
          grid[j][k]--;
          ans--;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}

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

int main(){
    
    long long L,R;
    cin >> L >> R;
    if(R-L> 2019)cout << 0 << endl;
    else{
        long long ans = 2018;
        for(long long i = L; i < R;i++){
            for(long long j = i + 1; j <= R;j++){
                ans = min(ans, (i*j)%2019);
            }
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int c,a,b;cin>>c>>a>>b;
    cout<<c*a/2<<endl;
}

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

int N;
int64_t L;
std::vector<std::pair<int64_t, int64_t>> intervals;

int64_t calcX();
int64_t calcY();

int main()
{
	scanf("%d%lld", &N, &L);
	intervals.resize(N);
	for (auto& e: intervals) scanf("%lld%lld", &e.first, &e.second);
	printf("%d %d\n", calcX(), calcY());

	return 0;
}

int64_t calcX()
{
	std::sort(intervals.begin(), intervals.end());
	std::priority_queue<int64_t> available;
	int64_t right{};
	int ans{}, index{};
	while (right < L)
	{
		while (index < N && intervals[index].first <= right)
		{
			available.push(intervals[index].second);
			index++;
		}
		ans++;
		right = available.top();
		available.pop();
	}
	return ans;
}

int64_t calcY()
{
	std::vector<std::pair<int64_t, int>> points(2 * N);
	for (int i{}; i < N; i++)
	{
		points[i].first = intervals[i].first;
		points[N + i].first = intervals[i].second;
	}
	std::sort(points.begin(), points.end());
	points.erase(std::unique(points.begin(), points.end()), points.end());
	for (auto& e: intervals)
	{
		std::pair<int64_t, int> tmp(e.first, -N);
		std::lower_bound(points.begin(), points.end(), tmp)->second++;
		tmp.first = e.second;
		std::lower_bound(points.begin(), points.end(), tmp)->second--;
	}
	for (int i{1}; i < (int)points.size(); i++)
		points[i].second += points[i - 1].second;
	int min{1 << 30};
	for (int i{}; i < (int)points.size() - 1; i++)
		min = std::min(min, points[i].second);
	return N - min + 1;
}


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


    using namespace std;
    #define ll long long
    #define endl "\n"
    #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    ll func(ll cost[],ll h[]){
      cost[1]=0;
      cost[2]=abs(h[1]-h[2]);
      for(ll i=3;i<=n;i++){
      	cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]));
      }
      return cost[n];
    }
    int32_t main(){
      IOS;
      cin>>n;
      ll h[n+1];
      for(int i=1;i<=n;i++){
      	cin>>h[i];
      }
      ll cost[n+1];
      ll costn=func(cost,h);
      cout<<costn;
      return 0;
    }

Measured memory_bytes: 5200
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a,b,c;
  char k;
  int ans1=0,ans2=0;
  while(cin>>a>>k>>b>>k>>c){
    if((a*a+b*b)==c*c)ans1++;
    else if(a==b)ans2++;
  }
  cout<<ans1<<endl;
  cout<<ans2<<endl;
  
  return 0;
}

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

int main(){
 int A, B, C, D;
 cin >> A >> B >> C >> D;
 while (A > 0 && C > 0){
   C -= B;
   if(C <= 0){
     cout << "Yes" << endl;
   }else{
     A -= D;
     if(A <= 0){
       cout << "No" << endl;
     }
   }
 }
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;
static const ld PI = acos(-1);

ld a, b, h, m;

int main(void) {
    cin >> a >> b >> h >> m;
    ld athita = 360 - (30 * h + 0.5 * m) + 90;
    if (athita>=360.0) athita -= 360.0;
    ld bthita = 360 - 6 * m + 90;
    if (bthita>=360.0) bthita -= 360.0;
 
    ld ax = a*cos(PI/180.0*athita), ay = a*sin(PI/180.0*athita);
    ld bx = b*cos(PI/180.0*bthita), by = b*sin(PI/180.0*bthita);
 
    ld vx = ax - bx, vy = ay - by;
    ld ans = sqrt(vx*vx+vy*vy);
 
    printf("%0.10Lf\n", ans);
 

/*
    ld at = 360 - (30 * h + 0.5 * m)+90;
    ld bt = 360 - (6 * m)+90;


    ld ax = a*cosl(PI/180.*at), ay = a*sinl(PI/180.*at);
    ld bx = b*cosl(PI/180.*bt), by = b*sinl(PI/180.*bt);

    ld vx = ax - bx, vy = ay - by;
    ld ans = sqrtl((ld)vx*vx+(ld)vy*vy);

    printf("%0.10Lf\n", ans);

	return 0;
*/
}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    int l, r;
    int L = 0, R = INF;
    rep(i, m) {
        cin >> l >> r;
        L = max(L, l);
        R = min(R, r);
    }
    int ans;
    if (R - L < 0) ans = 0;
    else ans = R - L + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c;cin>>a>>b>>c;
    if(c-a-b>0&&(c-a-b)*(c-a-b)>4*a*b)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

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

int main(){
    int x,y;
    while(1){
        cin >> x >> y;
        if(x==0 && y==0) break;
        cout << min(x,y) << " " << max(x,y) << endl;
    }
    
    return 0;
}


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

int gcd(int a,int b){
    int c=1;
    while(c>0){
        c=a-int(a/b)*b;
        a=b;
        b=c;
    }
    return a;
}

int main(){
    int N;cin>>N;
    int ans;cin>>ans;
    int p;
    for(int i=1;i<N;i++){
        cin>>p;
        ans=gcd(ans,p);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Max(A []int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}

type Items [][]int
func (I Items) Len() int { return len(I) }
func (I Items) Less(i, j int) bool {
  if I[i][1] == I[j][1] { return I[i][0] > I[j][0] }
  return I[i][1] < I[j][1]
}
func (I Items) Swap(i, j int) { I[i], I[j] = I[j], I[i] }

type BinaryIndexedTree []int
func InitBIT(N int) BinaryIndexedTree {
  BIT := make([]int, N + 1)
  return BIT
}
func (BIT *BinaryIndexedTree) Increment(idx int) {
  N := len((*BIT))
  for i := idx; i < N; i += i & (-i) {
    (*BIT)[i]++
  }
}
func (BIT *BinaryIndexedTree) Update(idx, v int) {
  N := len((*BIT))
  d := v - BIT.Get(idx) + BIT.Get(idx - 1)
  for i := idx; i < N; i += i & (-i) {
    (*BIT)[i] += d
  }
}
func (BIT *BinaryIndexedTree) Get(idx int) int {
  if idx < 1 { return 0 }
  b := 0
  for i := idx; 0 < i; i -= i & (-i) {
    b += (*BIT)[i]
  }
  return b
}
func (BIT BinaryIndexedTree) Query(s, t int) int {
  return BIT.Get(t) - BIT.Get(s)
}

func Count(A *[]int, k int) int {
  N := len((*A))
  B := make([]int, N + 1)
  for i, a := range (*A) {
    B[i + 1] = B[i]
    if a <= k {
      B[i + 1]++
    } else {
      B[i + 1]--
    }
  }
  C := make([][]int, N + 1)
  for i, b := range B {
    C[i] = []int{i + 1, b}
  }
  sort.Sort(Items(C))
  BIT := InitBIT(N + 1)
  cnt := 0
  for _, c := range C {
    cnt += BIT.Get(c[0])
    BIT.Increment(c[0])
  }
  return cnt
}

func Solve(N int, A []int) int {
  high, low := Max(A), 0
  N2 := N * (N + 1) / 2
  B := N2 / 2 + 1
  for 1 < high - low {
    med := (high + low) / 2
    if Count(&A, med) < B {
      low = med
    } else {
      high = med
    }
  }
  return high
}

func main() {
  N := NextInt()
  A := NextIntVec()
  ans := Solve(N, A)
  Write(ans)
  Output()
}

Measured memory_bytes: 14464
use std::io::*;
use std::str::FromStr;
use std::collections::BTreeMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let mut m: BTreeMap<i64, i64> = BTreeMap::new();

    for _ in 0..n {
        let a: i64 = read();

        match m.get_mut(&a) {
            None => {
                m.insert(a, 1);
            },
            Some(b) => {
                *b += 1;
            }
        }
    }

    let mut ret = 0;
    for (i, j) in &m {
        if i < j {
            ret += j - i;
        } else if i > j {
            ret += j;
        }

    }
    println!("{}", ret);
}


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

int main() {
  int a,b,c;
  cin >> a >>b>>c;

  vector<int> vec = {a,b,c};
    sort(vec.begin(), vec.end());
  
    cout << (vec.at(0))*(vec.at(1))/2 << endl;
  }

  




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    if(n==1){
        cout<<s<<endl;
    }
    else{//n>=2
        string t=s;
        for(int i=1;i<n;i++){
            t[i]='9';
        }
        if(s==t){
            for(int i=0;i<n;i++){
                ans+=t[i]-'0';
            }
            cout<<ans<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                ans+=t[i]-'0';
            }
            cout<<ans-1<<endl;
        }

    }
}


Measured memory_bytes: 256
while True:
    a,op,b = input().split()
    
    if op == "?":
        break
    elif op == "+":
        print(int(a) + int(b))
    elif op == "-":
        print(int(a) - int(b))
    elif op == "*":
        print(int(a) * int(b))
    elif op == "/":
        print(int(a) // int(b))

Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)

int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
int dxx[]={1,1,0,-1,-1,-1,0,1};
int dyy[]={0,-1,-1,-1,0,1,1,1};
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;


int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >>s;
  if(s[0]==s[1]&&s[0]==s[2]) cout <<s;
  else{
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0';
    if(a>b) cout <<a<<a<<a;
    else if(a>=b&&b>=c) cout <<a<<a<<a;
    else cout <<a+1<<a+1<<a+1;
  }
  cout <<endl;

  

  return 0;
}


Measured memory_bytes: 256
S = input()
Q = int(input())

rev_flag = False

heads = []
tails = []

for i in range(Q):
  in_ = input()
  if len(in_) > 1:
    _, f, c = in_.split()
    f = int(f)
    
    if rev_flag:
      if f==1:
        #S = S + c
        tails.append(c)
      elif f==2:
        #S = c+S
        heads.append(c)
    else:
      if f==2:
        #S = S + c
        tails.append(c)
      elif f==1:
        #S = c + S
        heads.append(c)
    
  else:
    # reverse    
    rev_flag = not rev_flag

if rev_flag:
  ans = "".join(tails[-1::-1]) + S[-1::-1] + "".join(heads)
else:
  ans = "".join(heads[-1::-1]) + S + "".join(tails)

print(ans)
    
  

Measured memory_bytes: 6252
#include <iostream>
#include <math.h>
using namespace std;

#define MAX 10

int dou_diff(int x, int y)
{
	int k = x - y;
	return k * k;
}

int main(void)
{
	int N, D;
	int x[MAX][MAX];
	int i, j;
	int ans = 0;
	cin >> N >> D;
	for (i = 0; i < N; i++) {
		for (j = 0; j < D; j++)cin >> x[i][j];
	}

	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			int d = 0;
			for (int k = 0; k < D; k++) {
				d += dou_diff(x[i][k], x[j][k]);
			}
			int judge = (int)sqrt(d);
			if ((judge*judge) == d)ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 int N, flag[101];
 int main () {
  cin >> N;
  for(int i = 0; i < N; ++i){
    int d;
    cin >> d;
    flag[d] = 1;
  }
  int ans = 0;
  for(int i = 0; i < 101; ++i){
    ans += flag[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int ans = N -K +1;

		System.out.println(ans);
		
		
		sc.close();
	}
	
}


Measured memory_bytes: 23892
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, ans=1e18;
ll a[222222], ps[222222];

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i, j, loc;
	for(i=1 ; i<=n ; i++) cin>>a[i];
	for(i=1 ; i<=n ; i++) ps[i]=ps[i-1]+a[i];
	for(i=2 ; i<=n-2 ; i++) // make a cut [right of i] 
	{
		loc=lower_bound(ps+1,ps+n+1,ps[i]/2)-ps;
		ll tt_1=0, tt_2=0, cc_1, cc_2;
		for(j=loc-3 ; j<=loc+3 ; j++)
		{
			if(j<=0 || j>=i) continue;
			if(min(ps[i]-ps[j],ps[j])>tt_1) cc_1=j, tt_1=min(ps[i]-ps[j],ps[j]);
		}
		loc=lower_bound(ps+1,ps+n+1,ps[i]+(ps[n]-ps[i])/2)-ps;
		for(j=loc-3 ; j<=loc+3 ; j++)
		{
			if(j<=i || j>=n) continue;
			if(min(ps[n]-ps[j],ps[j]-ps[i])>tt_2) cc_2=j, tt_2=min(ps[n]-ps[j],ps[j]-ps[i]);
		}
		ll v=max(max(ps[i]-ps[cc_1],ps[cc_1]),max(ps[n]-ps[cc_2],ps[cc_2]-ps[i]))-min(min(ps[i]-ps[cc_1],ps[cc_1]),min(ps[n]-ps[cc_2],ps[cc_2]-ps[i]));
		ans=min(ans,v);
	}
	cout<<ans; return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 3456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		int n = Integer.parseInt(tmpArray[0]);
		int q = Integer.parseInt(tmpArray[1]);

		SqrtDecompositionRSQRAQ sq = new SqrtDecompositionRSQRAQ(n);

		for(int i = 0; i < q ; i++){
			tmpArray = br.readLine().split(" ");
			if(tmpArray[0].equals("0")){
				sq.add(Integer.parseInt(tmpArray[1]), Integer.parseInt(tmpArray[2]) + 1, Integer.parseInt(tmpArray[3]));
			}

			else {
				System.out.println(sq.getSum(Integer.parseInt(tmpArray[1]), Integer.parseInt(tmpArray[2]) + 1));
			}

//			sq.printBucket();
			//debug
//			for(int j = 0; j < n; j++){
//				System.out.print(sq.getSum(j, j + 1) + " ");
//
//			}
//			System.out.println();
		}
	}

}

class SqrtDecompositionRSQRAQ {
	int N, K;
	long[] data;
	long[] bucketAdd;
	long[] bucketSum;
	static final int sqrtN = 512;

	public SqrtDecompositionRSQRAQ(int n) {
		N = n;
		K = (N + sqrtN - 1) / sqrtN;
		data = new long[K * sqrtN];
		bucketAdd = new long[K];
		bucketSum = new long[K];
	}

	void add(int s, int t, int x) {
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= s || t <= l)
				continue;
			if (s <= l && r <= t) {
				bucketAdd[k] += x;
			} else {
				for(int i = Math.max(s, l); i < Math.min(t, r); ++i) {
					data[i] += x;
				}
				bucketSum[k] = 0;
				for(int i = l; i < r; i++){
					bucketSum[k] += data[i];
				}
			}
		}
	}

	long getSum(int s, int t){
		long result = 0;
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= s || t <= l)
				continue;
			if (s <= l && r <= t) {
				result += bucketAdd[k]*sqrtN + bucketSum[k];
			} else {
				int count = 0;
				for(int i = Math.max(s, l); i < Math.min(t, r); ++i) {
					result += data[i];
					count++;
				}

				result += bucketAdd[k]*count;
			}
		}
		return result;
	}

	void printBucket(){
		System.out.println("********************");
		for(int i = 0; i < 20; i++){
			System.out.print(bucketAdd[i]+" ");
		}
		System.out.println();
		for(int i = 0; i < 20; i++){
			System.out.print(bucketSum[i]+" ");
		}
		System.out.println("\n*********************\n");
	}
//	long get(int s) {
//		int k = s / sqrtN;
//		return data[s] + bucketAdd[k];
//	}
}


Measured memory_bytes: 67624
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N),B;
  for(int &i:A)cin>>i;
  int ng=-1;
  for(int i=0;i<=K;i++){
    int n=10000,m;
    for(int i=0;i<N;i++)
      if(i!=ng && A[i]<n)n=A[i],m=i;
    for(int i=0;i<N;i++)
      if(i!=ng && i!=m){
        if(A[i])A[i]--;
        else{
          puts("-1");
          return 0;
        }
        B.push_back(i);
      }
    ng=m;
    if(A[m])A[m]--;
    else{
      puts("-1");
      return 0;
    }
    B.push_back(m);
  }
  cout<<B.size()<<'\n';
  for(int i=0;i<B.size();i++)cout<<B[i]+1<<(B.size()==i+1?'\n':' ');
}

Measured memory_bytes: 3664
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

ans = 0
capa = 0
dept = -1
for t in sorted(T):
    if t > dept or capa == 0:
        ans += 1
        dept = t+K
        capa = C-1
    else:
        capa -= 1
print(ans)

Measured memory_bytes: 8280
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int[] a=new int[n+1];
      for(int i=0;i<n+1;i++)a[i]=sc.nextInt();
      Arrays.sort(a);
      for(int i=1;i<n+1;i++)a[i]-=a[0];
      int m=a[1];
      for(int i=1;i<n+1;i++)m=gcd(m,a[i]);
      System.out.println(m);
	}
  public static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
  public static int gcd(int m, int n) {
		if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}

}


Measured memory_bytes: 49728
#include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define N 100000
    int n;
    long long a[N];
    int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    } 
    vector<long long> dp(n,INT_MAX);
    dp[0] = 0;
    for(int i=1;i<n;i++){
        dp[i] = min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
        if(i>1){
            dp[i] = min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
        }
    }
    cout<<dp[n-1];

    }

Measured memory_bytes: 1792