akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long N, A, B;
    scanf("%lld %lld %lld", &N, &A, &B);
    long long cnt = 0;
    if (N >= (A + B - 1) && N <= A * B) {
        while (1) {
            for (long long i = 1; i <= A; i++) {
                printf("%lld ", N - A + i);
            }
            cnt += 1;
            N -= A;
            if (B - cnt - 1 > N - A || N < 1) break;
        }
        if (N > 0){
            for (long long i = B - cnt; i <= N; i++) {
                printf("%lld ", i);
            }
            for (long long i = B - cnt - 1; i > 0; i--) {
                printf("%lld ", i);
            }
        }
    } else {
        printf("%d", -1);
    }

    return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s = reader.readLine();
        if(s.contains("RRR")) {
            System.out.println(3);
        } else if(s.contains("RR")) {
            System.out.println(2);
        } else if(s.contains("R")) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
        
    }
}


Measured memory_bytes: 32588
# n = int(input())
# s = input()
# a = list()
a, b, c, d = map(int, input().split())

while (a>0 and c>0 ):
    c-=b
    if c <= 0:
        print("Yes")
        exit()
    a-=d
    if a<=0:
        print("No")
        exit()


Measured memory_bytes: 9168
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    st = input[0].split(" ");
  

    s = st[1].trim();   //Sうけとり
    t = st[0].trim();   //Tうけとり
    
    var ts='';
    ts =s+t;
    
    console.log(ts);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main()
{
    long long int n,k,ch=0,i;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;++i) cin>>a[i];
    for(i=k;i<n;++i)
    {
        if(a[i]>a[i-k]) cout<<"Yes\n";
        else cout<<"No\n";
    }
    
    
    return 0;
}







Measured memory_bytes: 4344
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define re return
#define pb emplace_back
#define em emplace
#define er erase
#define all(x) (x).begin(), (x).end()
#define in(v); { for (auto &i : v) cin >> i; }
#define out(v); { for (auto &i : v) cout << i << ' '; cout << endl; }

#define int long long

using namespace std;
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;

const long long INFll = 1e18;


int dp[20000];
bool was[20000];

void solve() {
    int h, n; cin >> h >> n;
    vector <int> a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i];
    was[0] = 1;
    for (int i = 0; i < 20000; i++) {
        if (!was[i])
            continue;
        for (int j = 0; j < n; j++) {
            if (i + a[j] < 20000) {
                if (!was[i + a[j]]) {
                    was[i + a[j]] = 1;
                    dp[i + a[j]] = dp[i] + b[j];
                } else {
                    dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
                }
            }
        }
    }

    int ans = 1e18;
    for (int i = h; i < 20000; i++) {
        if (was[i])
            ans = min(ans, dp[i]);
    }
    cout << ans;
}

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

    solve();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main(){
	ios::sync_with_stdio(false);
	ll h,n;
	cin>>h>>n;
//	vectro<int> a;
	ll sum = 0;
	for(int i=0;i<n;++i){
		int val;
		cin>>val;
		sum+=val;
//		a.push_back(val);
	}
	if(sum>=h) cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';
	return 0;
}


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

using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::endl;
using std::ios_base;
using std::unordered_map;
using std::cerr;
using std::string;
using std::to_string;
using std::max;
using std::min;

const int INF = 1e9;

vector<vector<int>> g;
vector<int> t;
vector<bool> used;

void dfs(int u) {
    used[u] = 1;
    for (int v : g[u]) {
        if (!used[v]) {
            dfs(v);
            }
    }
    t.push_back(u);
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    g.resize(n);
    used.resize(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i);
        }
    }

    vector<int> dp(n);
    int maxi = 0;
    for (int i : t) {
        for (int to : g[i]) {
            dp[i] = max(dp[i], dp[to] + 1);
            maxi = max(maxi, dp[i]);
        }
    }
    cout << maxi << endl;
    


    return 0;
}



Measured memory_bytes: 8696
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;

int main()
{
  int N; cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d[i];

  sort(d.begin(), d.end());
  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}

Measured memory_bytes: 768
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		long[] a = new long[n + 1];
		long[] sum = new long[n + 1];
		sum[0] = 0;
		for(int i = 1; i < n + 1; i++) {
			a[i] = sc.nextLong();
			sum[i] = sum[i - 1] + a[i];
		}
		Map<Long, Long> div = new HashMap<>();
		for(int i = 0; i < n + 1; i++) {
			long x = sum[i] % m;
			if(div.containsKey(x)) {
				long val = div.get(x);
				val++;
				div.put(x, val);
			} else {
				div.put(x, (long) 1);
			}
		}
		long cnt = 0;
		for(Map.Entry<Long, Long> e : div.entrySet()) {
			long num = e.getValue();
			if(num >= 2) {
				cnt += num * (num - 1) / 2;
			}
		}
		System.out.println(cnt);
	}

}


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

using namespace std;
typedef long long ll;
int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ret;
    ret = max(a * c, b * d);
    ret = max(a*d,ret);
    ret = max(ret,b*c);
    cout<<ret<<endl;
    return 0;
}





Measured memory_bytes: 3636
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    char x[3];
    cin>>x;
    if ( strncmp(x,"SSS",3) == 0 )
    {
        cout<<0;
        return 0;
    }
    if ( strncmp(x,"RSS",3) == 0 || strncmp(x,"SRS",3) == 0 ||strncmp(x,"SSR",3) == 0 ||strncmp(x,"RSR",3) == 0)
    {
        cout<<1;
        return 0;
    }
    if ( strncmp(x,"RRS",3) == 0 || strncmp(x,"SRR",3) == 0 )
    {
        cout<<2;
        return 0;
    }
    if ( strncmp(x,"RRR",3) == 0 )
    {
        cout<<3;
        return 0;
    }
  
    return 0;
}

Measured memory_bytes: 3684
///created: 13/Jun/2019 15:05:58

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define db(x) cerr << "debug: " << #x << " = " << x << '\n';
template<class __Ty> bool minimize(__Ty& a, __Ty b) {
	if (a > b) { a = b; return true; }
	return false;
}
template<class __Ty> bool maximize(__Ty& a, __Ty b) {
	if (a < b) { a = b; return true; }
	return false;
}

bool cmp(ii a, ii b) {
	return a.second > b.second;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	map<int, int> mp[2];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		mp[i % 2][tmp]++;
	}
	int ans = 1e9 + 7;
	vector<ii> a(mp[0].begin(), mp[0].end());
	vector<ii> b(mp[1].begin(), mp[1].end());
	a.push_back(ii(1e9 + 7, 0));
	b.push_back(ii(1e9 + 7, 0));
	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end(), cmp);
	map<int, int> mt;
	for (int i = 0; i < int(b.size()); ++i)
		mt[b[i].first] = i + 1;
	for (int i = 0; i < int(a.size()); ++i) {
		if (!mt[a[i].first]) {
			ans = min(ans, n - mp[0][a[i].first] - b[0].second);
		}
		else {
			if (mt[a[i].first] > 1)
				ans = min(ans, n - mp[0][a[i].first] - b[mt[a[i].first] - 2].second);
			else
				ans = min(ans, n - mp[0][a[i].first] - b[mt[a[i].first]].second);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 10480
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1000000 + 5;

int n;
int a[N];

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; ++ i) {
        scanf("%d", a + i);
    }
    long long sum = 0;
    for(int i = 0; i <= n; ++ i) {
        sum += abs(a[i] - a[i + 1]);
    }
    for(int i = 1; i <= n; ++ i) {
        printf("%lld\n", sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]));
    }
}

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



Measured memory_bytes: 1664
s=input()
K=int(input())
l=len(s)
d=[[s[i],l-i] for i in range(len(s))]
d=sorted(d)
h=dict()
ans=0
ca=d[0][0]   

for i in d:
    if(i[0]!=i[0][0]):
        break
    z=min(i[1]+1,6)
    for j in range(1,z):
        if(s[l-i[1]:l-i[1]+j] not in h):
            ans+=1
            h.update({s[l-i[1]:l-i[1]+j]:1})
        else:
            pass


h=sorted(h)
print(h[K-1])

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

int main() {
	int k, s, v ;
	cin >> k >> s;
	for(int x=0; x < k+1; x++){
		for(int y=0; y < k+1; y++){
			int z = s-x-y;
			if(z<k+1&&z>-1){
				v++;
			}
			
		
	}
	}
	cout<< v <<endl;
return 0;	
}

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

using namespace std;

void move(bool who, int n, pair<int,int>& pos){
	int a = pos.first, b = pos.second;
	if(who){
		if(b != a+1){
			pos.first++;
		}
		else{
			pos.first--;
		}
	}
	else{
		if(a != b-1){
			pos.second--;
		}
		else{
			pos.second++;
		}
	}
}

int main(){
	int n; cin >> n;
	pair<int,int> p;
	cin >> p.first >> p.second;
	bool who = true;
	while(true){
		move(who, n, p);
		who = !who;
		if(p.first == 0){
			who = true;
			break;
		}
		else if(p.second == n+1){
			who = false;
			break;
		}
	}
	if(who)cout << "Borys" << endl;
	else cout << "Alice" << endl;
	return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n=int(input())
a = [int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
mina=min(a)
maxa=max(a)
absa=float('inf')
for t in range(mina,maxa):
    s1=0
    for i in range(n):
        if i <= t:
            s1+=a[i]
    s2=suma-s1
#    print(s1,s2)

    tmp=abs(s1-s2)
    if tmp < absa:
        absa=tmp
    
print(absa)

Measured memory_bytes: 39024
n,m = map(int,input().split())
l = []
r = []

while True:
  try:
    tl,tr = map(int,input().split())
    l.append(tl)
    r.append(tr)
  except:
    break

R = min(r)
L = max(l)
cnt = 0
for i in range(1,n+1):
  if i>=L and i<=R:
    cnt +=1
    
print(cnt)
    

Measured memory_bytes: 56280
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;

  string res = "";

  for(char& c : s) {
    if (c == 'B') {
      res.pop_back();
    } else {
      res.push_back(c);
    }
  }

  printf("%s\n", res.c_str());
  return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+111;
int a[maxn],b[maxn],c[maxn],d[maxn];
int ans=0;
int n,m,q;
vector<int> st;
void search(int num,int index){
    if(index==n){
        int tpans=0;
        for(int j=1;j<=q;++j){
            if(st[b[j]]-st[a[j]]==c[j]){
                tpans+=d[j];
            }
        }
        ans=max(ans,tpans);
        return;
    }
    for(int i=num;i<=m;++i){
        st.push_back(i);
        search(i,index+1);
        st.pop_back();
    }
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;++i){
        scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
    }
    st.push_back(0);
    for(int i=1;i<=m;++i){
        st.push_back(i);
        search(i,1);
        st.pop_back();
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3832
def resolve():
    n,x,m = map(int,input().split())
    ans = x
    y = [x]
    for i in range(n-1):
        x = (x**2)%m
        if x not in y:
            y.append(x)
        else:
            break
    b = y.index(x)
    N = len(y[b:])
    c = sum(y[b:])
    ans = sum(y[:b]) + c*((n-b)//N)+sum(y[b:b+(n-b)%N])
    print(ans)
resolve()

Measured memory_bytes: 68536
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, T = reads()
t = reads() + [1 << 60]

ans = 0
for i in range(N):
  ans += min(T, t[i+1] - t[i])
print(ans)

Measured memory_bytes: 88784
#include<stdio.h>
int main(){
	long long i,n,p = 1;
	scanf("%lld",&n);
	for(i = 1;i <= n;i++){
		p = p * i % (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7);
		}
	printf("%lld\n",p);
	return 0;
	}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

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

ll f[200002] = {};

ll MODPOW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = MODPOW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * MODPOW(n, m - 1)) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r) {
    return 0LL;
  }

  if (r > n / 2LL) {
    r = n - r;
  }

  ll res = (f[n] * MODPOW(f[n - r], MOD - 2LL)) % MOD;
  res = (res * MODPOW(f[r], MOD - 2LL)) % MOD;

  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, W, A, B;
  cin >> H >> W >> A >> B;
  f[0] = 1;
  FOR(i, 1, H + W) { f[i] = (f[i - 1] * i) % MOD; }

  ll ans = 0;
  ll y = H - 1 - A;
  ll x = B;

  while (x < W && y >= 0) {
    // cout << x << "," << y << endl;
    ll ans1 = nCr(x + y, x);
    ll ans2 = nCr(H - 1 - y + W - 1 - x, W - 1 - x);
    ans = (ans + (ans1 * ans2) % MOD) % MOD;
    x++;
    y--;
  }

  cout << ans << endl;

  return 0;
}


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

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


    int f[n]{0};
    f[0]=0;
    f[1]=abs(arr[1]-arr[0]);
    for (int i=2;i<n;i++)
    {
        
            f[i]=min(abs(arr[i]-arr[i-2])+f[i-2],abs(arr[i]-arr[i-1])+f[i-1]);

        
    }
    cout<<f[n-1];
}

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

def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        C[i][A[k]-1] = 1

N = int(input())
C = [[0]*N for _ in range(N)]
for i in range(N):
    A = list(map(int, input().split()))
    getNeighbor(A,i)
for i in range(N):
    print(*C[i])



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

const int m = 1000000007;
int main(){
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll inv1=0,inv2=0;
  rep(i,n){
    rep(j,n){
      if(i==j) continue;
      if(a[i]>a[j]){
        if(i<j) inv1++;
        inv2++;
      }
    }
  }
  ll ans=0;
  ans+=(k*inv1)%m;
  ans+=((k*(k-1))/2)%m*inv2;
  ans%=m;
  cout<< ans;
  return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };



int main() {
	ll a;

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> a;
	if (a >= 1000) {
		cout << "ABD" << endl;
	}
	else {
		cout << "ABC" << endl;

	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = in.nextInt();
		int x = in.nextInt();

		int sum = 0;
		int[] l = new int[n];
		for ( int i = 0; i < n; i++ ) {
			l[i] = in.nextInt();
		}

		int cnt = 1;
		for ( int i = 0; i < n; i++ ) {
			
			sum += l[i];

			if ( sum > x ) {
				break;
			}
			
			cnt++;
		}

		System.out.println(cnt);
		in.close();
	}
}


Measured memory_bytes: 21716
# coding:utf-8

def palindrome(string): 
    return 0 if string==string[::-1] else 1
    
def main():
    s = input()
    n = int(len(s))

    temp = []
    temp2 = []

    for i in range(int((n-1)/2)):
        temp.append(s[i])
    temp = ''.join(temp)
        
    for i in range(int((n+3)/2)-1, n):
        temp2.append(s[i])
    temp2 = ''.join(temp2)

    if (palindrome(temp) == 0 and palindrome(temp2) == 0) and palindrome(s) == 0:
        print("Yes")
    else: print("No")

if __name__ == '__main__' :
    main()

Measured memory_bytes: 3064
N, K, Q = map(int, input().split())
A = [0 for _ in range(N)]
for i in range(Q):
  A[int(input()) - 1] += 1

ans = []
for a in A:
  if K + a - Q > 0:
    ans.append("Yes")
  else:
    ans.append("No")
print("\n".join(ans))

Measured memory_bytes: 5912
#include <cstdio>
#include <algorithm>

const int MAXD = 12;

struct Prob {
    int score, p, c;
} P[MAXD];

struct HeapNode {
    int i, c;

    HeapNode(int i = 0, int c = 0) : i(i), c(c) {}

    bool operator<(const HeapNode &rhs) const {
        return c > rhs.c;
    }
};

int main() {
    int D, G, ans = 0;
    scanf("%d %d", &D, &G);
    for (int i = 0; i < D; i++) {
        scanf("%d %d", &P[i].p, &P[i].c);
        P[i].score = 100 * (i + 1);
        ans += P[i].p;
    }

    for (int s = 0; s < 1 << D; s++) {
        int sum = 0, cnt = 0, restMax = -1;

        for (int i = 0; i < D; i++) {
            if (s & (1 << i)) {
                sum += P[i].score * P[i].p + P[i].c;
                cnt += P[i].p;
            } else {
                restMax = i;
            }
        }

        if (sum < G) {
            int need = (G + P[restMax].score - 1 - sum) / P[restMax].score;
            if (need > P[restMax].p) continue;
            cnt += need;
        }

        ans = std::min(ans, cnt);
    }

    printf("%d\n", ans);
    
    return 0;
}

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

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(int i = 0;i<(int)n;i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
static const long long INFTY = (1LL << 32);

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	string ans;
	if (A + B == C + D) {
		ans = "Balanced";
	}
	else if (A + B > C + D) {
		ans = "Left";
	}
	else if (A + B < C + D) {
		ans = "Right";
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define INFTY 1000000001

typedef struct{
  char c;
  int x;
}card;

int part(card *A,int p,int r){
  int f,i,j;
  card tmp;

  f=A[r].x;
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].x<=f){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}

void quick(card *A,int p,int r){
  int q;
  if(p<r){
    q=part(A,p,r);
    quick(A,p,q-1);
    quick(A,q+1,r);
  }
}

void merge(card *C,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  card L[n1+N],R[n2+N];
  for(i=0;i<n1;i++) L[i]=C[left + i];
  for(i=0;i<n2;i++) R[i]=C[mid + i];
  L[n1].x=INFTY;
  R[n2].x=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i].x<=R[j].x){
      C[k]=L[i];
      i=i+1;
    }
    else{
      C[k]=R[j];
      j=j+1;
    }
  }
}

void  mergeSort(card *C,int left,int right){
  int mid;
  if (left+1<right){
    mid=(left+right)/2;
    mergeSort(C,left,mid);
    mergeSort(C,mid,right);
    merge(C,left,mid,right);
  }
}

int main(){

  int i,j,n,x,flag=0;
  card A[N],B[N];

  scanf("%d",&n);

  for(i=0;i<n;i++) {
    scanf(" %c%d",&A[i].c,&A[i].x);
    B[i].c=A[i].c;
    B[i].x=A[i].x;
  }

  quick(A,0,n-1);

  mergeSort(B,0,n);

  for(i=0;i<n;i++){
    if(B[i].c != A[i].c){
      flag=1;
      break;
    }
  }

  if(flag==1)printf("Not stable\n");
  else printf("Stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].x);
  }

  return 0;
}



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


int main() {
    long long N;
    cin >> N;
    long long counter=0;
    long long b;
    long long i=0;
    queue <long long> c;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        c.push(ex);}
    if (N != 1) counter++;
    while(c.size()>0){
    b=c.front();
    c.pop();
    i=1;
    while(b>0){
    if(b-i>=0){
    counter++;
    b-=i;
    i++;
    }
    else
    break;
    }
    }
    cout << counter<< endl;
}

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

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	int N; cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		reverse(S[i].begin(), S[i].end());
	}
	sort(S.begin(), S.end(), [](const string& a, const string& b) { return a.size() > b.size(); });

	int V = 1;
	vector<array<int, 26>> ch;
	vector<array<int, 26>> dp;
	vector<int> par;

	ch.emplace_back(); ch.back().fill(0);
	dp.emplace_back(); dp.back().fill(0);
	par.push_back(-1);

	int64_t ans = 0;
	for (string s : S) {
		char last = s.back();
		s.pop_back();
		int cur = 0;
		for (char c : s) {
			if (!ch[cur][c-'a']) {
				int ind = V++;
				ch.emplace_back(); ch.back().fill(0);
				dp.emplace_back(); dp.back().fill(0);
				par.push_back(cur);
				ch[cur][c-'a'] = ind;
			}
			cur = ch[cur][c-'a'];
		}
		ans += dp[cur][last-'a'];

		dp[cur][last-'a']++;

		array<bool, 26> seen; seen.fill(false);
		seen[last-'a'] = true;

		for (int z = int(s.size())-1; z >= 0; z--) {
			seen[s[z]-'a'] = true;
			cur = par[cur];
			for (int i = 0; i < 26; i++) {
				if (seen[i]) {
					dp[cur][i]++;
				}
			}
		}
	}
	cout << ans << '\n';

	return 0;
}

// S_i -> S_j iff S_i.endswith(S_j[1:]) and S_j[0]


Measured memory_bytes: 215040
import sys
INF = 1 << 60
MOD = 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, s = map(int, input().split())
    dp = [0] * (s + 1)
    dp[0] = 1
    res = 0
    A = list(map(int, input().split()))
    for a in A:
        ndp = [2 * t % MOD for t in dp]
        if s >= a:
            for i in range(s - a, -1, -1):
                ndp[i + a] += dp[i]
                ndp[i + a] %= MOD
        dp = ndp


    print(dp[s] % MOD)
resolve()

Measured memory_bytes: 71756
# -*- coding: utf-8 -*-
import sys

def main():
    N = int( sys.stdin.readline() )
    A_list = list(map(int, sys.stdin.readline().split()))

    A_list.sort(reverse=True)
    arrived_idx = 1
    comfort = A_list[0]


    for i in range(1, len(A_list)):
        if ( len(A_list) - 1 - arrived_idx ) >= 2:
            comfort += (A_list[i] * 2)
            arrived_idx += 2
        elif ( len(A_list) - 1 - arrived_idx ) == 1:
            comfort += A_list[i]
            break
        else:  # ( len(A_list) - 1 - arrived_idx ) == 0:
            break


    print(comfort)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31304
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int a = Integer.parseInt(sc.next());
	int b = Integer.parseInt(sc.next());
	int c = Math.min(n*a,b);
	System.out.println(c);
}
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  deque<int> deq;
  bool rev = false;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (rev) {
      deq.push_back(a);
    } else {
      deq.push_front(a);
    }
    rev ^= 1;
  }
  if (!rev) {
    reverse(deq.begin(), deq.end());
  }
  for (auto i = deq.begin(); i != deq.end(); i++) {
    if (i != deq.begin()) cout << " ";
    cout << *i;
  }
  cout << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int N, T;

    cin >> N;
    cin >> T;
    
    int c[N];
    int t[N];
    for (int i = 0; i < N; i++) {
        cin >> c[i];
        cin >> t[i];
    }
    int min = 1001;
    for (int i = 0; i < N; i++) {
        if (t[i] <= T)
            if (min >= c[i])
                min = c[i];
    }
    if (min == 1001) cout << "TLE";
    else cout << min;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()) {
      char gene = in.next().charAt(0);
      char pair = ' ';

      switch(gene) {
        case 'A':
          pair = 'T';
          break;
        case 'C':
          pair = 'G';
          break;
        case 'G':
          pair = 'C';
          break;
        case 'T':
          pair = 'A';
          break;
      }

      System.out.println(pair);
    }
  }
}

Measured memory_bytes: 21204
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe

main :: IO ()
main = do
    -- 文字列の入力
    s <- sort <$> getLine
    -- 出力
    putStrLn . show $ length (takeWhile (== 'g') s) - ((length s + 1) `div` 2)


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

int main(){
  string s1,s2;
  cin >> s1 >> s2;
  rep(i,0,s1.size()){
    if(s1[i]!=s2[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<cstdio>  
#include<iostream>  
#include<cstring>  
#include<algorithm>  
#include<vector>  
using namespace std;  
const int maxn = 100007;  
int f[maxn],d[maxn];  
int n,m,l,r,v;  
int find(int x)  
{  
    if(x==f[x])return x;  
    int now = f[x];  
    f[x]=find(f[x]);  
    d[x]=d[x]+d[now];  
    return f[x];  
}  
int main()  
{  
    scanf("%d %d",&n,&m);  
    int ok = 1;  
    for(int i=1;i<=n;i++)f[i]=i;  
    for(int i=1;i<=m;i++)  
    {  
        scanf("%d %d %d",&l,&r,&v);  
        int fl = find(l);  
        int fr = find(r);  
        if(fl==fr)  
        {  
            if(d[l]-d[r]!=v)ok = 0;  
        }  
        else  
        {  
            f[fl]=fr;  
            d[fl]=v+d[r]-d[l];  
        }  
    }  
    if(ok)cout<<"Yes"<<endl;  
    else cout<<"No"<<endl;  
    return 0;  
}  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// for(long long i = 0;i < num; i++){}
int main() {
    //
    int n, m;
    int cnt = 0;

    cin >> n >> m;

    vector<vector<int>> vec(m);
    vector<int> power(m);

    for (int i = 0; i < m; i++) {
        int x, tmp;
        cin >> x;
        for (int j = 0; j < x; j++) {
            cin >> tmp;
            tmp--;
            vec.at(i).push_back(tmp);
        }
    }

    for (int i = 0; i < m; i++) cin >> power.at(i);

    for (int bit = 0; bit < (1 << n); bit++) {
        bool chk = true;

        for (int i = 0; i < m; i++) {
            int tmpCnt = 0;
            //for (int j = 0; j < vec.at(i).size(); j++) {
                for(auto j : vec[i]){
                if (bit & (1 << j)) tmpCnt++;
            }

            if (tmpCnt % 2 != power.at(i)) chk = false;
        }

        if (chk == true) cnt++;
    }

    cout << cnt;
    //
}


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

int main() {
  ll a, b, k; cin >> a >> b >> k;
  if (a>k) cout << a-k << " " << b << endl;
  else if(b>k-a) cout << 0 << " " << b-(k-a) << endl;
  else cout << 0 << " " << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, M;
bool cannot[100001];
int dp[100001];

signed main() {
	cin >> N >> M;
	for(int i = 0; i < M; ++i) {
		int a;
		cin >> a;
		cannot[a] = true;
	}
	if(!cannot[1]) dp[1] = 1;
	if(!cannot[2]) dp[2] = dp[1] + 1;
	for(int i = 3; i <= N; ++i) {
		if(cannot[i]) continue;
		dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
	}
	cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1152
using System;
class A{
  public static void Main(){
    var sum = 0;
    var max = 0;
    var n = int.Parse(Console.ReadLine());
    for (int i = 0; i <n ; i++)
    {
      var a = int.Parse(Console.ReadLine());
      sum += a;
      if (a > max) max = a;
    }
    Console.WriteLine(sum - max / 2);
  }
}

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

int main(){
    int x_min(0),x_max(0),y_min(0),y_max(0);
    int x,y;    cin >> x >> y;
    int side[35];
    side[0] = 1;    side[1] = 1;

    for(int i=2;i<35;i++){
        side[i] = side[i-1] + side[i-2];
    }

    int i(1);
    while(1){
        if(x_min<=x && x<=x_max && y_min<=y && y<=y_max){
            if(i%3==0)
                cout << 3 << endl;
            else
                cout << i%3 << endl;
            
            break;
        }else{
            switch (i%4){
            case 0:
                y_min -= side[i];
                break;

            case 1:
                x_max += side[i];
                break;

            case 2:
                y_max += side[i];
                break;
            
            case 3:
                x_min -= side[i];
            
            default:
                break;
            }

            i++;
        }
    }
}


Measured memory_bytes: 3088
if __name__ == '__main__':
    S = input()
    n = len(S)
    l_res = [0]
    r_res = [0]
    for i in range(n):
        if S[i] == '<':
            l_res.append(l_res[i] + 1)
        else:
            l_res.append(0)
    inv_S = S[::-1]

    for i in range(n):
        if inv_S[i] == '>':
            r_res.append(r_res[i] + 1)
        else:
            r_res.append(0)
    res = 0
    for l_cnt, r_cnt in zip(l_res, r_res[::-1]):
        res += max(l_cnt, r_cnt)
    print(res)
    

Measured memory_bytes: 153448
a=gets.chomp
# 取得した値を標準出力するために"XXXXXX"をどう書き換える？
b=a.reverse

if a==b
    c=a[0..(a.length-1)/2-1]
    d=a[0..(a.length-1)/2-1]
    
    if c==c.reverse&&d==d.reverse
        puts "Yes"
    else puts "No"
    end
else puts "No"
end

Measured memory_bytes: 3836
from collections import Counter

n,m = map(int,input().split())
A = list(map(int,input().split()))

B = [0]
res = 0
for a in A:
	res += a
	B.append(res%m)

C = Counter(B)
ans = 0
for c in C.values():
	ans += c*(c-1)//2

print(ans)

Measured memory_bytes: 16552
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

LL n, k;
V<LL> a;

template<typename T> bool judge(T x) {
	bool ans;

	LL cnt = 0;
	RBF(i, a) {
		LL tmp = ceil(static_cast<double>(i) / x) - 1;
		cnt += tmp;
	}
	if (cnt > k) {
		ans = false;
	}
	else {
		ans = true;
	}

	return ans;
}
// 範囲[a, b]の連続する整数のなかで，judge(x)=trueとなる最小のxを二分探索で求める
template<typename T> T bin_search_min(T a, T b) {
	if (a > b) {
		return bin_search_min(b, a);
	}

	T x = b;
	T d = max(static_cast<T>(1), (b - a) / 2 + (b - a) % 2);
	T cnt = 0;
	T lim = log2(b - a) + 10;

	while (cnt < lim) {
		if (judge(x)) {
			x -= d;
		}
		else {
			x += d;
		}
		if (x < a) {
			x = a;
			if (judge(x)) {
				break;
			}
		}
		if (x > b) {
			x = b;
			if (!judge(x)) {
				break;
			}
		}
		d = d / 2 + d % 2;
		cnt++;
	}

	if (x < a) {
		x = a;
	}
	while(!judge(x) && x <= b) {
		x++;
	}

	// x > bならjudge(x)=trueとなるxが存在しなかったことを意味する
	return x;
}

signed main() {
	cin >> n >> k;
	a = V<LL>(n);
	LL b = 0;
	REP(i, n) {
		LL tmp;
		cin >> tmp;
		a[i] = tmp;
		b = max(b, tmp);
	}

	LL ans = bin_search_min(1ll, b);
	col(ans);
	return 0;
}

Measured memory_bytes: 4768
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
template <typename T>
void greater_sort(vector<T>& vec) {
	sort(all(vec), greater<T>());
	return;
}

int a, b, c, d;
int cnt1, cnt2, cnt3;
signed main() {
	cin >> a >> b >> c >> d;
	cnt1 = b / c - a / c;
	if (a % c == 0) cnt1++;
	cnt2 = b / d - a / d;
	if (a % d == 0) cnt2++;
	cnt3 = b / lcm(c, d) - a / lcm(c, d);
	if (a % lcm(c, d) == 0) cnt3++;
	cout << b - a + 1 - cnt1 - cnt2 + cnt3 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigInteger;
import java.io.PrintWriter;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    long a = Long.parseLong(str[0]);
    long b = Long.parseLong(str[1]);
    
    long min = a<b?a:b;
    long max = a>b?a:b;
    
    for(long i=1; i<=max; i++) {
      if(min*i%max==0) {
        System.out.println(min*i);
        break;
      }
    }
  }
}

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

class MaxFlow {
public:
  struct edge { int to, cap, rev; };

  const int INF = 1 << 28;
  int N;
  vector<vector<edge>> E;
  vector<int> level;
  vector<int> iter;

  MaxFlow(int N): N(N), E(N), level(N), iter(N) {}

  void add_edge(int from, int to, int cap) {
    E[from].push_back((edge) { to, cap, (int) E[to].size() });
    E[to].push_back((edge) { from, 0, (int) E[from].size() - 1 });
  }

  void bfs(int s) {
    for (int i = 0; i < N; i++) level[i] = -1;
    level[s] = 0;

    queue<int> q;
    q.push(s);

    while (!q.empty()) {
      int v = q.front();
      q.pop();

      for (int i = 0; i < E[v].size(); i++) {
        edge &e = E[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < E[v].size(); i++) {
      edge &e = E[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          E[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (1) {
      bfs(s);
      if (level[t] < 0) break;
      for (int i = 0; i < N; i++) iter[i] = 0;
      while (1) {
        int f = dfs(s, t, INF);
        if (f == 0 || f == INF) break;
        flow += f;
      }
    }
    return flow;
  }
};

int main(void) {
  ll N, M;
  cin >> N >> M;
  string U;
  cin >> U;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];
  vector<ll> S(M), T(M), B(M);
  REP(i, 0, M) cin >> S[i] >> T[i] >> B[i], S[i]--, T[i]--;

  MaxFlow mf(N + 2);
  ll s = N, t = N + 1;

  REP(i, 0, N) {
    if (U[i] == 'L') {
      mf.add_edge(s, i, 0);
      mf.add_edge(i, t, A[i]);
    }
    if (U[i] == 'R') {
      mf.add_edge(s, i, A[i]);
      mf.add_edge(i, t, 0);
    }
  }

  REP(i, 0, M) {
    if (S[i] > T[i]) swap(S[i], T[i]);
    mf.add_edge(S[i], T[i], B[i]);
  }

  cout << mf.max_flow(s, t) << endl;
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int K,N;
    cin >> N >> K;
    int A[N];
    rep(i,N) {
        cin >> A[i];
    }
    int ans=(N+K-3)/(K-1);
    cout << ans << endl;




}


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

// ---- ----

LL n, a[200000], dp[200001][5], INF = 1e15;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc1(i, n) {
	inc(j, 5) {
		dp[i][j] = INF;
	}
	}
	
	inc(i, n) {
		dp[i + 1][0] = dp[i][0] + a[i];
		dp[i + 1][1] = dp[i][1] + (a[i] % 2 == 1 ? 1 : 0) + (a[i] == 0 ? 2 : 0);
		dp[i + 1][2] = dp[i][2] + (a[i] % 2 == 0 ? 1 : 0);
		dp[i + 1][3] = dp[i][3] + (a[i] % 2 == 1 ? 1 : 0) + (a[i] == 0 ? 2 : 0);
		dp[i + 1][4] = dp[i][4] + a[i];
		
		inc(j, 4) { setmin(dp[i + 1][j + 1], dp[i + 1][j]); }
	}
	
	cout << dp[n][4] << endl;
	
	return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(abs(a-c)<=d || (abs(b-a)<=d&&abs(c-b)<=d)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	vector<vector<bool>> c(h, vector<bool>(w, false));
	rep(snip_i, h) cin >> a.at(snip_i);
	int x, y;
	x = y = 0;
	int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	while(1){
		int nx_i = -1;
		rep(i, 4){
			int nx, ny;
			nx = x + dx[i];
			ny = y + dy[i];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(a.at(ny)[nx] == '#' && c.at(ny).at(nx) == false){
				if(i == 2 || i == 3){
					cout << "Impossible" << endl;
					return 0;
				}else{
					if(nx_i == -1) nx_i = i;
					else{
						cout << "Impossible" << endl;
						return 0;
					}
				}
			}
		}
		int nx = x + dx[nx_i], ny = y + dy[nx_i];
		c.at(y).at(x) = true;
		if(x == w-1 && y == h-1) break;
		x = nx; y = ny;
	}
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
map<int, int>dp;
int fib(int N) {
   if (N == 0 || N == 1) {
       return 1;
   } else if (dp.count(N) > 0) {
        return dp[N];
    }

    int ans = fib(N-1) + fib(N-2);
    dp[N] = ans;
    return ans;
}
int main() {
    int N;
    cin >> N;
    dp[0] = 1;
    dp[1] = 1;
    cout << fib(N) << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int findSum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
  return sum;
}

int main(){
    int N;
    cin>>N;
    
  	if(N%findSum(N)==0)cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
}

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

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> a(3);
   rep(i,3) cin >> a[i];
   string t;
   cin >> t;

   vector<int> ctoi(256);

   ctoi['r'] = 2;
   ctoi['s'] = 0;
   ctoi['p'] = 1;
   int ans=0;
   
   rep(i,k){
      vector<int> x;
      for(int j=i;j<n;j+=k){
         x.push_back(ctoi[t[j]]);
      }
      vector<int> dp(2);
      int pre = -1;
      for (int nx : x){
         vector<int> p(2);
         swap(dp,p);
         dp[0] = max(p[0],p[1]);
         if (pre == nx){
            dp[1] = p[0]+a[nx];
         }else {
            dp[1] = max(p[0],p[1])+a[nx]; 
         }
         pre = nx;
      } 
      ans += max(dp[0],dp[1]);
   }
   cout << ans << endl;
   return 0;  
}

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
ll a,v,b,w,t;
cin>>a>>v>>b>>w>>t;
if(w>=v)
{
	ol("NO");
	return 0;
}
ld x=abs(a-b);
x/=ld(v-w);
if(x>ld(t))
{
	ol("NO");
}
else
{
	ol("YES");
}
return 0;
}



Measured memory_bytes: 3652