akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef vector<Point> Polygon;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a, b) < -EPS) return CLOCKWISE;
    if(dot(a, b) < -EPS) return ONLINE_BACK;
    if(norm(a) < norm(b)) return ONLINE_FRONT;

    return ON_SEGMENT;
}

Point getCrossPointLL(Line l1, Line l2){
    double a = cross(l1.second - l1.first, l2.second - l2.first);
    double b = cross(l1.second - l1.first, l1.second - l2.first);
    if(abs(a) < EPS && abs(b) < EPS) return l2.first;
    return l2.first + (l2.second - l2.first) * (b / a);
}

Polygon convexCut(Polygon pol, Line l){
    Polygon q;
    int n = pol.size();
    for(int i=0; i<n; i++){
        Point a = pol[i];
        Point b = pol[(i+1)%n];
        if(ccw(l.first, l.second, a) != CLOCKWISE) q.emplace_back(a);
        if(ccw(l.first, l.second, a) * ccw(l.first, l.second, b) < -EPS){
            q.emplace_back(getCrossPointLL(Line(a, b), l));
        }
    }

    return q;
}

double convexArea(Polygon pol){
    int n = pol.size();
    double S = 0;
    for(int i=0; i<n; i++){
        S += cross(pol[i], pol[(i+1)%n]);
    }

    return S / 2;
}

int solve(Polygon pol){
    Polygon ps;
    ps.emplace_back(0, 0);
    ps.emplace_back(10000, 0);
    ps.emplace_back(10000, 10000);
    ps.emplace_back(0, 10000);

    int n = pol.size();
    for(int i=0; i<n; i++){
        ps = convexCut(ps, Line(pol[i], pol[(i+1)%n]));
    }

    if(convexArea(ps) < EPS) return 0;
    else return 1;
}

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        Polygon pol;
        for(int i=0; i<n; i++){
            double x, y; cin>>x>>y;
            pol.emplace_back(x, y);
        }

        cout << solve(pol) << endl;
    }
}


Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  vector<ll> a(n);

  ll ans = 0;
  REP(i, n) {
    cin >> a[i];
    ans = max(a[i], ans);
  }

  ll l = 0, r = INF + 1;
  while(r - 1 > l) {
    ll t = 0;
    ll mid = (l + r) / 2;
    REP(i, n) {
      if(a[i] % mid) t += a[i] / mid;
      else t += a[i] / mid - 1;
    }
    if(t <= k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  ans = min(ans, r);
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q), b(Q), c(Q), d(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    vector<int>vec(N+M-1, 1);
    for (int i = 0; i < M-1; ++i) vec[i] = 0;
    int ans = 0;
    do {
        int zero_cnt = 0;
        int score = 0;
        vector<int> A;
        for (int i = 0; i < N+M-1; ++i) {
            if (vec[i] == 0) zero_cnt++;
            else A.push_back(zero_cnt + 1);
        } 
        for (int i = 0; i < Q; ++i) {
            if (A[b[i]] - A[a[i]] == c[i]) score += d[i];
        }
        ans = max(ans, score);
    } while (next_permutation(vec.begin(), vec.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
    char n[10];
    gets(n);
    if((n[0]==n[1] && n[1]==n[2]) || (n[1]==n[2] && n[2]==n[3]))
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    
    return 0;
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (B == C) {
		cout << A << endl;
	}
	else if (A == C) {
		cout << B << endl;
	}
	else {
		cout << C << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
int factorial(int n);
int factorial(int n)
{
    if(n==1)
    {
        return 1;
    }
    else
    {
        return n*factorial(n-1);
    }

}

bool is_prime(ll n) {
    // Assumes that n is a positive natural number
    // We know 1 is not a prime number
    if (n == 1) {
        return false;
    }

    ll i = 2;
    // This will loop from 2 to int(sqrt(x))
    while (i*i <= n) {
        // Check if i divides x without leaving a remainder
        if (n % i == 0) {
            // This means that n has a factor in between 2 and sqrt(n)
            // So it is not a prime number
            return false;
        }
        i += 1;
    }
    // If we did not find any factor in the above loop,
    // then n is a prime number
    return true;
}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
typedef unsigned long long  ull;

int check(int x,vector <int> a,int n)
{  int county=0;
  map <int,int> mapa;
    for(int i=0;i<n;i++)
    {
        mapa.insert(pair<int,int>(a[i],0));
    }
    for(int i=0;i<n;i++)
    {
        mapa[a[i]]++;
    }
   // cout<<mapa[1]<<mapa[2]<<mapa[3]<<mapa[4]<<mapa[5]<<endl;
    for(int i=0;i<a.size();i++)
    {   mapa[a[i]]--;
        if(mapa[abs(a[i]-x)]>0)
        {
            county++;


            mapa[abs(a[i]-x)]--;
        }


    }
    return county;
}

typedef unsigned int ui;

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

float d,t,s;
cin>>d>>t>>s;
if(d/s<=t)
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}
}

Measured memory_bytes: 3792
def main():
  n,a,b = map(int,input().split())
  MOD = 10 ** 9 + 7
  ans = pow(2,n,MOD) - 1
  P = 1
  F = 1

  for i in range(1,b + 1):
    P = P * (n - i + 1) % MOD #P!
    F = F * i % MOD  # i! 
    if i == a or i == b:
      #Fの逆元のmodをとる
      ans -= P * pow(F,MOD - 2,MOD)
  
  print(ans % MOD)

main()


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

int main(void){
  int n;
  std::string s;
  std::cin >> n >> s;

  int number = 0;
  int max_number = 0;
  for(int i=0; i<n; i++){
    if(s[i] == 'I'){
      number++;
      max_number = max_number<number?number:max_number;
    }else if(s[i] == 'D'){
      number--;
    }
  }

  std::cout << max_number << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	V<ll> x(N),y(N);
	rep(i,N) cin >> x[i] >> y[i];
	int ans = N;
	rep(i,N) rep(j,N) if(i!=j){
		ll X = x[i]-x[j], Y = y[i]-y[j];
		int score = N;
		rep(a,N) rep(b,N) if(x[a]-x[b] == X && y[a]-y[b] == Y) score--;
		chmin(ans,score);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, w; cin >> n >> w;
    vector<pair<ll, ll>> wv(n+1);
    repf(i, n) cin >> wv[i].first >> wv[i].second;
    vector<vector<ll>> dp(n+1, vector<ll>(1000*n+1, INFLL/2));
    rep(i, dp.size()) dp[i][0] = 0;

    // i番目までの品物を含められる場合に、価値j以下を達成しうる最小の重さ
    repf(i, n){
        rep(j, dp[i].size()){
            if(j-wv[i].second >= 0) dp[i][j] = min(dp[i-1][j], dp[i-1][j-wv[i].second]+wv[i].first);
            else dp[i][j] = dp[i-1][j];
        }
    }

    // i番目までの品物を含められる場合に、重さがw以下の最大価値を出力
    for(ll i=dp[n].size()-1; i>=0; i--){
        if(dp[n][i] <= w){
            cout << i << endl;
            return 0;
        }
    }
}

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

using i64 = int64_t;

int main(){
    int n, m;
    cin >> n >> m;
    string str;
    for(int i=0;i<n;++i)str += '?';
    bool ok = true;
    for(int i=0;i<m;++i){
        int s, c;
        cin >> s >> c;
        if(n != 1 && s == 1 && c == 0)ok = false;
        if(str[s-1] != '?' && str[s-1] != (char)('0'+c))ok = false;
        str[s-1] = (char)('0'+c);
    }

    for(int i=0;i<n;++i){
        if(str[i] == '?'){
            if(n != 1 && i == 0)str[i] = '1';
            else str[i] = '0';
        }
    }

    if(ok)cout << str << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
typedef pair<int, int> P;
const double EPS = 1e-11;
int k;
double r, l, p, e, t, pp;

int inside(double nr, double nl){
    if(t - e - EPS < nr && nl < t + e + EPS) return 1; // in
    if(nl < t - e + EPS || t + e - EPS < nr) return 0; // out
    return 2; // cross
}

void dfs(double nowr, double nowl, double nowp, int step){
    int res = inside(nowr, nowl);
    if(step == k){
        double mid = (nowr + nowl) / 2.0;
        if(t - e - EPS < mid && mid < t + e + EPS) pp += nowp;
        return;
    }
    if(res == 1) pp += nowp;
    if(res == 2){
        double mid = (nowr + nowl) / 2.0;
        if(mid < t - EPS){
            dfs(mid, nowl, nowp * p, step + 1);
            dfs(nowr, mid, nowp * (1.0 - p), step + 1);
        }else{
            dfs(mid, nowl, nowp * (1.0 - p), step + 1);
            dfs(nowr, mid, nowp * p, step + 1);
        }
    }
}

int main(){
    cin >> k >> r >> l >> p >> e >> t;
    p = 1.0 - p;
    dfs(r, l, 1.0, 0);
    printf("%.12f\n", pp);
}


Measured memory_bytes: 3236
#include <stdio.h>
 
int main(void){
    char s[100+1];
    char ss[100*2+1];
    char p[100+1];
     
    scanf("%s", s);
    scanf("%s", p);
     
    strcpy(ss, s);
    strcpy(ss+strlen(s), s);
     
    if(strstr(ss, p) != NULL){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
     
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int l[200005], r[200005];
pii p[200005];
int ft[200005];
void update(int i, int v){
    for(;i<=200000;i+=(i&-i)) ft[i] += v;
}
int query(int i){
    int res = 0;
    for(;i>0;i-=(i&-i)) res+=ft[i];
    return res;
}

int n, m;
void assign(int r){
    int lo = r, hi = m, idx = -1;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        int le = mid-r+1;
        if(query(mid) - query(r-1) != le) idx = mid, hi = mid-1;
        else lo = mid+1;
    }
    update(idx, 1);
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &l[i], &r[i]);
        p[i] = pii(l[i], r[i]);
    }   
    sort(p+1, p+1+n);
    int ans = 0;
    int L = 0;

    multiset<int> ms;
    for(int i=1;i<=n;i++){
        int l = p[i].fi, r = p[i].se;
        if(l == 0){
            if(r == m+1) ans++;
            else{
                int le = m-r+1;
                int q = query(m) - query(r-1);
                if(q == le){
                    ms.insert(r);
                    ans++;
                }
                else assign(r);
            }
        }
        else{
            if(L < l){
                int r2 = L+1;
                if(query(r2) - query(r2-1) == 1){
                    int le = m-r2+1;
                    int q = query(m) - query(r2-1);
                    if(q == le){
                        ans++;
                        continue;
                    }
                    else{
                        update(r2, -1);
                        assign(r2+1);
                    }
                }
                L++;
                ms.insert(r);
                update(L, 1);
            }
            else{
                ms.insert(r);
                int r2 = *ms.upper_bound(L);

                int le = m-r2+1;
                int q = query(m) - query(r2-1);
                if(q == le){
                    ans++;
                    continue;
                }
                else{
                    assign(r2);
                    ms.erase(ms.find(r2));
                }
            }
        }
    }
    printf("%d\n", ans);
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

int dp[200][5][5][5];

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

    Int(n);

    dp[0][0][0][0] = 1;
    dp[1][0][0][0] = 1;
    dp[2][0][0][0] = 1;

    for (int i = 2; i < n + 2; i++) {
        for (int a = 0; a < 5; a++) {
            for (int b = 0; b < 5; b++) {
                for (int c = 0; c < 5; c++) {
                    for (int d = 1; d < 5; d++) {
                        if (b == 1 && c == 3 && d == 2) continue;
                        if (b == 1 && c == 2 && d == 3) continue;
                        if (b == 3 && c == 1 && d == 2) continue;
                        if (a == 1 && b == 3 && d == 2) continue;
                        if (a == 1 && c == 3 && d == 2) continue;
                        dp[i+1][b][c][d] = 
                            (dp[i+1][b][c][d] + dp[i][a][b][c]) % MOD;
                    }
                }
            }
        }
    }

    /*
    rep(i, n + 4) {
        rep(a, 5) {
            cout << "a : " << a << endl;
            rep(b, 5) {
            cout << "b : " << b << endl;
                rep(c, 5) {
                    std::cout << dp[i][a][b][c] << " ";
                }
                cout << endl;
            }
        }
    }
    */

    int ans = 0;
    rep(a, 5) rep(b, 5) rep(c, 5) 
        ans = (ans + dp[n+2][a][b][c]) % MOD;

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 384
import qualified Data.Vector.Unboxed as V
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

main = do
  [n,k] <- getIntList
  p <- V.fromList . map (+(-1)) <$> getIntList
  c <- V.fromList <$> getIntList
  let acc i = scanl1 (+) $ map ((c V.!).(p V.!)) $ takeWhile (/=i) (iterate (p V.!) (p V.! i)) ++ [i] -- O(n)
      ans i = -- O(n)
        if val > 0
          then
            if rem /= 0
              then num * val + maximum (take (fromIntegral rem) list)
              else (num-1) * val + maximum list
          else maximum list
        where list = acc i
              val = last list
              len = fromIntegral $ length list
              num = k `div` len
              rem = k `mod` len
  print $ maximum $ map ans [0..n-1] -- n * O(n) = O(n^2)


Measured memory_bytes: 8196
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    String s = scanner.next();
    if (possible(s.toCharArray(), 0)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  private static boolean possible(char[] str, int index) {
    if (index == str.length) return true;
    if (compare(str, index, "dreamer".toCharArray())) {
      return possible(str, index + 5) || possible(str, index + 7);
    }
    if (compare(str, index, "eraser".toCharArray())) return possible(str, index + 6);
    if (compare(str, index, "dream".toCharArray()) || compare(str, index, "erase".toCharArray())) return possible(str, index + 5);
    return false;
  }

  private static boolean compare(char[] str, int index, char[] target) {
    int i = 0;
    while (i < target.length && index + i < str.length && str[index + i] == target[i]) i++;
    return i == target.length;
  }
}


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

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			int N = Integer.parseInt(br.readLine());
			String[] input_S = new String[N];
			int[] array_S = new int[N];

			input_S = br.readLine().split("\\s+");
			for(int i = 0; i < N; i++){
				array_S[i] = Integer.parseInt(input_S[i]);
			}

			int Q = Integer.parseInt(br.readLine());
			String[] input_T = new String[Q];
			int tmp,ans = 0;

			input_T = br.readLine().split("\\s+");
			for(int i = 0; i < Q; i++){
				tmp = Integer.parseInt(input_T[i]);
				for(int k = 0; k < N; k++){
					if(tmp == array_S[k]){
						ans++;
						break;
					}
				}
			}

			System.out.println(ans);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}




Measured memory_bytes: 30516
import scala.collection.immutable.Stack
import scala.io.StdIn._

object Main extends App {
  Stream
    .continually(readLine)
    .takeWhile(_ != null)
    .map(_.toInt)
    .foldLeft(Stack.empty[Int]) {
      case (stack, h) =>
        if (h == 0) stack.pop2 match {
          case (e, tail) => println(e); tail
        } else stack.push(h)
    }
}


Measured memory_bytes: 43852
#include <stdio.h>

int main(void)
{
  int a[200],b[200],c;
  int n=0,i=0,j=0,k,l=0,max=4;
  int hit = 0, blow = 0;

  while((n < 50) && 
         scanf("%d%d%d%d",&a[i],&a[i+1],&a[i+2],&a[i+3]) != EOF){
    scanf("%d%d%d%d",&b[i],&b[i+1],&b[i+2],&b[i+3]);
    i+= 4;
    n++;
  } 

  for(k=0; k<n; k++){
    hit = blow = 0;
    while(l < max){
      while(j < max){
        if(a[l] == b[j]){
          if(l == j){
	     hit += 1;
          }else{
             blow += 1;
          }
        }
	j++;
      }
      j = max - 4;
      l++;
    } 
    l = j = max;
    max += 4;
    printf("%d %d\n",hit,blow);
  }

  return 0;
}

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

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

using ll = long long;

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  vector<vector<char>> vv(N, vector<char>(2));
  vector<vector<char>> vw(N, vector<char>(2));
  for(int i = 0; i < N; i++) {
    vv.at(i).at(0) = S.at(i);
    vv.at(i).at(1) = T.at(i);
    vw.at(i).at(1) = S.at(i);
    vw.at(i).at(0) = T.at(i);
  }
  bool can = true;
  sort(vv.begin(), vv.end());
  sort(vw.begin(), vw.end());
  for(int i = 0; i < N-1; i++) {
    if(vv.at(i).at(0) == vv.at(i+1).at(0) && vv.at(i).at(1) != vv.at(i+1).at(1)) can=false;
    if(vw.at(i).at(0) == vw.at(i+1).at(0) && vw.at(i).at(1) != vw.at(i+1).at(1)) can=false;
    if(!can) break;
  }
  if(can) cout<<"Yes"<<endl;
  if(!can) cout<<"No"<<endl;
}
  
  

Measured memory_bytes: 22536
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
 
class Car{
public:
  int id, in_time, rem_time;
  Car(){}
  Car(int a, int b, int c): id(a), in_time(b), rem_time(c){}
};
 
const int INF = (1<<28);
 
int m, n;
queue<Car> que;
Car pa[20];
vector<int> ans;
 
void init(){
  for(int i=0;i<m*2;i++) pa[i] = Car(-1, -1, -1);
  while(!que.empty()) que.pop();
  ans.clear();
}
 
bool is_full(){
  for(int i=0;i<m*2;i++) if(pa[i].id == -1) return false;
  return true;
}

void put_in(int t){
  while(!que.empty()){
    Car c = que.front();
    if(c.in_time > t || is_full()) break;
    int pos = -1;
    for(int i=1;i<m*2;i+=2){
      if(pos == -1 && pa[i].id == -1 && pa[i-1].id == -1) pos = i;
    }
    if(pos != -1){
      pa[pos] = c;
      que.pop();
      continue;
    }
    int valm = INF;
    pos = -1;
    for(int i=0;i<m*2;i+=2){
      if(pa[i].id != -1) continue;
      if(pa[i+1].rem_time >= c.rem_time){
        if(valm > abs(pa[i+1].rem_time - c.rem_time)){
          valm = abs(pa[i+1].rem_time - c.rem_time);
          pos = i;
        }
      }
    }
    if(pos != -1){
      pa[pos] = c;
      que.pop();
      continue;
    }
    valm = INF;
    pos = -1;
    for(int i=0;i<m*2;i+=2){
      if(pa[i].id != -1) continue;
      if(valm > abs(pa[i+1].rem_time - c.rem_time)){
        valm = abs(pa[i+1].rem_time - c.rem_time);
        pos = i;
      }
    }
    if(pos != -1){
      pa[pos+1].rem_time = c.rem_time;
      pa[pos] = c;
      que.pop();
      continue;
    }
  }
}

void put_out(int t){
  while(1){
    int valm = INF;
    int ex_pos = -1;
    for(int i=0;i<m*2;i++){
      if(pa[i].id == -1) continue;
      if(pa[i].rem_time > 0) continue;
      if(valm > pa[i].rem_time){
        valm = pa[i].rem_time;
        ex_pos = i;
      }
    }
    if(ex_pos == -1) break;
    ans.push_back(pa[ex_pos].id);
    pa[ex_pos] = Car(-1, -1, -1);
  }
}

void print(){
  for(int i=0;i<m*2;i++){
    cout << pa[i].id << ' ';
  }
  cout << endl;
}

bool is_empty(){
  for(int i=0;i<m*2;i++) if(pa[i].id != -1) return false;
  return true;
}

main(){
  while(cin >> m >> n && (m|n)){
    init();
    for(int i=0;i<n;i++){
      Car in = Car(i+1, i*10, 0);
      cin >> in.rem_time;
      que.push(in);
    }
    for(int t=0;;t+=1){
      //cout << t << endl;
      //print();
      if(t > 0 && is_empty()) break;
      for(int i=0;i<m*2;i++){
        if(pa[i].id == -1) continue;
        pa[i].rem_time -= 1;
      }
      put_out(t);
      put_in(t);
    }
    cout << ans[0];
    for(int i=1;i<ans.size();i++) cout << " " << ans[i];
    cout << endl;
  }
}

Measured memory_bytes: 1220
n = int(input())
previous_t = 0
ans = "Yes"
for i in range(n):
    t, x, y = list(map(int, input().split()))
    if x + y > t:
        ans = "No"
        break
    if (x + y) % 2 != t % 2:
        ans = "No"
        break
    if previous_t > 0 and (abs(x - previous_x) + abs(y - previous_y) > (t - previous_t)):
        ans = "No"
        break
    previous_t = t
    previous_x = x
    previous_y = y

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include<iostream>
#include<string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <map>
#include <cstring>
using namespace std;
int a[200005];
int k, n;
int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int l = 1, r = 1000000000;
    while (l <= r) {
        if (l == r) break;
        int mid = (l + r) / 2;
        long long cnt = 0;
        for (int i = 1; i <= n; i++) cnt += a[i] / mid + (a[i] % mid > 0) - 1;
        if (cnt <= k) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", l);
    return 0;
}

Measured memory_bytes: 4452
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <functional>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
int N, bob, alice;
int a[100];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a, a + N, greater<int>());
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<cmath>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mkp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010,mod=1e9+7;
int p[N],sz[N];
int n,m;
int find(int x)
{
    if(x!=p[x]) p[x]=find(p[x]);
    return p[x];
}
int main()
{
    //IO;
    cin>>n>>m;
    for(int i=1;i<=n;i++) p[i]=i,sz[i]=1;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        int pa=find(a),pb=find(b);
        if(pa!=pb)
        {
            p[pa]=pb;
            sz[pb]+=sz[pa];
        }
    }
    int res=0;
    for(int i=1;i<=n;i++)   
        if(i==p[i]) res=max(res,sz[i]);
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 5188
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

n=I()
a=LI()
m,M=min(a),max(a)
n_m=a.count(m)
n_M=a.count(M)

if m+1<M:
    ans=1
elif m+1==M:
    if n_M//2+n_m>=m+1>=n_m+1:
        ans=0
    else:
        ans=1
else:
    if m==n-1 or m<=n//2:
        ans=0
    else:
        ans=1

print(YN[ans])


Measured memory_bytes: 53112
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>

using namespace std;

typedef struct datum_name {
	int x;
	int y;
	int whosay;
	bool operator==(const datum_name& data) const
	{
		return (x == data.x && y == data.y);
	}
} datum;


bool cmp_who(const datum& left, const datum& right) {
	return left.whosay < right.whosay;
}

typedef vector<vector<int>> Graph;
vector<bool> seen;
vector<int> depth;

void dfs(const Graph& G, int v, int depth_num) {
	seen[v] = true;
	depth[v] = depth_num;

	for (auto next_v : G[v]) {
		if (seen[next_v]) continue;
		dfs(G, next_v, depth_num+1); //再帰探索
	}
}

int count_char(char& S) {
	if (S == 'A') return 1;
	if (S == 'B') return 2;
	if (S == 'C') return 3;
	if (S == 'D') return 4;
	if (S == 'E') return 5;
	if (S == 'F') return 6;
	if (S == 'G') return 7;
	if (S == 'H') return 8;
	if (S == 'I') return 9;
	if (S == 'J') return 10;
	if (S == 'K') return 11;
	if (S == 'L') return 12;
	if (S == 'M') return 13;
	if (S == 'N') return 14;
	if (S == 'O') return 15;
	if (S == 'P') return 16;
	if (S == 'Q') return 17;
	if (S == 'R') return 18;
	if (S == 'S') return 19;
	if (S == 'T') return 20;
	if (S == 'U') return 21;
	if (S == 'V') return 22;
	if (S == 'W') return 23;
	if (S == 'X') return 24;
	if (S == 'Y') return 25;
	if (S == 'Z') return 26;
	return 0;
}

char get_char(int& input) {
	if (input == 1) return 'A';
	if (input == 2) return 'B';
	if (input == 3) return 'C';
	if (input == 4) return 'D';
	if (input == 5) return 'E';
	if (input == 6) return 'F';
	if (input == 7) return 'G';
	if (input == 8) return 'H';
	if (input == 9) return 'I';
	if (input == 10) return 'J';
	if (input == 11) return 'K';
	if (input == 12) return 'L';
	if (input == 13) return 'M';
	if (input == 14) return 'N';
	if (input == 15) return 'O';
	if (input == 16) return 'P';
	if (input == 17) return 'Q';
	if (input == 18) return 'R';
	if (input == 19) return 'S';
	if (input == 20) return 'T';
	if (input == 21) return 'U';
	if (input == 22) return 'V';
	if (input == 23) return 'W';
	if (input == 24) return 'X';
	if (input == 25) return 'Y';
	if (input == 26) return 'Z';
	return 'Z';
}

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

	string S;
	cin >> S;

	for (unsigned int i = 0; i < S.size(); i++ ) {
		int tmp = count_char(S[i]);
		tmp = tmp+N;
		if (tmp > 26) tmp = tmp - 26;

		char tmp2 = get_char(tmp);
		S[i] = tmp2;

	}

	cout << S << endl;

	return 0;

}


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

using namespace std;

#define RI register int

typedef long long LL;
const int mod = 1e9 + 7;

int n, m, a1, a2, b, s;
LL K;
char mp[1005][1005];
int tmp[3];

int ksm(int x, LL y) {
  int re = 1;
  for (; y; y >>= 1, x = 1LL * x * x % mod)
    if (y & 1) re = 1LL * re * x % mod;
  return re;
}

struct matrix {
  int t[3][3];
} X, re;

int qm(int x) { return x >= mod ? x - mod : x; }

matrix operator*(matrix A, matrix B) {
  matrix C;
  for (RI i = 0; i < 3; ++i)
    for (RI j = 0; j < 3; ++j) C.t[i][j] = 0;
  for (RI k = 0; k < 3; ++k)
    for (RI i = 0; i < 3; ++i)
      for (RI j = 0; j < 3; ++j)
        C.t[i][j] = qm(C.t[i][j] + 1LL * A.t[i][k] * B.t[k][j] % mod);
  return C;
}

void work() {
  for (RI i = 0; i < 3; ++i) re.t[i][i] = 1;
  X.t[0][0] = X.t[1][1] = s, X.t[1][2] = 1, X.t[2][2] = a1;
  for (LL i = K - 2; i; i >>= 1, X = X * X)
    if (i & 1) re = re * X;
  int V = 0, E = 0;
  tmp[0] = s, tmp[1] = b, tmp[2] = a1 * b;
  for (RI i = 0; i < 3; ++i) V = qm(V + 1LL * re.t[0][i] * tmp[i] % mod);
  for (RI i = 0; i < 3; ++i) E = qm(E + 1LL * re.t[1][i] * tmp[i] % mod);
  printf("%d\n", qm(V - E + mod));
}

int main() {
  scanf("%d%d%lld", &n, &m, &K);
  if (K <= 1) {
    puts("1");
    return 0;
  }
  for (RI i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
  for (RI i = 1; i <= m; ++i)
    if (mp[1][i] == '#' && mp[n][i] == '#') ++a1;
  for (RI i = 1; i <= n; ++i)
    if (mp[i][1] == '#' && mp[i][m] == '#') ++a2;
  for (RI i = 1; i <= n; ++i)
    for (RI j = 1; j <= m; ++j)
      if (mp[i][j] == '#') ++s;
  if (a1 && a2) {
    puts("1");
    return 0;
  } else if (!a1 && !a2) {
    printf("%d\n", ksm(s, K - 1));
    return 0;
  }
  if (a1) {
    for (RI i = 1; i < n; ++i)
      for (RI j = 1; j <= m; ++j) b += (mp[i][j] == '#' && mp[i + 1][j] == '#');
  } else {
    for (RI i = 1; i <= n; ++i)
      for (RI j = 1; j < m; ++j) b += (mp[i][j] == '#' && mp[i][j + 1] == '#');
  }
  a1 = a1 | a2, work();
  return 0;
}


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

using namespace std;
typedef long long ll;
const long double pi=3.14159265358979323846;
#define x  first
#define y  second
#define deb(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
bool isPar(string s)
{
    ll n=s.size();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        {
            return 0;
        }
    }
    return 1;
}

ll nOfD(ll n)
{
    ll d=0;
    ll i=1;
    while(i * i < n)
    {
        if(n%i ==0) d+=2;
        i++;
    }
    if(i * i == n)d++;
    return d;
}
ll sOfD(ll n)
{
    ll sum=0;
    ll i=1;
    while(i * i < n)
    {
        if(n%i ==0) sum+=i,sum+=n/i;
        i++;
    }
    if(i * i == n)sum+=i;
    return sum;
}
bool isP(ll x)
{
    if(x==2)return 1;
    if(x<2 || x%2==0)return 0;
    for(ll i=3;i * i <= x;i+=2)
    {
        if(x%i==0)return 0;
    }
    return 1;
}
ll lcm(ll a, ll b)
{
    return (a / __gcd(a, b) * b);
}

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    //freopen("op.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       ll a[n];
       for(int i=0;i<n;i++)cin>>a[i];
       stack<pair<int,ll> > s;
       pair<ll,ll>cnt[n]={};
       for(int i=0;i<n;i++)
       {
           int c=1;
           while (!s.empty() && (s.top().first) >= a[i]) {
                c += s.top().second;
                s.pop();
            }
            s.push({a[i],c});
            cnt[i].x=c;
       }
       while(!s.empty())s.pop();
       for(int i=n-1;i>=0;i--)
       {
           int c=1;
           while (!s.empty() && (s.top().first) >= a[i]) {
                c += s.top().second;
                s.pop();
            }
            s.push({a[i],c});
            cnt[i].y=c;
       }
       ll sum=0;
       for(int i=0;i<n;i++)sum+=a[i]*cnt[i].x * cnt[i].y;
       cout<<sum;
    }
    return 0;
}


Measured memory_bytes: 11468
let rec nfs cand acc m = function
  | 0 -> List.rev cand :: acc
  | n ->
      nfs (Char.chr (Char.code 'a' + m) :: cand)
        (Array.fold_left
          (fun acc i -> nfs (Char.chr (Char.code 'a' + i) :: cand) acc m (n - 1)) acc
          (Array.init m @@ fun i -> i))
        (m + 1) (n - 1)
let nfs = nfs [] [] 0

let () = Scanf.scanf "%d\n" @@ fun n ->
  List.iter (fun cs ->
    List.iter print_char cs;
    print_newline ()) @@
  List.sort compare @@ nfs n

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

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

	vector<pair<int,int>> inp[n];
	for(int i=0 ; i<n; ++i){
		int t; cin>>t;
		for(int j=0; j<t; ++j){
			int u,v;
			cin>>u>>v;
			u--;
			inp[i].push_back({u,v});
		}
	}
	int max_ans = 0;
	for(int i=0 ; i< (1<<n); ++i){
		// i is the combination now.
		vector<int> valid(n,-1);
		int cnt = 0;
		for(int j=0; j<n; ++j){
			if( (i & (1<<j))== 0 ){ valid[j] = 0; }
			else{ valid[j] = 1; cnt++; }
		}
		bool ok = true;
		for(int i=0; i<n; ++i){
			if( valid[i] == 0 ){ continue; }
			for(int j=0; j<inp[i].size(); ++j){
				auto now = inp[i][j];
				if( valid[now.first] != now.second ){
					ok = false;
					break;
				}
			}
		}
		if( ok ){ max_ans = max(max_ans, cnt); }
	}
	cout<<max_ans<<'\n';

	return 0;
}


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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;
const int N = 200000;

ll fac[N + 10], inv[N + 10];
ll H, W, A, B;

ll PowMod(ll a,ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

void pre() {
	fac[0] = inv[0] = 1;
	for(int i = 1;i <= N; ++i) 
		fac[i] = fac[i - 1] * i % mod;
	inv[N] = PowMod(fac[N], mod - 2);
	for(int i = N - 1;i >= 1; --i)
		inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) {
	if(n == 0 || m == 0) return 1;
	ll res = 1;
	res = res * fac[n] % mod;
	res = res * inv[n - m] % mod;
	res = res * inv[m] % mod;
	return res;
}

int main() {
	cin >> H >> W >> A >> B;
	pre(); // 2 3 1 1
	ll ans = 0; 
	for(int i = 1;i <= H - A; ++i) 
		ans = (ans + (C(i + B - 2, i - 1) * C(H - i + W - B - 1, H - i) % mod))% mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6764
def get_ints():
    return list(map(int, input().split()))

[n, l] = get_ints()
a = get_ints()

for i in range(n - 1):
    if a[i] + a[i + 1] < l:
        continue
    print("Possible")
    for j in range(1, i + 1):
        print(j)
    for j in range(n - 1, i, -1):
        print(j)
    exit(0)

print("Impossible")


Measured memory_bytes: 14064
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
 
  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
//   typedef string str;
//   typedef unsigned long long ull;
//   ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;
  



 






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

   int a,b,h,m;
   cin>>a>>b>>h>>m;
    lld a1 = lld(m)/60 * 2 * PI;
    lld a2 = ((lld)h*60+m)/(12*60) * 2 * PI;
    a1 = abs(a1-a2);
    lld ans = sqrt(a*a+b*b-2*a*b*cos(a1));
    cout<<setprecision(20)<<ans<<endl;
  

}
  

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

	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		int arr[]=new int[n];
		int dp[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}
		Arrays.fill(dp, -1);
		int ans=rec(dp,arr,0,k);
		System.out.println(ans);
		
		//dp[0]=0;
		//dp[1]=Math.abs(arr[0]-arr[1]);
//		for(int i=1;i<n;i++)rr
//		{
//			int min=Integer.MAX_VALUE;
//			for(int j=1;j<=k&&i-j>=0;j++)
//			{
//				//System.out.println(i+" "+j);
//				int temp=dp[i-j]+Math.abs(arr[i]-arr[i-j]);
//			min=Math.min(temp, min);
//			}
//			dp[i]=min;
//			//System.out.println(dp[i]);
//		}
//		System.out.println(dp[n-1]);
	}

	private static int rec(int[] dp, int[] arr, int ind, int k) {
		// TODO Auto-generated method stub
		if(ind==arr.length-1)
		{
			return 0;
		}
		
		if(dp[ind]!=-1)
		{
			
			return dp[ind];
		}
		int n=arr.length;
		int ans=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			if(ind+i<n)
			{
				//System.out.println(ind+" "+i);
				ans=Math.min(ans, Math.abs(arr[ind]-arr[i+ind])+rec(dp,arr,ind+i,k));
			}
		}
		dp[ind]=ans;
		return ans;
	}
}


Measured memory_bytes: 74144
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program {
    

    internal static void Main(string[] args)
    {
        int[] inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = inp[0];
        int K = inp[1];
        int[] A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int ans = 0;

        for (int i = N - 1; i > 0; i = i - (K - 1)) {
            ans++;
        }

        WriteLine(ans);
    }
}

Measured memory_bytes: 19936
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

int needed_kaisu(long long a, long long N, long long *A) {
	int count = 0;
	for (long long i = 0; i < N; i++) {
		count += (A[i]+a-1) / a -1;
	}
	return count;
}


int main() {


	string S;
	int N;
	long long L[110];

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

	int count = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (i < j && j < k && L[i] != L[j] && L[j] != L[k] && L[k] != L[i] && abs(L[i] - L[j]) < L[k] && L[k] < L[i] + L[j]) {
					count++;
				}
			}
		}
	}

	cout << count;

	cin >> N;

	return 0;


}



Measured memory_bytes: 3624
#include <stdio.h>

int main()
{
	char S[10], T[10], U[10];
	int a, b;
	
	
	scanf("%s %s", S, T);
	
	scanf("%d %d", &a, &b);
	
	scanf("%s", U);
	
	if(*S==*U){ printf("%d %d", a-1, b); }
	else if(*T==*U){ printf("%d %d", a, b-1); }
	
	return 0;
}

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

int main()
{
  int a[3];
  rep(i, 3){
    cin >> a[i];
  }
  sort(a, a + 3);
  cout << a[0] * a[1] / 2 << endl;

  return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
123456789
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    string a;
    while(N > 0) {
        N--;
        a += 'a' + (N % 26);
        N /= 26;
    }
    reverse(a.begin(), a.end());
    cout << a;
    return 0;
}


Measured memory_bytes: 3620
#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 INF = 1001001001;
const int MOD = 1000000007;

// auto MOD int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination MOD prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(1000005);

int modPow(long long a, long long n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  long long t = modPow(a, n / 2);
  return (t * t) % MOD;
}

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> A;
    rep(i,N) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(),A.end());
    mint ans = 0;
    rep(m,N) {
        if (N-(m+1)>=K-1) {
            ans -= comb(N-(m+1), K-1)*A[m];
        }
        if ((m+1)-1>=K-1) {
            ans += comb(m+1-1, K-1)*A[m];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 19496
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll  long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
int fun(char ch,int n)
{
    for(int i=1;i<=n;i++)
    {
        cout << ch;
    }
}
int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x = x2-x1;
    int y = y2-y1;
    // for(int i=1;i<=y;i++)
    fun('U',y);
    fun('R',x);
    fun('D',y);
    fun('L',x);
    cout << 'L';
    fun('U',y+1);
    fun('R',x+1);
    cout << 'D';
    cout << 'R';
    fun('D',y+1);
    fun('L',x+1);
    cout << 'U';
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace _2259
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int max = 0;
            for (int i = 0; i < x[0]; i++)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                max = Math.Max(max,a.Sum());
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 9656
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
 
int main(){
    int N;
    string S;
    cin >> N >> S;
    rep(i,S.size()){
        S[i]=(S[i]-'A' + N)%26+'A';
 
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;

class plmko{
  static void Main(){
    string a = ReadLine();
    string b = "";
    for(int i=0;i<3;i++){
      if(a[i] == '1'){
        b += 9;
      }else if(a[i] == '9'){
        b+= 1;
      }else{
        b += a[i];
      }
    }
    WriteLine(b);
  }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<int> g(n,-1),k(n,-1);
  int nowg=0,nowk=0;
  int a;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a%2){
      k[nowk]=a;
      nowk++;
    }else{
      g[nowg]=a;
      nowg++;
    }
  }
  g.resize(nowg);
  k.resize(nowk);
  sort(all(g));
  sort(all(k));
  int ans=0;
  for(int i=0;i<nowg;i++){
    ans+=g[i];
  }
  for(int i=nowk%2;i<nowk;i++){
    ans+=k[i];
  }
  cout << ans/2 << endl;
  return 0;
}



Measured memory_bytes: 3128