akhauriyash/Code-Regression huggingface dataset:
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int ffind(vll& v,int x)
{
	int low=0,high=v.size()-1,mid,ans=-1;
	while(low<=high)
	{
		mid=(low+high)/2;
		if(v[mid]<=x)
		{
			ans=mid;
			low=mid+1;
		}
		else high=mid-1;
	}
	return ans;
}
int32_t main() {
    IOS;
    	int n,m,k;
    	cin>>n>>m>>k;
        vll a(n),b(m);
        rep(i,0,n-1)cin>>a[i];
        rep(i,0,m-1)cin>>b[i];
        rep(i,1,n-1)a[i]+=a[i-1];
        rep(i,1,m-1)b[i]+=b[i-1];
        int val=ffind(a,k),ans=val+1;
        for(int i=val;i>=0;--i)
        {
        	int x=ffind(b,k-a[i]);//db1(x);
        	ans=Max(ans,x+i+2);
        }
        ans=Max(ans,ffind(b,k)+1);
        cout<<ans;


        cout<<'\n';
    return 0;
}

Measured memory_bytes: 6360
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-19 20:12:22
---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int pre[MAXN];

int find(int x){
	if(x == pre[x])	return x;
	else	return pre[x] = find(pre[x]);
}
int main(int argc, char const *argv[])
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)	pre[i] = i;
	int u, v, w;
	for(int i = 1; i <= m; ++i){
		cin >> u >> v >> w;
		int fx = find(u);
		int fy = find(v);
		if(fx == fy)	continue;
		pre[fx] = fy;
	}
	int cnt = 0;
	for(int i = 1; i <= n; ++i){
		if(pre[i] == i)	cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int keta(ll x){
  int ans = 0;
  while(x > 0){
    x /= 10;
    ans++;
  }
  return ans;
}

int main(){
  ll N;
  cin >> N;
  //cout << keta(N) << endl;

  int ans = 100;
  for(ll i=1 ; i*i<=N ; i++){
    if(N%i == 0){
      int a = keta(i);
      int b = keta(N/i);
      ans = min(ans, max(a,b));
    }
  }

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


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=0||b<=0)
        return 0;
    if(a*b%2==0)
        cout<<"Even\n";
    else
        cout<<"Odd\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a=a%b)
    return gcd(b,a);
  else
    return b;
}
int main(){
  int K,i,j,k,A=0;
  cin >> K;
  for(i=1;i<=K;i++){
    for(j=i;j<=K;j++){
      for(k=j;k<=K;k++){
        if(k==i)
          A+=k;
        else if(k==j)
          A+=3*gcd(j,i);
        else if(j==i)
          A+=3*gcd(k,j);
        else
          A+=6*gcd(k,gcd(j,i));
      }
    }
  }
    
  cout << A;
}

Measured memory_bytes: 3632
# Educational DP Contest A
N = int(input())
H = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0
dp[1] = abs(H[0] - H[1])
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(H[i] - H[i-2]), 
                dp[i-1] + abs(H[i] - H[i-1])
                )
print(dp[N-1])

Measured memory_bytes: 13980
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<' ';
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int r,d,x;
    cin>>r>>d>>x;
    ll ans = x;
    rep(i,10){
        x = r*x -d;
        cout<<x<<endl;
    }return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int even[100001];
int odd[100001];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int v;
		cin >> v;
		if (i % 2 == 1) odd[v]++;
		else even[v]++;
	}
	int top1_e = 0, top2_e = 0;
	int top1_o = 0, top2_o = 0;
	for (int i = 1; i <= 100000; i++) {
		if (even[top1_e] <= even[i]) {
			top2_e = top1_e;
			top1_e = i;
		}
		else if (even[top2_e] <= even[i]) {
			top2_e = i;
		}
		if (odd[top1_o] <= odd[i]) {
			top2_o = top1_o;
			top1_o = i;
		}
		else if (odd[top2_o] <= odd[i]) {
			top2_o = i;
		}
	}
	if (top1_e != top1_o) cout << n - (even[top1_e] + odd[top1_o]);
	else cout << n - max(even[top1_e] + odd[top2_o], even[top2_e] + odd[top1_o]) << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int n,m;
cin >> n >> m;
vector<bool>oka(n+1,true);
for(int i=0;i<m;i++){
  int a;cin >> a;
  oka[a]=false;
}
vector<ll>dp(n+1);
dp[0]=1;
ll mod = 1e9+7;
for(int now=0;now<n;now++){
  for(int next=now+1;next<=min(now+2,n);next++){
    if(oka[next]){
      dp[next]+=dp[now];
      dp[next]%=mod;
    }
  }
}
cout << dp[n]<<endl;
}
 


Measured memory_bytes: 1024
import java.util.*;

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

        int N = sc.nextInt();
        sc.close();

        long sum = 0;

        for(int i = 1; i <= N; i++){
            if(i != N)
                sum += i;
        }

        System.out.println(sum);
        
    }
}

Measured memory_bytes: 23764
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int y, m, d;
	char c1, c2;
	cin >> y >> c1 >> m >> c2 >> d;
	cerr << y << m << d << endl;
	if ((m < 4) || (m == 4 && d <= 30))
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;
}

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

	solve();
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::iter::once;
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

////////////////////////////////////////////////////////////////////////////////

fn main() {
    let n = read!(usize);
    let mut a = read!([i64]);

    a.sort();

    let neg = a.iter().filter(|&&x| x <= 0).map(|&x| x).vec();
    let pos = a.iter().filter(|&&x| x > 0).map(|&x| x).vec();
    debug!(neg, pos);

    let mut ops = vec![];
    let mut ans: i64;

    if neg.len() > 0 && pos.len() > 0 {
        ans = neg[0];
        for i in 0..pos.len() - 1 {
            ops.push(format!("{} {}", ans, pos[i]));
            ans = ans - pos[i];
        }
        ops.push(format!("{} {}", pos[pos.len() - 1], ans));
        ans = pos[pos.len() - 1] - ans;
        for i in 1..neg.len() {
            ops.push(format!("{} {}", ans, neg[i]));
            ans = ans - neg[i];
        }
    } else if neg.len() == 0 {
        ans = pos[0];
        for i in 1..pos.len() - 1 {
            ops.push(format!("{} {}", ans, pos[i]));
            ans = ans - pos[i];
        }
        ops.push(format!("{} {}", pos[pos.len() - 1], ans));
        ans = pos[pos.len() - 1] - ans;
    } else {
        ans = neg[neg.len() - 1];
        for i in (0..neg.len() - 1).rev() {
            ops.push(format!("{} {}", ans, neg[i]));
            ans = ans - neg[i];
        }
    }

    println!("{}", ans);
    for s in ops {
        println!("{}", s);
    }
}


Measured memory_bytes: 13816
# coding: utf-8

import collections
import sys
sys.setrecursionlimit(100000)

def dfs(i):
    if visited[i] == 1:
        return
    visited[i] = 1
    for j in speakers[i]:
        if used_lang[j] == 1:
            continue
        used_lang[j] = 1
        for k in langs[j]:
            dfs(k)


N, M = map(int, input().split())

langs = collections.defaultdict(list)
speakers = [[] for _ in range(N)]

for i in range(N):
    ls = list(map(int, input().split()))
    for j in range(1, ls[0] + 1):
        langs[ls[j]-1].append(i)
        speakers[i].append(ls[j]-1)

visited = [0] * N
used_lang = [0] * M
dfs(0)

if 0 not in visited:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 30128
#include <iostream>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i <=n;i++)
    {
        cin>>a[i];
    }

    int ans=(n-1)/(k-1);
    if(0!=(n-1)%(k-1))
    {
        ans+=1;
    }

    cout<<ans;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
template <int MOD>
class ModInt {
  long long x;

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }
};

const ll MOD = 1000000007;
using mint = ModInt<MOD>;

int N, K;
vector<int> a;

int main() {
  cin >> N >> K;
  a.resize(N);
  rep(i, N) cin >> a[i];

  vector<vector<mint>> dp(N + 1, vector<mint>(K + 2, 0));
  dp[0][0] = 1;

  rep(i, N) {
    rep(k, K + 1) dp[i][K - k + 1] = dp[i][K - k];
    rep(k, K + 1) dp[i][k + 1] += dp[i][k];

    rep(k, K + 1) { dp[i + 1][k] = dp[i][k + 1] - dp[i][k - min(a[i], k)]; }
  }

  cout << dp[N][K] << endl;
  return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int X[M];
    for (int i = 0; i < M; i++) cin >> X[i];

    if (M <= N) {
        cout << 0 << endl;
        return 0;
    } else {
        sort(X, X+M);
        int D[M-1];
        for (int i = 0; i < M-1; i++) {
            D[i] = X[i+1] - X[i];
        }
        sort(D, D+M-1);
        int ans = 0;
        for (int i = 0; i < M-N; i++) ans += D[i];
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		double dis = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
		System.out.println(dis);
		sc.close();
	}
}



Measured memory_bytes: 28024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD=1e9+7;
const int INF=1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m=MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------//
int calc(int n1,int n2,int p1,int p2){
	int x=lcm(p1,p2);
	int a=(n2/p1)-(n1-1)/p1;
	int b=(n2/p2)-(n1-1)/p2;
	int cd=(n2/x)-(n1-1)/x;
	int ret=(n2-n1+1)-a-b+cd;
	return ret;
}
void solve(){
   int l,r,c,d;
   cin>>l>>r>>c>>d;
   cout<<calc(l,r,c,d)<<endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll h, w, mn = INF, used[50][50];
queue<pp> q;
char m[55][55];
int main() {
	rep(i, 50)rep(j, 50)used[i][j] = INF;
	ll ct = 0;
	cin >> h >> w;
	rep(i, h)rep(j, w)cin >> m[i][j],ct+=(m[i][j]=='.'?1:0);
	q.push(pp{ 0,0 });
	used[0][0] = 0;
	while (!q.empty()) {
		pp p = q.front();
		q.pop();
		//cout << p.first << "," << p.second << endl;
		if (p.first < h - 1 && used[p.fi + 1][p.se] == INF && m[p.fi + 1][p.se] == '.') { q.push(pp{ p.fi + 1,p.se }); used[p.fi + 1][p.se] = used[p.fi][p.se] + 1; }
		if (p.first > 0 && used[p.fi - 1][p.se] == INF && m[p.fi - 1][p.se] == '.') { q.push(pp{ p.fi - 1,p.se }); used[p.fi - 1][p.se] = used[p.fi][p.se] + 1;}
		if (p.se < w - 1 && used[p.fi][p.se + 1] == INF && m[p.fi][p.se + 1] == '.'){q.push(pp{ p.fi ,p.se + 1 }); used[p.fi][p.se+1] = used[p.fi][p.se] + 1;}
		if (p.se > 0 && used[p.fi][p.se - 1] == INF && m[p.fi][p.se - 1] == '.') { q.push(pp{ p.fi ,p.se - 1 }); used[p.fi][p.se-1] = used[p.fi][p.se] + 1;}
	}
	cout << (used[h - 1][w - 1] == INF ? -1 : ct - used[h - 1][w - 1]-1) << endl;
	return 0;
}

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

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  REP(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  REP(i, m) {
    int p = q.top(); q.pop();
    q.push(p / 2);
  }
  ll ans = 0;
  while (!q.empty()) {
    int p = q.top(); q.pop();
    ans += p;
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd

n,k = map(int,input().split())

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

if (n-1)%(k-1) == 0:
    print((n-1)//(k-1))
else:
    print((n-1)//(k-1)+1)

#mini = min(a)
#mini_index = a.index(mini)
#
#
##if (len(a)-mini_index)%(k-1):ans = (len(a) - mini_index)/(k-1)+1
##else:ans = (len(a) - mini_index)/(k-1)
##
##if ( (mini_index-1)%(k-1)):ans = ans + (mini_index-1)/(k-1)+1
##else:ans = ans + (mini_index-1)/(k-1)
#
#ans = -(-(len(a)-(mini_index+1))//(k-1))
#ans = ans + (-(-(mini_index-1)//(k-1)))
#
##if ((len(a) - mini_index)%(k-1) + (mini_index-1)%(k-1)) <= (k-1):ans = ans -1
#
#print(ans)
#

Measured memory_bytes: 23744
#include <iostream>
#include <list>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
    int q, x;
    char command[20];

    list<int> v;

    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%s", command);
        
        if (command[0] == 'i') {
            scanf("%d", &x);
            v.push_front(x);
        } else if (command[6] == 'L') {
            v.pop_back();
        } else if (command[6] == 'F') {
            v.pop_front();
        } else if (command[0] == 'd') {
            scanf("%d", &x);
            for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
                if (*it == x) {
                    v.erase(it);
                    break;
                }
            }
        }
    }

    int i = 0;
    
    for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 34396
import java.util.Arrays;
import java.util.Scanner;

class Main{

	static	int count = 0;
	public static void main(String[] args) {



		Scanner scanner = new Scanner(System.in);
		int H = scanner.nextInt();
		int W = scanner.nextInt();

		int[][] c = new int[10][10];
		for(int i = 0;i < 10;i++){
			for(int j = 0;j < 10;j++){
				c[i][j] = scanner.nextInt();
			}
		}


		int[][] A = new int[H+1][W+1];
		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				A[i][j] = scanner.nextInt();
			}
		}

		int[] minsum = new int[10];
		Arrays.fill(minsum, 100000);

		int[][] dis = new int[10][10];

		for(int k = 0;k < 10;k++){

			for(int i = 0;i < 10;i++){			//ある値から1にいくまでの最小の値を求める

				for(int j = 0;j < 10;j++){
					c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);

				}

			}
		}



		
		int ans = 0;
		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				if(A[i][j] == -1 ){
					ans += 0;
				}else{
					ans += c[A[i][j]][1];
				}

			}
		}
		System.out.println(ans);

	}



	static int allsum(int[][]c,int i,int j ,int sum,boolean[] flag){


		sum += c[i][j];

		System.out.println("i "+i + " j "+j+" c "+count+" sum "+sum);
		count++;





		if(j == 1){				//現在地が1の時、終了]
			System.out.println("finish");
			return sum;

		}

		flag[j] = true;				//現在地のflagを立てる

		//			for(int t = 0;t < 10;t++){
		//				if(!flag[t]){				//まだ訪れていない数値について調べる

		for(int k = 0; k < 10;k++){
			if(!flag[k]){
				sum =Math.min(sum, allsum(c, j, k, sum, flag));			//iは現在地、kは行き先
			}
		}

		//				}
		//			}

		return sum;

	}




}

class Pair implements Comparable{
	int from;
	int middle;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 46720
#include<bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;//
template <typename T>
T sq (T x) {
    return x * x ;
}
signed main () {
ll A,B,C;
string s;
ll N,M,L;

cin >> s;

if(s =="ABC"){
cout << "ARC" <<endl;
}else{
cout << "ABC" << endl;
}
return 0;
}



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

int main(){
 ll n,ans;
 cin>>n;
 vector<ll>a(n);
 for(ll i=0;i<n;i++){
    cin>>a[i];

 }
 ans=a[0];
 for(ll i=1;i<n;i++){
    ans=ans^a[i];
 }
 for(ll i=0;i<n;i++){
    cout<<(a[i]^ans)<<" ";
 }
 cout<<endl;
 return 0;
}





Measured memory_bytes: 4744
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();
		int[] dp = new int[n + 1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[n] = 0;

		Queue<Integer> q = new LinkedList<>();
		q.offer(0);
		for (int i = n - 1; i >= 0; i--) {
			while (true) {
				if (q.size() == 0) {
					System.out.println(-1);
					return;
				}
				if (q.peek() != Integer.MAX_VALUE && q.size() <= m) break;
				q.poll();
			}

			if (s.charAt(i) == '0') dp[i] = q.peek() + 1;
			q.offer(dp[i]);
		}

		List<Integer> answeer = new ArrayList<>();
		int x = 0;
		int rest = dp[0];
		while (x < n) {
			--rest;
			int i = 1;
			while (dp[x + i] != rest) ++i;
			answeer.add(i);
			x += i;
		}
		for (int i = 0; i < answeer.size(); i++) {
			System.out.print(answeer.get(i));
			System.out.print(" ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 39848
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

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

        final String S = sc.next();
        // final int A = sc.nextInt();

        boolean result = false;
        if (S.contains("a") && S.contains("b") && S.contains("c")) {
            result = true;
        }

        // System.out.println();
        System.out.println(result ? "Yes" : "No");

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21716
n = int(input())

alp = 'Zabcdefghijklmnopqrstuvwxyz'

ans = ''

while n:
    if n<27:
        ans += alp[n]
        break
    else:
        t = n%26
        if not t:
            t = 26
        ans += alp[t]
        n = (n-t)//26

ans = ans[::-1]

print(ans)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double;
using ii = pair <int, int>;

#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define FORD(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _ = c; a < _; ++a)
#define ALL(a, b) for(auto &a : b)
#define pb push_back
#define mp make_pair
#define all(a) begin(a), end(a)
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
#define s(i) s[i + 1]

const int N = 105, _N = 1e5 + 5;
const ll mod = 1e9 + 7;
int n, k, a[N];
ll s[_N], f[N][_N];

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> k;
  FOR(i, 1, n) cin >> a[i];
  FOR(i, 0, k) s(i) = 1;
  FOR(i, 1, n) {
    FOR(j, 0, k) f[i][j] = (s(j) - s(max(0, j - a[i]) - 1) + mod) % mod;
    FOR(j, 0, k) s(j) = (f[i][j] + s(j - 1)) % mod;
  }
  cout << f[n][k];
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, long long K, std::vector<long long> h) {
    vi dp(N, inf);
    dp[0] = 0;
    rep(i, N) {
        rep(j, K) {
            int next = i + j + 1;
            if (next < N) chmin(dp[next], dp[i] + abs(h[i] - h[next]));
        }
    }

    cout << dp.back() << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> h(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
local s = io.read()
local n = #s
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i) == "R"
end

local lastpos = {}
local r_start_pos = 1
local curpos = 2
while curpos <= n do
  if t[curpos] then
    curpos = curpos + 1
  else
    -- L FOUND. curpos is L
    for i = r_start_pos, curpos - 1 do
      if (curpos - i) % 2 == 0 then
        lastpos[i] = curpos
      else
        lastpos[i] = curpos - 1
      end
    end
    local l_begin = curpos
    while curpos <= n do
      if t[curpos] then
        r_start_pos = curpos
        break
      else
        if (curpos - l_begin) % 2 == 0 then
          lastpos[curpos] = l_begin
        else
          lastpos[curpos] = l_begin - 1
        end
        curpos = curpos + 1
      end
    end
  end
end
local ret = {}
for i = 1, n do ret[i] = 0 end
for i = 1, n do
  local z = lastpos[i]
  ret[z] = ret[z] + 1
end
print(table.concat(ret, " "))


Measured memory_bytes: 7188
#include<bits/stdc++.h>
using namespace std ;
int cnt , cnt4 , cnt2 ;
int main()
{
	int n ;
	cin >> n ;
	for ( int i = 0; i< n ; i++)
	{
		int x ;
		cin >> x ;
		x = x % 4 ;
		if ( x == 0 ) 
			cnt4 ++  ;
		else if ( x == 2 ) 
			cnt2 ++ ;
	}
	int cnt = n-cnt2-cnt4 ;
	if ( cnt2 ) 
	{
		if ( cnt4 >= cnt ) 
			return cout<<"Yes\n" , 0 ;

	}
	else
	{
		if ( cnt4 && ( cnt4+1 >= cnt )) 
			return cout << "Yes\n" , 0 ;

	}
	cout << "No" << "\n" ;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    ll n;
    cin>>n;
    vector<bool> a(n+100,false);
    a[0]=true;
    for(int i=0;i<n;i++){
        if(a[i]){
            a[i+4]=true;
            a[i+7]=true;
        }
    }
    if(a[n]){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    
    return 0;
}


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

int N, A[1 << 18], cnt = 1, maxn = 1;
bool used[1 << 18];
vector<pair<int, int>> vec;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		used[i] = true;
		vec.push_back(make_pair(A[i], i));
	}
	sort(vec.begin(), vec.end());

	if (vec[0].first == 0) maxn = 0;

	for (int i = 0; i < vec.size(); i++) {
		int pos = vec[i].second;
		used[pos] = false; cnt--;
		if (used[pos - 1] == true) cnt++;
		if (used[pos + 1] == true) cnt++;
		if (i + 1 == vec.size() || vec[i].first != vec[i + 1].first) {
			maxn = max(maxn, cnt);
		}
	}
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 4308
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

#define PLIMIT 1000000
int prime[PLIMIT+10];
void makep(ll n){prime[0]=prime[1]=1;for(int i=2;i*i<=n;i++)if(!prime[i])for(int j=i*i;j<=n;j+=i)prime[j]=1;}

int main(){
	makep(PLIMIT);
	ll a,d,n;
	while(scanf("%lld%lld%lld",&a,&d,&n),n){
		ll cnt=0;
		while(1){
			if(!prime[a]){
				cnt++;
				if(cnt==n){
					printf("%lld\n",a);
					break;
				}
			}
			a+=d;
		}
	}
}


Measured memory_bytes: 5588
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {

	    int A = nextInt();
	    int B = nextInt();
	    int X = nextInt();
	    
	    if(X<A){
            out.println("NO");   	        
	    }else if(X<=(A+B)){
            out.println("YES");   
	    }else{
            out.println("NO");   	        
	    }

	}

	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

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

int main() {
  string str;
  cin>>str;
  int N =str.size();
  int count=0;
  for(int i=0;i<N/2;i++){
      if(str.at(i)!=str.at(N-1-i)){
        count++;
      }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
#define N 100009

long gcd(long x, long y){
    if (y>x){
       swap(x,y); 
    }
    while (y!=0){
        long r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(){
    long n;
    cin>>n;
    long a,b;
    cin>>a>>b;
    long p=gcd(a,b);
    for (long i=2; i<n; i++){
        long q;
        cin>>q;
        p=gcd(p,q);
    }
    cout<<p<<endl;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,sum=0;cin>>n;
    vector<int>l(n);
    rep(i,n){
        cin>>l[i];
        sum+=l[i];
    }
    sort(l.begin(),l.end());
    sum-=l[n-1];

    if(sum>l[n-1]){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }

}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String numbers[] = br.readLine().split(" ");
		int n = Integer.parseInt(numbers[0]);
		int x = Integer.parseInt(numbers[1]);
		String length[] = br.readLine().split(" ");
		int len[] = new int[n];
		for (int i = 0; i < n; i++) {
			len[i] = Integer.parseInt(length[i]);
		}
		int bounces[] = new int[n + 1];
		bounces[0] = 0;
		for (int j = 1; j <= len.length; j++) {
			bounces[j] = bounces[j - 1] + len[j - 1];
		}
		int count = 0;
		for (int k = 0; k < bounces.length; k++) {
			if (bounces[k] <= x) {
				count++;
			}
		}
		System.out.println(count);
	}

}

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

using namespace std;

string a,b;

int tb[3000][3000];
vector<char> out;

int dp(int x, int y){
	if(x == a.size() || y == b.size())
		return 0;
	
	if(tb[x][y] != -1) return tb[x][y];
	
	int total = 0;
	if(a[x] == b[y]) total = dp(x+1, y+1)+1;
	else total = max(dp(x+1, y), dp(x, y+1));
	
	return tb[x][y] = total;
}

void get(int x, int y){
	if(x == a.size() || y == b.size())
		return;
	
	if(a[x] == b[y]){
		out.push_back(a[x]);
		get(x+1, y+1);
	}else{
		if(tb[x][y+1] > tb[x+1][y]) get(x,y+1);
		else get(x+1,y);
	}
}

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	
	memset(tb, -1, sizeof(tb));
	
	cin >> a >> b;
	if(dp(0,0)){
		get(0,0);
		for(auto c : out) cout << c;
	}
	
	return 0;
}

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

int main()
{
    int x;
    cin>>x;
    int p=x,sum=0;
    while (p>0)
    {
        sum+=p%10;
        p/=10;
    }
    if(x%sum==0)
    {
        cout<<"Yes";
        return 0;
    }
    else
    {
        cout<<"No";
        return 0;
    }
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main(){
	char s[5001];
	scanf("%s",s);
	int K;
	scanf("%d",&K);
	
	int l=strlen(s);
	int c=0;
	for(int i=0;i<K;i++)c+=l-i;
	
	char sub[c][K+1];
	
	int cc=0;
	for(int i=1;i<=K;i++){
		for(int j=0;j<l-i+1;j++)
{
			for(int k=0;k<i;k++)
{
				sub[cc][k]=s[j+k];
				if(k==i-1)for(k;k<K;k++)sub[cc][k+1]='\0';
			}
			cc++;
		}
	}
	
	//sort
	int r=c;
	int swapped=0;
	while(r>1 || swapped==1)
{
		if(r>1)r=r*10/13;
		swapped=0;
		for(int i=0;i+r<c;i++)
{
			if(strcmp(sub[i],sub[i+r])>0)
{
				char tmp[K+1];
				for(int j=0;j<K+1;j++)tmp[j]=sub[i][j];
				for(int j=0;j<K+1;j++)sub[i][j]=sub[i+r][j];
				for(int j=0;j<K+1;j++)sub[i+r][j]=tmp[j];
				swapped=1;
			}
		}
	}
	
	int k=1;
	for(int i=0;i<c;i++)
{
		if(i>0 && strcmp(sub[i-1],sub[i])!=0)k++;
		if(k==K)
{
			printf("%s\n",sub[i]);
			return 0;
		}
	}
	
	//for(int i=0;i<c;i++)printf("%s\n",sub[i]);
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    println(N - Array.fill(N)(Array.fill(3)(sc.nextInt - 1).sorted).map(x => x(0) * 1000000 + x(1) * 1000 + x(2)).distinct.size)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 53552
#include<bits/stdc++.h>
#define int long long
using namespace std;

int dp[5010][5010];

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

    for(int i=N-2;i>=0;i--){
        for(int j=N-1;j>i;j--){
            if(s[i]==s[j]){
                if(i+dp[i+1][j+1]>=j) dp[i][j]=j-i;
                else dp[i][j]=dp[i+1][j+1]+1;
            }
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ans=max(ans,dp[i][j]);
        }    
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 194944
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const string yaku[] = { "four card", "full house", "straight", "three card", "two pair", "one pair", "null" };

int main()
{
//	cut here before submit 
//	freopen ("testcase.PH", "r", stdin );
	string str = "";
	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		stringstream ss (str );
		vector<int> card (5, 0 );
		map<int,int> cnt; cnt.clear();
		rep (i, 5 ){
			int c;
			ss >> c;
			card[i] = c-1;
			cnt[card[i]]++;			
		} // end rep
		string res = yaku[6];
		map<int,int>::iterator it;
		vector<int> num (5, 0 );
		int i = 0;
		for (it = cnt.begin(); it != cnt.end(); it++ ){
			num[i++] = (*it).second;
		} // end for
		sort (ALL (num ), greater<int>() );
		if (cnt.size() == 2 ){
			if (num[0] == 4 ){
				res = yaku[0];	// four card
			}else{
				res = yaku[1];	// full house
			} // end if
		}else
		if (cnt.size() == 3 ){
			if (num[0] == 3 ){
				res = yaku[3];	// three card
			}else
			if (num[0] == 2 ){
				res = yaku[4];	// two pair
			} // end if
		}else
		if (cnt.size() == 4 ){
			res = yaku[5];		// one pair
		}else{
			sort (ALL (card ), greater<int>() );
			bool ok = true;				
			if (card[0]+1 != 13 ){
				rep (i, 4 ){
					if (card[i] == card[i+1] + 1 ) continue;
					ok = false; break;
				} // end rep
			}else{
				if (card[4] + 1 == 1 ) card[4] = 13;
				sort (ALL (card ), greater<int>() );
				rep (i, 4 ){
					if (card[i] == card[i+1] + 1 ) continue;
					ok = false; break;
				} // end rep
			} // end if
			if (ok ){
				res = yaku[2]; 	// straight
			} // end if
		} // end if
		cout << res << endl; 
	} // end loop

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

Measured memory_bytes: 1232
import           Data.Functor ((<$>))
import           Text.Printf  (printf)

sort :: [Int] -> [Int]
sort [] = []
sort [x] = [x]
sort (x:y:ys)
    | x > y = y : sort (x : ys)
    | otherwise = x : sort (y : ys)

main :: IO ()
main = do
    xs <- fmap read . words <$> getLine :: IO [Int]
    let [a, b, c] = sort . sort $ xs
    printf "%d %d %d\n" a b c



Measured memory_bytes: 3652
import fractions

a, b, c, d = map(int, input().split())
c, d = min(c,d), max(c, d)

ans = b - a + 1 

if d%c == 0:#4 8 4 2
    ans -= b//c - a//c + (0 if a%c != 0 else 1)

else:
    x = b // c - a//c + (0 if a%c != 0 else 1)
    y = b // d - a//d + (0 if a%d != 0 else 1)

    lcm = c*d // fractions.gcd(c,d)
    t = b //lcm - a//lcm + (1 if a >= lcm and a%lcm ==0 else 0)

    ans = ans -x-y+t
#    print(x,y,t,lcm,ans)

#    ans += t 


print(ans)

Measured memory_bytes: 5048
#include<stdio.h>

int main(){

  int N,flag,sum=0,temp,i,j;
  int A[100];

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

  for(i=0;i<(N-1);i++){

    for(j=N-1;j>i;j--){
      if(A[j-1]>A[j]){
      temp=A[j-1];
      A[j-1]=A[j];
      A[j]=temp;
      sum++;
      }
    }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[N-1],sum);
}



Measured memory_bytes: 2124
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)

int INF = 2147483647;
struct RUQ{//平方分割 0-index
	int n,rn,bn,Q=0;
	vector<P> a,b;
	RUQ(int n_){
		n = n_; rn = sqrt(n); bn = ceil((double)n/rn);
		a.resize(n,{2147483647,0});
		b.resize(bn,{2147483647,0});
	}
	int value(int s){
		if(a[s].second < b[s/rn].second){
			a[s] = b[s/rn];
		}
		return a[s].first;
	}
	void updete(int s,int t,int x){
		Q++;
		FOR(i,s,t+1){
			if(i%rn==0 && (i+rn-1)<=t){
				b[i/rn] = {x,Q};
				i += rn-1;
			}else{
				a[i] = {x,Q};
			}
		}
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,Q;
	cin >> N >> Q;
	priority_queue<pair<int,P>> pq;
	vector<int> D(Q+1,INF);
	FOR(i,0,N){
		int s,t,x;
		cin >> s >> t >> x;
		pq.push({x,{s-x,t-x}});
	}
	FOR(i,0,Q){
		cin >> D[i];
	}
	RUQ ruq(Q+1);
	FOR(i,0,N){
		int s = pq.top().second.first;
		int t = pq.top().second.second;
		int x = pq.top().first;
		pq.pop();
		s = (lower_bound(D.begin(),D.end(),s)-D.begin());
		t = (lower_bound(D.begin(),D.end(),t)-D.begin());
		ruq.updete(s,t-1,x);
	}
	FOR(i,0,Q){
		int ans = ruq.value(i);
		if(ans==INF) ans = -1;
		cout << ans << '\n';
	}
}


Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define vd vector<dbl>
#define vf vector<float>
#define vs vector<string>




void solve(){
	string a;
	cin >> a;
	if(a == "SUN"){
		cout << 7;
	}
	if(a == "SAT"){
		cout << 1;
	}
	if(a == "MON"){
		cout << 6;
	}
	if(a == "TUE"){
		cout << 5;
	}
	if(a == "WED"){
		cout << 4;
	}
	if(a == "THU"){
		cout << 3;
	}
	if(a == "FRI"){
		cout << 2;
	}
	
	

	
}






int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
 }




Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,ans=""; cin>>s;
  for(char c:s) {
    if(c=='B'&&ans=="") continue;
    if(c=='0') ans+='0';
    else if(c=='1') ans+='1';
    else ans.pop_back();
  }
  cout<<ans;
}

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

#define endl '\n'
#define sz(x) ((int)(x.size()))

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

	long long n, k;
	cin >> n >> k;
	long long p[n+1], c[n+1];
	for(int i=1; i<=n; i++) cin >> p[i];
	for(int i=1; i<=n; i++) cin >> c[i];
	bool seen[n+1];
	long long ans = -1e18;
	for(int i=1; i<=n; i++) {
		int ptr = i;
		long long tot = 0;
		vector <long long> v;
		memset(seen, 0, sizeof seen);
		while(!seen[ptr]) {
			seen[ptr] = 1;
			v.push_back(c[ptr]);
			tot += c[ptr];
			ptr = p[ptr];
		}
		for(int i=0; i<sz(v); i++) {
			if(i) v[i] += v[i-1];
			if(i+1 <= k) ans = max(ans, v[i]);
		}
		for(long long i=max(k - sz(v) * 3, 0LL); i<k; i++) {
			ans = max(ans, (i+1) / sz(v) * tot + ((i+1)%sz(v) > 0) * v[((i+1)%sz(v) - 1)]);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
using graph = vector<vector<int>>;

constexpr int mod = 1e9 + 7;

int main(){
  int n; cin >> n;
  graph g(n+1);
  g[0].emplace_back(1);
  g[1].emplace_back(0);

  REP(i, n-1){
    int x, y; cin >> x >> y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }

  vector<vector<ll>> dp(n+1, vector<ll>(2, -1));
  function<ll(int, int, int)> rec = [&](const int v, const int c, const int b){
    if(dp[v][c] != -1) return dp[v][c];

    ll res = 1LL; bool isChild = true;
    for(const int u: g[v]){
      if(u == b) continue;
       
      isChild = false;
      ll tmp = 0LL;
      REP(nc, 2){
        if(nc == 1 && c == 1) continue;
        (tmp += rec(u, nc, v)) %= mod;
      }

      (res *= tmp) %= mod;
    }

    if(isChild) res = 1LL;

    return dp[v][c] = res;
  };

  cout << rec(0, 0, 0) << endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N, K;
vector<int> A;
vector<vector<ll>> dp(110, vector<ll>(100100, 0));
vector<ll> S(100100, 0);

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

    cin >> N >> K;
    A.resize(N);
    REP(i, N) cin >> A.at(i);

    REP(i, A.at(0) + 1) dp.at(0).at(i) = 1;
    REP(i, K + 1) S.at(i + 1) = S.at(i) + dp.at(0).at(i);

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= K; j++) {
            dp.at(i).at(j) = (S.at(j + 1) - S.at(max(0, j - A.at(i))) + mod) % mod;
        }
        for (int j = 0; j <= K; j++) {
            S.at(j + 1) = (S.at(j) + dp.at(i).at(j) + mod) % mod;
        }
    }

    cout << dp.at(N - 1).at(K) << endl;
    
    return 0;
}

Measured memory_bytes: 87296