akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<set>
#include<unordered_set>
#include <map>
#include <vector>
using namespace std;

int N, Q;
long long int S[200005], T[200005], X[200005];
long long int D[200005];

set<long long int> W;

map<long long int, int> MAP;

vector<long long int> PUSH[500005], POP[500005];

long long int LIMIT[500005];

long long int INF = 99999999999999;

int main(void) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> Q;

	for (int i = 1; i <= N; i++) {
		cin >> S[i] >> T[i] >> X[i];
	}

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

	
	W.insert(-INF);
	W.insert(INF);
	for (int i = 1; i <= N; i++) {
		W.insert(S[i]-X[i]);
		W.insert(T[i]-X[i]);
	}

	int q = 1;
	for (auto y : W) {
		MAP[y] = q;
		q++;
	}
	

	for (int i = 1; i <= N; i++) {
		PUSH[MAP[S[i] - X[i]]].push_back(X[i]);
		POP[MAP[T[i] - X[i]]].push_back(X[i]);
	}
	
	 //692 msec
	int NUM = W.size();
	for (int i = 0; i <= NUM+1; i++) { LIMIT[i] = INF; }

	set<long long int> H;
	H.insert(INF);
	
	for (int i = 1; i <= NUM; i++) {
		for (int j = 0; j < (int)POP[i].size(); j++) {
			H.erase(POP[i][j]);
		}
		for (int j = 0; j < (int)PUSH[i].size(); j++) {
			H.insert(PUSH[i][j]);
		}

		auto it = H.begin();
		LIMIT[i] = (*it);
	}
	
	auto it = W.begin();
	for (int i = 1; i <= NUM; i++) {
		//cout << (*it)<<" " <<LIMIT[i] << endl;
		//it++;
	}
	  //822 msec

	
	for (int i = 1; i <= Q; i++) {
		if (W.count(D[i]) > 0) {
			auto it = W.find(D[i]);
			//int y = distance(W.begin(), it)+1;
			int y = MAP[(*it)];
			//int y = 1;
			//cout << "y= " << y << endl;
			if (LIMIT[y] == INF) {
				cout << -1 << endl;
			}
			else {
				cout << LIMIT[y] << endl;
			}
		}
		else {
			W.insert(D[i]);
			auto it = W.find(D[i]);
			it;
			//int y = distance(W.begin(), it);
			it--;
			int y = MAP[(*it)];
			if (LIMIT[y] == INF) {
				cout << -1 << endl;
			}
			else {
				cout << LIMIT[y] << endl;
			}
			W.erase(D[i]);
		}
		
	}
	
	return 0;
}

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

#define int long long

typedef long long li;
typedef long double ld;

void solve();
int32_t main() {
    #ifndef ONLINE_JUDGE
      //  freopen("input.txt", "r", stdin);
    #endif
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
const int N = 2e5;
int n;
int p[N];
void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 2; i < n; ++i) {
		vector<int> lol;
		lol.push_back(p[i]);
		lol.push_back(p[i - 1]);
		lol.push_back(p[i + 1]);
		sort(lol.begin(), lol.end());
		if (lol[1] == p[i]) ans++;
	}
	cout << ans;
}

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

int main(){
    int N; cin >> N;
    vector<int> cnt(N+1);
    for(int i=1; i<=N; ++i) cin >> cnt[i];
    cnt[0] = 0;
    sort(all(cnt));
    for(int j=1; j<=N; ++j){
        if(cnt[j-1]==cnt[j]){
            cout << "NO" << endl; return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    ll ans = n * m / __gcd(n, m);
    ll a = ans / m, b = ans / n;
    forn(i, n / a)
    {
        if (s[i * a] != t[i * b])
            return cout << -1, 0;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
N,M=map(int,input().split())
PY=[[0,0]]
ans=[]
for m in range(M):
    L=list(map(int,input().split()))
    L.append(m+1)
    PY.append(L)
PY.sort(key=lambda x:(x[0],x[1]))

for i in range(M):
    number=""
    if PY[i+1][0]!=PY[i][0]:
        x=1
    else:
        x+=1
    number+=str(PY[i+1][0]).zfill(6)
    number+=str(x).zfill(6)
    ans.append([number,PY[i+1][2]])

ans.sort(key=lambda x:x[1])

for i in ans:
    print(i[0])


Measured memory_bytes: 45608
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a > 8 || b > 8) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}


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

int main(){
  int s;
  cin >> s;
  int a[10000];
  rep(i, 10000) {
    a[i] = 0;
  }
  a[s] = 1;
  FOR(i, 2, 1000002) {
    if (s % 2 == 0) {
      s /= 2;
    }else {
      s = s * 3 + 1;
    }
    if (a[s] == 0) {
      // cout << s << endl;
      a[s] = i;
    }else {
      cout << i << endl;
      exit(0);
    }
  }
}


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

int main()
{
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N);
  for (int i = 0; i < N; ++i)
  {
    X[i].resize(D);
    for (int j = 0; j < D; ++j)
      cin >> X[i][j];
  }
  long long count = 0;
  for (int i = 0; i < N - 1; ++i)
  {
    for (int j = i + 1; j < N; ++j)
    {
      long long square = 0;
      for (int d = 0; d < D; ++d)
        square += (X[i][d] - X[j][d])*(X[i][d] - X[j][d]);
      long long root = static_cast<long long>(sqrt(square));
      if (root*root == square)
        ++count;
    }
  }
  cout << count;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAX 100010
ll N,a[MAX],b[MAX],c[MAX];
ll dp[MAX][3];
bool been[MAX][3];
ll f(int i,int s){
    if(i == N) return 0;
    if(been[i][s]) return dp[i][s];
    been[i][s] = true;
    if(s == 0)
        return dp[i][s] = a[i]+max(f(i+1,1),f(i+1,2));
    if(s == 1)
        return dp[i][s] = b[i]+max(f(i+1,0),f(i+1,2));
    if(s == 2)
        return dp[i][s] = c[i]+max(f(i+1,0),f(i+1,1));

}
int main(){
    cin >> N;
    for(int i = 0;i<N;i++) cin >> a[i] >> b[i] >> c[i];
    cout << max(f(0,0),max(f(0,1),f(0,2))) << '\n';
    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
 
using namespace std;
 
long long dp[5001];
 
int main()
{
	int n,a,x;
	cin >> n >> a;
	dp[2500]=1;
	for (int i=0; i<n; i++)
	{
		cin >> x;
		x -= a;
		if (x > 0)
			for (int s=5000; s>=x; s--)
				dp[s]+=dp[s-x];
		else
			for (int s=0; s-x<=5000; s++)
				dp[s]+=dp[s-x];
	}
	cout << dp[2500]-1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
	#include <iomanip>
	#include<math.h>
	#include<list>
	#include <algorithm>
	#include<set>
	#include<vector>
	#include<math.h>
	#include<map>
	#include<string>
	#include <numeric>
	#include <queue>
	#include <sstream>
	#include <bitset>
	#include<stack>

	using namespace std;
	using ll = long long;
	using vll = vector<long long>;
	using sll = set<long long>;


	template<typename T>
	T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
	template<typename T>
	T lcm(T a, T b) { return a / gcd(a, b) * b; }

	template<typename T>
	map<T, T> getPrimeFactor(T n) {
		map<T, T> res;
		for (T i = 2; i * i <= n; ++i) {
			while (n % i == 0) {
				res[i] ++;
				n /= i;
			}
		}
		if (n != 1) res[n] = 1;
		return res;
	}

	template<typename T>
	bool IsPrimeNumber(T num)
	{
		if (num <= 2) return true;
		else if (num % 2 == 0) return false;

		double sqrtNum = sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2)
		{
			if (num % i == 0)
			{
				return false;
			}
		}

		return true;
	}

	long long modinv(long long a, long long m) {
		long long b = m, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= m;
		if (u < 0) u += m;
		return u;
	}

	// 繰り返し二乗法
	ll pow2(ll n, ll p, ll mod) {
		if (p == 0 || n == 1) {
			return 1;
		}
		else {
			ll ret = pow2(n * n % mod, p / 2, mod);
			if (p % 2 == 1) {
				ret *= n;
			}
			return ret % mod;
		}
	}


	#define rep(i,s,e) for(ll i=s;i<e;i++)
	#define repeq(i,s,e) for(ll i=s;i<=e;i++)

	int main() {
		ll X;
		cin >> X;

		ll ans;
		if (X < 600) {
			ans = 8;
		}
		else if(X<800){
			ans = 7;
		}
		else if (X < 1000) {
			ans = 6;
		}
		else if (X < 1200) {
			ans = 5;
		}
		else if (X < 1400) {
			ans = 4;
		}
		else if (X < 1600) {
			ans = 3;
		}
		else if (X < 1800) {
			ans = 2;
		}
		else if (X < 2000) {
			ans = 1;
		}
		cout << ans << endl;
		return 0;
	}


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

signed main() {
    int A, B;
    cin >> A >> B;

    if ((A + B) % 2) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << (A + B) / 2 << endl;
    }
}


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

int main(void)
{
    string s;
    getline(cin,s);
        for(int i=0;i<s.size();i++){
            char c=s[i];
            if('A'<=c && c<='Z'){
                c=c+32;
            }
            else if('a'<=c && c<='z'){
                c=c-32;
            }
            cout<<c;
    }
    cout<<endl;
}


Measured memory_bytes: 3064
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String o = sc.nextLine();
		String e = sc.nextLine();
		
		System.out.println(mekePw(o,e));
		
		

	}
	
	static String mekePw(String o, String e) {
		StringBuilder pw = new StringBuilder();
		int l = o.length()+e.length();
		int counto = 0,counte = 0;
		for(int i=1; i<=l; i++) {
			if(i%2==0) {
				pw.append(e.charAt(counte));
				counte += 1;
			}else {
				pw.append(o.charAt(counto));
				counto += 1;
			}
		}
		
		return pw.toString();
		
	}

}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
} 

int check(vector<int>&nums) {
	int sum = 0;
	for (int i = 0; i < nums.size(); ++i) {
		int anum;
		if (i % 2)anum = nums[i] * 2;
		else anum = nums[i];

		if (anum >= 10)anum = anum / 10 + anum % 10;
		sum += anum;
	}
	return sum % 10 == 0;
}

int memo[10][2];

int getnum( int num, const bool iseven) {
	return memo[num][iseven];
}

int main() {
	for (int i = 0; i < 10; ++i) {
		for (int j = 0; j < 2; ++j) {
			memo[i][j] = j ? (i * 2) % 10 + (i * 2) / 10 : i;
		}
	}
	int N; cin >> N;
	vector<int>asta_doubles;
	int ini_sum = 0;
	int evennum = 0;
	int oddnum = 0;
	{
		string st; cin >> st;
		for (int i = 0; i < st.size(); ++i) {
			char c = st[i];
			if (c == '*') {
				asta_doubles.emplace_back((st.size()-i) % 2==0);
			}
			else ini_sum += getnum(c - '0', (st.size() - i) % 2 == 0);
		}
	}
	
	int M; cin >> M;
	vector<int>kouhos(M);
	for (int i = 0; i < M; ++i) {
		cin >> kouhos[i];
	}

	int ans = 0;
	for (int i = 0; i < powint(M, asta_doubles.size()); ++i) {
		int n(i);
		int asum = ini_sum;
		for (int j = 0; j < asta_doubles.size(); ++j) {
			int anum = kouhos[n%M];
			n /= M;
			asum += memo[anum][asta_doubles[j]];
		}
		
		ans += asum % 10==0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3248
# -*- coding:utf-8 -*-
H, W = map(int, input().split())
a = []
b = []
for tmp in range(H):
    a.append(list(input()))
add = [ '#' for tmp in range(W+2) ]
b.append(add)
for tmp in range(H):
    c = ['#'] + a[tmp] + ['#']
    b.append(c)
b.append(add)
for tmp in range(H+2):
    print(''.join(b[tmp]))

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

int main() {

  char X,Y;
  cin >> X >> Y;
  
  if(X<Y){
  cout << "<" << endl;
  }else if(X==Y){
    cout << "=" << endl;
  }else {
    cout << ">" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}
 
ll solve(ll N){
    ll ans = 0;
    return ans;
}
 
int main(){
    ll A,B,K; cin >> A >> B >> K;
    if(A >= K) cout << A-K << " " << B << '\n';
    else if(A + B <= K) cout << "0 0" << '\n';
    else cout << 0 << " " << (A+B)-K << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;

  ll oN = N;

  ll s = 0;
  while (N > 0) {
    s += N % 10;
    N /= 10;
  }

  if (oN % s == 0) {
    COUT("Yes");
  } else {
    COUT("No");
  }
  return 0;
}

Measured memory_bytes: 3636
n, m = map(int, input().split())
corrects = [0] * n
penalties = [0] * n
penalties_sum = 0
for i in range(m):
    p, S = input().split()
    p = int(p) - 1
    if corrects[p]:
        continue
    if S == 'AC':
        corrects[p] = 1
        penalties_sum += penalties[p]
    elif S == 'WA':
        penalties[p] += 1

print("{} {}".format(sum(corrects), penalties_sum))

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}
int cnt2, cnt4;
int main(int argc, char const *argv[]) {
	int n = read();
	for (int i = 1; i <= n; i++) {
		int x = read();
		if (x % 4 == 0) cnt4 ++;
		else if (x % 2 == 0) cnt2 ++;
	}
	if (cnt4 * 2 + (cnt2 ? cnt2 : 1) >= n) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define C std::cout<<
#define F(i,x) for(i=x;i<N;i++)
main(){for(int N;std::cin>>N&&N;){int A[N],i,j;F(i,0)std::cin>>A[i];F(i,0){F(j,i+1)if(A[j-1]+1!=A[j])break;if(i)C" ";C A[i];if(j>i+1){C'-'<<A[j-1];i=j-1;}}C '\n';}}

Measured memory_bytes: 1164
//
//  main.cpp
//  CODE
//
//  Created by mac on 2019/8/21.
//  Copyright © 2019 mac. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, k, x, y;

int main()
{
    cin >> n >> k >> x >> y;
    
    if(n < k){
        cout << n * x << endl;
    } else {
        cout << k * x + (n - k) * y << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=700,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	if(a<=c&&c<=a+b){cout<<"YES";}
	else{cout<<"NO";}



	cout<<endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>

static int dd(const std::pair<int, int>& p1, const std::pair<int, int>& p2) {
    return std::abs(p1.first - p2.first) + std::abs(p1.second - p2.second);
}
int main() {
    int n, m; std::cin >> n >> m;
    std::vector<std::pair<int, int>> s(n);
    std::vector<std::pair<int, int>> p(m);

    for (int i = 0; i < n; i++) {
        int a, b; std::cin >> a >> b;
        s[i] = std::make_pair(a, b);
    }

    for (int j = 0; j < m; j++) {
        int c, d; std::cin >> c >> d;
        p[j] = std::make_pair(c, d);
    }

    std::vector<int> g(n);
    for (int i = 0; i < n; i++) {
        int pp = 0;
        int ds = dd(s[i], p[0]);
        for (int j = 1; j < m; j++) {
            int dx = dd(s[i], p[j]);
            if (dx < ds) {
                pp = j;
                ds = dx;
            }
        }
        g[i] = pp+1;
    }

    for (int i = 0; i < n; i++) {
        std::cout << g[i] << std::endl;
    }
    return 0;
}

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

int main(){
  int n, m; cin >> n >> m;
  vector<int> a(m);
  
  int sum = 0;
  
  for(int i = 0; i < m; i++){
  	cin >> a[i];
  	sum += a[i];
  }
  //cout << sum << endl;
  if(sum <= n) cout << n - sum << endl;
  else cout << -1 << endl;
}

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

using namespace std;




int main()
{
	int N, K;

	cin >> N >> K;

	if (N == K) {
		printf("%d", 1);
		return 0;
	}

	vector<int> list(N);
	vector<int> pp(N,0);
	vector<int> list_min(N,0);
	vector<int> list_max(N,0);
	deque<int> deq_min_index;
	deque<int> deq_max_index;

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

	pp[0] = 1;
	for(int ni = 1; ni < N; ni++){
		if(list[ni] > list[ni-1]){
			pp[ni] = 1;
		}		
	}

	int T = N - K + 1; 

	vector<int> Cs(T,0);

	for (int ki = 0; ki < K; ki++){
		Cs[0] += pp[ki];
	}
	for (int ti = 1; ti < T; ti++){
		Cs[ti] = Cs[ti-1] - pp[ti] + pp[ti + K  -1];
	}

	deq_min_index.push_back(0);
	deq_max_index.push_back(0);
	for (int ki = 1; ki < K; ki++){
		while(deq_min_index.size() > 0  && list[ki] < list[deq_min_index.back()]){
			deq_min_index.pop_back();
		}
		deq_min_index.push_back(ki);
		while(deq_max_index.size() > 0 && list[ki] > list[deq_max_index.back()]){
			deq_max_index.pop_back();
		}
		deq_max_index.push_back(ki);
	}
	list_min[0] = list[deq_min_index.front()];
	list_max[K - 1] = list[deq_max_index.front()];

	for(int ni = 1; ni < T; ni++){
		if(deq_min_index.front() < ni){
			deq_min_index.pop_front();
		}
		while(deq_min_index.size() > 0 && list[ni + K - 1] < list[deq_min_index.back()] ){
			deq_min_index.pop_back();
		}
		deq_min_index.push_back(ni + K -1);
		list_min[ni] = list[deq_min_index.front()];

		if(deq_max_index.front() < ni){
			deq_max_index.pop_front();
		}
		while(deq_max_index.size() > 0 && list[ni + K - 1] > list[deq_max_index.back()] ){
			deq_max_index.pop_back();
		}
		deq_max_index.push_back(ni + K -1);
		list_max[ni+K-1] = list[deq_max_index.front()];
	}

	vector<int> flags(T,1);
	int cnt = 0;
	for (int ti = 0; ti < T; ti++){
		if (Cs[ti] == K){
			cnt++;
			if (cnt > 1){
				flags[ti] = 0;
			}
		}
	}

	for (int ti = 1; ti < T; ti++){
		if (list_min[ti - 1] == list[ti - 1] && list_max[ti + K - 1] == list[ti + K - 1]) {
			flags[ti] = 0;
		}
	}

	int ans = 0;
	for (int ti = 0; ti < T; ti++) {
		if (flags[ti] == 1)ans++;
	}

	printf("%d",ans);


	return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<vector<int> > T(2, vector<int>(N + 1, 0));
  for (int i = 0; i < 2; ++i) {
    for (int j = 1; j <= N; ++j) {
      scanf("%d", &T[i][j]);
      T[i][j] += T[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans = max(ans, T[0][i] + T[1][N] - T[1][i - 1]);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll R, G, B;
    
    cin >> R >> G >> B;
    
    if((R * 100 + G * 10 + B) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,num,d;
	int xmax,xmin,ymax,ymin;
	int x[1000],y[1000];
	scanf("%d",&num);
	while(num != 0){
		xmax = 0;
		xmin = 0;
		ymax = 0;
		ymin = 0;
		x[0] = 0;
		y[0] = 0;
		for(int i = 1; i < num; i++){
			scanf("%d %d",&n,&d);
			if(d == 0){
				x[i] = x[n] - 1;
				y[i] = y[n];
				if(x[i] < xmin){
					xmin = x[i];
				}
			}else if(d == 1){
				x[i] = x[n];
				y[i] = y[n] - 1;
				if(y[i] < ymin){
					ymin = y[i];
				}
			}else if(d == 2){
				x[i] = x[n] + 1;
				y[i] = y[n];
				if(x[i] > xmax){
					xmax = x[i];
				}
			}else if(d == 3){
				x[i] = x[n];
				y[i] = y[n] + 1;
				if(y[i] > ymax){
					ymax = y[i];
				}
			} 
		}

		printf("%d %d\n",xmax - xmin + 1,ymax - ymin + 1);
		scanf("%d",&num);
	}
	return 0;
}

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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    if((10*g + b) % 4 == 0 ){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

int searchX(int n, int x){
  int cnt = 0;
  for(int i = 1; i<=n; i++){
    for(int j = i+1; j<=n; j++){
      for(int k = j+1; k<=n; k++){
        if (i+j+k == x) cnt++;
      }
    }
  }
  return cnt;
}

int main(){

  int n, x;
  while(true){
    cin >> n >> x;
    if(n == 0 && x == 0) return 0;
    cout << searchX(n,x) << endl;
  }
  return 0;
}


Measured memory_bytes: 3100
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  vector<int> A(3); loop(i,0,3) cin >> A[i];
  int k; cin >> k;
  while (k--) {
    sort(A.rbegin(), A.rend());
    A[0] *= 2;
  }
  cout << A[0]+A[1]+A[2] << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(int i=0;i<n;i++)
int main(){
  int h,n;	cin >> h >> n;
  vector<pair<int,int>>	ab(n);
  rep(i,n){
    cin >> ab[i].first >> ab[i].second;
  }
  
  vector<int> dp(h+1,1001001001);
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<h;j++){
      int nj=min(j+ab[i].first,h);
      dp[nj]=min(dp[nj],dp[j]+ab[i].second);
    }
  }
  cout << dp[h];
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll a, b, c, n;
string s;
int main(){
	cin >> n >> a >> b;
	p(min(n*a, b));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector

int n,p;
map<int,int>m;


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    cin>>n>>p;
    for(int i = 2 ; i*i<=p ; i++)
    {
        if(p%i==0)
        {
            while(p%i==0)
            {
                m[i]++;
                p/=i;
            }
        }
    }
    if(p!=1)
    {
        m[p] = 1;
    }
    int gcd = 1;
    for(auto i : m)
    {
        int x = i.Y/n;
        forn(j,1,x)gcd*=i.X;
    }
    cout<<gcd;
    return 0;
}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
 
struct pos{
    int x;
    int y;
    int dis;
};
 
int main(){
    int w, h;
    while(cin >> w >> h){
        if(w == 0 || h == 0) break;
        int map[65][65];
        for(int i = 0; i < 65; i++){
            for(int j = 0; j < 65; j++){
                map[j][i] = 1;
            }
        }
 
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                map[i*2-1][j*2-1] = 0;
            }
        }
 
        int l = 1;
        for(int i = 1; i <= h*2-1; i++){
            if(i % 2 == 1){ 
                for(int j = 1; j <= w-1; j++){
                    int input;
                    cin >> input;
                    map[l*2-1][j*2] = input;
                }
            }else{
                for(int j = 1; j <= w; j++){
                    int input;
                    cin >> input;
                    map[l*2][j*2-1] = input;
                }
                l++;
            }
        }
 
        queue<pos> q;
        map[1][1] = 1;
        pos p;
        p.x = 1;
        p.y = 1;
        p.dis = 1;
        q.push(p);
        int x1[] = {-1, 0, 1, 0}, y1[] = {0, -1, 0, 1};
        while(!q.empty()){
            p = q.front();
            q.pop();
            for(int i = 0; i < 4; i++){
                pos p1 = p;
                p1.x += x1[i]; p1.y += y1[i];
                if(!map[p1.x][p1.y]){
                    //p1.x += x1[i]; p1.y += y1[i];
                    p1.dis++;
                    map[p1.x][p1.y] = p1.dis;
                    q.push(p1);
                }
            }
        }
 
        int ans = (map[h*2-1][w*2-1] + 1) /2;
 
        cout << ans << endl;
 
    }
}

Measured memory_bytes: 1228
#include<stdio.h>
main(){
  int a,b,c,d;
 
  scanf("%d %d %d",&a,&b,&c);
  d=c-a+b;
  if(d>0){
    
  printf("%d",d);
  }
  else{
    printf("0");
  }
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int calcCost(int N, vector<int> heights) {

  // cout << "here\n";

  // init dp array
  vector<int> dp(N, 0);

  dp[0] = 0;
  dp[1] = abs(heights[1] - heights[0]);
  if (N == 2) {
    return dp[1];
  }

  int cost;
  int firstJump;
  int secondJump;
  for (int i = 2; i < N; i++) {
    firstJump = abs(heights[i]-heights[i-1]);
    secondJump = abs(heights[i]-heights[i-2]);
    cost = min(firstJump+dp[i-1], secondJump+dp[i-2]);
    dp[i] = cost;
  }
  return dp[N-1];
}

int main() {

  int numStones;
  int height;

  cin >> numStones;
  if (numStones < 2 || numStones > 100000) {
    cout << 0;
    return 0;
  }

  vector<int> heights(numStones + 1, -1);
  // cout << numStones << "\n";
  for (int i = 0; i < numStones; i++) {
    cin >> height;
    heights[i] = (int)height;
    // printf("enter\n");
    // heights.insert(heights.end(), height);
    // printf("exit\n");
  }

  // for (int i = 0; i < numStones; i++) {

  //   cout << heights[i];
  // }
  int cost = calcCost(numStones, heights);
  
  cout << cost;
  return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int D; cin >> D;
    vector<int> c(26, 0);
    for(auto& t : c) cin >> t;
    vector s(D, vector(26, 0));
    for(auto& v : s){
        for(auto& t : v) cin >> t;
    }
    vector<int> last(26, 0);
    long long score = 0;
    for(int i=1;i<=D;i++){
        int t; cin >> t;
        --t;
        score += s[i-1][t];
        last[t] = i;
        for(int j=0;j<26;j++){
            score -= c[j] * (i - last[j]);
        }
        cout << score << endl;
    }
}

Measured memory_bytes: 3668
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,A = ilint()
B = deque()
for i in range(N):
    if i%2==0:
        B.append(A[i])
    else:
        B.appendleft(A[i])
B = list(B)
if N%2!=0:
    B = B[::-1]
lprint(B,' ')

Measured memory_bytes: 106164
#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>;

	int n,m,q;
	vector<int> a,b,c,d;
	int ans;

	void dfs(vector<int> A){
		if(A.size() == n+1) {
			int now = 0;
			rep(i,q){
				if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
			}
			ans = max(ans,now);
			return;
		}
		A.push_back(A.back());
		while(A.back() <= m){
			dfs(A);
			A.back()++;
		}
	}

int main(){
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	dfs(vector<int>(1,1));
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

int main(void) {
    long long n, m;
    cin >> n >> m;
    if (n > m / 2) {
        cout << m / 2 << endl;
    } else {
        cout << n + (m - n * 2) / 4 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;


signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

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

   int a,b,c,k;
  cin>>a>>b>>c;
  cin>>k;
  int f=0;
  while(k--)
  {
    if (b<=a)
      b=2*b;
    else if (c<=b)
      c=2*c;
    else{
      f=1;
      break;
    }
  }
  if (f || (b>a && c>b))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	ll a, b, k;
	cin >> a >> b >> k;
	ll a_ans, b_ans;
	a_ans = a - k;
	b_ans = (a_ans < 0) ? b - abs(a - k) : b;
	a_ans = (a_ans < 0) ? 0 : a_ans;
	b_ans = (b_ans < 0) ? 0 : b_ans;
	cout << a_ans << " " << b_ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

ll tree[4*200003],a[200003],h[200003],dp[200003];

void build(int node,int start,int end){
	if(start == end){
		tree[node] = 0;
	}
	else{
		int m = (start+end)/2;
		build(2*node,start,m);
		build(2*node+1,m+1,end);
		tree[node] = max(tree[node*2],tree[node*2+1]);
	}
}

void update(int node,int start,int end,int idx,ll val){
	if(start == end){
		tree[node] = max(val,tree[node]);
	}
	else{
		int m = (start+end)/2;
		if(idx>=start && idx<=m)
		{
			update(2*node,start,m,idx,val);
		}
		else{
			update(2*node+1,m+1,end,idx,val);
		}
		tree[node] = max(tree[node*2],tree[node*2+1]);
	}
}

ll query(int node,int l,int r,int start,int end){
	if(r<start || l>end){
		return 0;
	}
	if(l<=start && r>=end){
		return tree[node];
	}

	int m = (start+end)/2;
	return max(query(2*node,l,r,start,m),query(2*node+1,l,r,m+1,end));

}
int main(){
	int n,i;
	scanf("%d",&n);
	build(1,1,n);
	for(i=1;i<=n;i++){
		scanf("%lld",&h[i]);
	}
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	dp[0]=0;
	for(i=1;i<=n;i++){
		ll val = a[i] + query(1,1,h[i]-1,1,n);
		update(1,1,n,h[i],val);
		dp[i]= max(dp[i-1],val); 
	}
	ll ans=dp[n];
	printf("%lld\n",ans );
	
	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int ans=0;
void Main(){
    string s;
    cin >> s;
    ans = count(ALL(s), 'R');
    if(s[1] == 'S'){
        ans = min(ans, 1);
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

vector<ll> bitconversion(ll i, ll n, ll N){
    ll x = 1;
    rep(j,N){
        x *= n;
    }
    vector<ll> vec(N);
    rep(j,N){
        x /= n;
        vec[j] = i / x;
        i -= x * vec[j];
    }
    return vec;
}

int main(){
    ll N;
    cin >> N;
    N *= 2;
    vector<bool> isprime(40000001, true);
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= 40000000; i++){
        if (isprime[i]){
            for (ll j = 2; j * i <= 40000000; j++){
                isprime[i * j] = false;
            }
        }
    }
    vector<ll> divisor(0);
    for (ll i = 2; i * i <= N; i++){
        if (isprime[i]){
            ll now = 1;
            while(true){
                if (N % i != 0){
                    break;
                }
                else{
                    now *= i;
                    N /= i;
                }
            }
            if (now != 1) divisor.push_back(now);
        }
    }
    if (N != 1){
        divisor.push_back(N);
    }
    ll len = divisor.size();
    
    ll num = 1;
    rep(i,len){
        num *= 2;
    }
    
    ll ans = 1e16;
    for (ll i = 0; i < num; i++){
        vector<ll> vec = bitconversion(i,2,len);
        ll k0 = 1;
        ll k1 = 1;
        rep(j,len){
            if (vec[j] == 0) k0 *= divisor[j];
            if (vec[j] == 1) k1 *= divisor[j];
        }
        ll y;
        if (k0 == 1){
            y = 1;
        }
        else if (k1 == 1){
            y = k0 + 1;
        }
        else{
            y = inv_mod(k1, k0);
        }
        ll k = y * k1 - 1;
        ans = min(ans, k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8292
#include<stdio.h>

int main()
{
     int n,T,c,t,i,f=10000;
     scanf("%d %d",&n,&T);
     for(i=1; i<=n; i++)
      {
          scanf("%d %d",&c,&t);
          if(t<=T && c<f)
               f=c;
               
               
        
      }
    if(f==10000)
       printf("TLE\n");
    else
    printf("%d\n",f);
    
    return 0;
}

Measured memory_bytes: 128
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

#n = int(input())
#s = int(input())
#a, b, c, x, y = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
#s = input()

#list = list(s)
#a = [0 for _ in range(n+1)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]

n = int(input())
word_list = [[] for i in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = [int(i) for i in input().split()]
        word_list[i].append((x-1,y))

ans = 0

for i in range(2**n):
    peoples = []
    flag = 1
    for j in range(n):
        if(i >> j & 1):
            peoples.append(1)
        else:
            peoples.append(0)

    for k in range(n):
        if peoples[k] == 1:
            words = word_list[k]
            for word in words:
                if peoples[word[0]] != word[1]:
                    flag = 0
                    break

    if flag:
        ans = max(ans,sum(peoples))

print(ans)

Measured memory_bytes: 12028
#include <iostream>

using namespace std;

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

    int ans = 0;
    for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){
            int z = S - x - y;
            if(z >= 0 && z <= K){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner s = new Scanner(System.in);
		String n = s.nextLine();
		
		long ans = 0;
		
		for(int i = 0; i < n.length(); i++) {
			
			ans += n.charAt(i) - '0';
			
		}
		
		System.out.println(((ans % 9 == 0) ? "Yes" : "No"));
		

	}

}

Measured memory_bytes: 40988
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = LIST()
A.sort()

ans = ((A[2]-A[0])//2) + ((A[2]-A[1])//2)

if (A[2]-A[0])%2 +  (A[2]-A[1])%2 == 1:
	ans += 2
elif (A[2]-A[0])%2 +  (A[2]-A[1])%2 == 2:
	ans += 1

print(ans)

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

using std::cin;
using std::cout;
using std::endl;

using std::string;

int abs(int a) { return a < 0 ? -a : a; }

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

    int a, b, c;
    a = b = c = 0;
    for (char i : s) {
        if (i == 'a') {
            a++;
        } else if (i == 'b') {
            b++;
        } else if (i == 'c') {
            c++;
        }
    }

    while (a >= 3 && b >= 3 && c >= 3) {
        a -= 3;
        b -= 3;
        c -= 3;
    }

    bool ans = abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1;
    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 888
N = int(input())
hap = []
for i in range(N):
	abc = list(map(int, input().split()))
	hap.append(abc)

dp = []
for i in range(N):
	dp.append([0,0,0])

dp[0] = hap[0]

for x in range(N-1):
	i = x+1
	dp[i][0] = hap[i][0]+max(dp[i-1][1], dp[i-1][2])
	dp[i][1] = hap[i][1]+max(dp[i-1][0], dp[i-1][2])
	dp[i][2] = hap[i][2]+max(dp[i-1][0], dp[i-1][1])

print(max(dp[N-1]))

Measured memory_bytes: 76376
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.BufferedOutputStream;
public class Main
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int s = sc.nextInt(); int w = sc.nextInt();
        if (w >= s) {
            out.println("unsafe");
        } else out.println("safe");
 
        out.close();
    }
 
 
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
 
 
 
    }
 
}

Measured memory_bytes: 32956
#include <iostream>

using namespace std;

int player[55];

int main(void){
	int n,p;
	while(cin >> n >> p){
		if(n==0&&p==0)
			break;
		for(int i=0;i<n;++i) player[i]=0;

		int cur=0;
		int ans=-1;
		int center=p;
		while(ans==-1){
			if(center){
				player[cur]++;
				center--;
			}else{
				center+=player[cur];
				player[cur]=0;
			}
			cur=(cur+1)%n;
			for(int i=0;i<n;++i)
				if(player[i]==p)
					ans=i;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
using uint = unsigned int;

uint N, S;

int main() {
  scanf("%u", &N);

  S = 0;
  uint buf = N;
  while(buf != 0) {
    S += buf % 10;
    buf /= 10;
  }

  if (N % S == 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    ret = []
    stack = [('', ord('a'))]
    while stack:
        s, c = stack.pop()
        if len(s) == n:
            ret.append(s)
        else:
            for x in range(ord('a'), c+1):
                stack.append((s+chr(x), c+1 if c == x else c))

    return '\n'.join(sorted(ret))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 13504
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	lint n,out=0,x;
	cin>>n;
	for(x=1;x<1001001;x++){
		if((n-x)%x==0 && (n-x)/x>x) out+=(n-x)/x;
	}
	cout<<out<<endl;
}


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

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

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,ans=0;
    cin>>n;
    for(int x=1;x<=n;x++){
      for(int y=1;y<=n;y++){
        for(int z=1;z<=n;z++){
          ans+=gcd(gcd(x,y),z);
        }
      }
    }
    cout<<ans<<'\n';
    return 0;
}
/*

*/


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Schema;

class IDONTKNOWCSHARP
{

    public static void Main()
    {
        long[] values = Convert(GetLines());

        long[] test = new long[4];
        test[0] = values[0] * values[2];
        test[1] = values[0] * values[3];
        test[2] = values[1] * values[2];
        test[3] = values[1] * values[3];

        long max = long.MinValue;
        foreach (long value in test)
        {
            if (value > max)
                max = value;
        }


        Console.WriteLine(max);
 //      Console.ReadLine();
    }


    static long[] Convert(string[] v)
    {
        var temp = new long[v.Length];

        for (int i = 0; i < temp.Length; i++)
        {
            temp[i] = long.Parse(v[i]);
        }

        return temp;
    }


    static string[] GetLines()
    {
        return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
    }
}

Measured memory_bytes: 27540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i, n) for (int i = 0; i < n; i++)
int main()
{
    int N; cin >> N;
    vector<vector<pair<int, int>>> node(N);
    REP(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        node[a].push_back(make_pair(b, c));
        node[b].push_back(make_pair(a, c));
    }
    int Q, K; cin >> Q >> K;
    K--;
    vector<Int> distK(N);
    function<void(int, int, Int)> dfs;
    dfs = [&](int x, int prev, Int dist) {
        distK[x] = dist;
        for (auto edge : node[x]) {
            if (edge.second == 0) continue;
            if (edge.first != prev) {
                dfs(edge.first, x, dist + edge.second);
            }
        }
    };
    dfs(K, -1, 0);
    REP(i, Q) {
        int x, y; cin >> x >> y;
        x--; y--;
        cout << distK[x] + distK[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 15872