akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<ll,ll> pii;
typedef map<int,int> mii;
typedef vector<int> V;

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

inline int read() {
	int input=0,v=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')v=-1,c=getchar();
	while(c>='0'&&c<='9')input=input*10+c-'0',c=getchar();
	return v*input;
}

int a[100010];
char s[100010];
int main() {
	int n,t;
	sc(n),sc(t);
	scs(s+1);
	up(i,1,n-1)
	if(s[i]=='A'&&s[i+1]=='C')a[i]++;
	up(i,1,n)a[i]+=a[i-1];
	up(i,1,t){
		int l,r;sc(l),sc(r);
		pr(a[r-1]-a[l-1],'\n');
	}
}

Measured memory_bytes: 1280
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

A = sorted(A, reverse = True)
import heapq as hq
q = []
ans = 0
for i in range(len(A)):
  if q:
    ans += -hq.heappop(q)
  for j in range(min(i + 1,2)):
    hq.heappush(q, -A[i])
    
print(ans)

Measured memory_bytes: 31248
G = [120001,60001,30001,15001,3001,901,601,301,91,58,31,7,4,1]

def insertion_sort(array,g):
    for i in range(g,len(array)-1):
        v = array[i]
        j = i-g
        while j>=0 and array[j] > v:
            array[j+g] = array[j]
            j = j-g
            array[-1] += 1
        array[j+g] = v

def shell_sort(array,G):
    for i in G:
        insertion_sort(array,i)


n = int(input())
arr = [int(input()) for i in range(n)] + [0]
Gn = [i for i in G if i <= n]


shell_sort(arr,Gn)
print(len(Gn))
print(' '.join([str(i) for i in Gn]))
print(arr[-1])
[print(i) for i in arr[:-1]]

Measured memory_bytes: 62964
N,M = map(int,input().split())
LR = [tuple(map(int,input().split())) for i in range(M)]

imos = [0] * (N+1) 
for l,r in LR:
    imos[l-1] += 1
    imos[r] -= 1

for i in range(N):
    imos[i+1] += imos[i]
print(imos.count(M))

Measured memory_bytes: 20468
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long n,s=0;
    cin>>n;
    long a[n];
    f(i,0,n-1){
       cin>>a[i];
       s+=a[i];
    }
    
    sort(a,a+n,greater<int>());
    
    cout<<s-a[0]/2;
}   
    
    
     

     
   





Measured memory_bytes: 3560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  int A,B;
  cin >>A>>B;
  cout <<A*B;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long int lli;
const lli mod = 998244353;
const int inf = 1e9;

int main(){
	lli x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	priority_queue<lli> p,q,r;
	lli z;
	vector<lli> pp(a), qq(b);
	for(int i=0; i<a; i++){
		cin >> pp[i];
	}
	for(int i=0; i<b; i++){
		cin >> qq[i];
	}
	for(int i=0; i<c; i++){
		cin >> z;
		r.push(z);
	}
	sort(pp.begin(), pp.end(), greater<lli>());
	sort(qq.begin(), qq.end(), greater<lli>());
	for(int i=0; i<x; i++){
		p.push(-pp[i]);
	}
	for(int i=0; i<y; i++){
		q.push(-qq[i]);
	}

	while(!r.empty()){
		lli num = min(-p.top(), -q.top());
		bool isp = -p.top() < -q.top();
		if(r.top() <= num){
			break;
		}
		if(isp){
			p.pop();
			p.push(-r.top());
		}else{
			q.pop();
			q.push(-r.top());
		}
		r.pop();
	}

	lli ans = 0;
	while(!p.empty()){
		ans += -p.top();
		p.pop();
	}
	while(!q.empty()){
		ans += -q.top();
		q.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4852
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val a = nextInt()
    println(a + a * a + a * a * a)
}

Measured memory_bytes: 34008
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
vector<P>vec[100009];
P ans[100009];

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int p,y;
    cin>>p>>y;
    vec[p].push_back(P(y,i));
  }
  for(int i=1;i<=n;i++){
    sort(vec[i].begin(),vec[i].end());
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<vec[i].size();j++){
      ans[vec[i][j].second]=P(i,j+1);
    }
  }
  for(int i=0;i<m;i++){
    printf("%06d",ans[i].first);
    printf("%06d\n",ans[i].second);
  }
  return(0);
}


Measured memory_bytes: 7808
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

int main()
{
  ll A, B, M;
  cin >> A >> B >> M;
  vector<ll> a(A);
  vector<ll> b(B);
  vector<Pl> m(M);
  vector<ll> c(M);
  vector<ll> ans(M + 1);
  ll INF = 100000000;
  ll answer = INF;
  rep(i, ans.size())
  {
    ans.at(i) = INF;
  }
  rep(i, A)
  {
    cin >> a.at(i);
  }
  rep(i, B)
  {
    cin >> b.at(i);
  }
  rep(i, M)
  {
    cin >> m.at(i).first >> m.at(i).second >> c.at(i);
    m.at(i).first--;
    m.at(i).second--;
    ans.at(i) = a.at(m.at(i).first) + b.at(m.at(i).second) - c.at(i);
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(ans.begin(), ans.end());
  answer = min(ans.at(0), a.at(0) + b.at(0));
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
signed main(){
	int n,ed=0;
  	bool sell=0;
  	cin>>n;
  	n*=100;
  	while(ed < 100){
      if((n+ed)%108 == 0){
        cout<<(n+ed)/108<<endl;
        sell = 1;
        break;
      }
      ed++;
    }
  	if(!(sell))
       cout<<":("<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ld = long double;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vll P(N);
  REP(i, 0, N) {
    cin >> P[i];
  }
  sort(P.begin(), P.end(), less<>());

  ll ans = 0;
  REP(i, 0, K) {
    ans += P[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, a[N], k, m;
ll y[N], p[N], o[N], ans[N];
ll G[N];
ll C = 1;
ll cyc[N];
ll M[N];
vector<ll> V[N];
ll pos[N], end[N];
ll Z[N];
void f() {
	for (int i = 1; i <= n; i ++) 
		p[i] = i; 
	for (int i = 1; i <= m; i ++) 
		swap(p[o[i]], p[o[i] + 1]);
	for (int i = 1; i <= n; i ++) {
		if (M[i]) continue;
		if (i == p[i]) {
			M[i] = 1;
			C ++;
			cyc[i] = C;
			pos[i] = 0;
			V[C].pb(i);
			continue;
		}
		ll x = i;
		ll y = p[i];
		C ++;
		cyc[x] = C;
		pos[x] = V[C].size();
		V[C].pb(x);
		M[x] = 1;
		while (y ^ x) {
			cyc[y] = C;
			pos[y] = V[C].size();
			V[C].pb(y);
			M[y] = 1;
			y = p[y];
		}
	}
	for (int i = 1; i <= n; i ++) {
		ll cc = cyc[i];
		ll ps = pos[i];
		ll res = ps + k;
		res %= ll(V[cc].size());
		ll id = V[cc][res];
		ans[i] = y[id];
	}
}
int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i ++) 
    	cin >> a[i];
	for (int i = 1; i <= n; i ++) 
		y[i] = a[i] - a[i - 1]; 
	cin >> m >> k;
	for (int i = 1; i <= m; i ++) 
		cin >> o[i];
	f();
	cout << ans[1] << '\n';
	Z[1] = ans[1];
	for (int i = 2; i <= n; i ++) {
		Z[i] = ans[i] + Z[i - 1];
		cout << Z[i] << '\n';
	}
    return (0);
}

Measured memory_bytes: 24192
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
	int before_num, N, a[20], b[50], c[50], answer;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N - 1; i++) {
		cin >> c[i];
	}
	answer = b[a[0] - 1];
	before_num = a[0];
	for (int i = 1; i < N; i++) {
		if (before_num + 1 == a[i]) {
			answer += b[a[i] - 1] + c[before_num - 1];
		}
		else {
			answer += b[a[i] - 1];
		}
		before_num = a[i];
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, a[105], b[105];
    cin >> n;
    for (int i = 1; i < n; i++)
        cin >> b[i];

    a[1] = b[1];
    a[2] = b[1];
    for (int i = 2; i < n; i++)
    {
        if (b[i] > a[i])
            a[i + 1] = b[i];
        else
        {
            a[i] = b[i];
            a[i + 1] = b[i];
        }
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++)
        sum += a[i];
    cout << sum;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < N; i++) {
			sb.append(S.charAt(i));
			sb.append(T.charAt(i));
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 35568
#include <bits/stdc++.h>
using namespace std;
long f(long x,long y){
    long a = x,b = y;
    while(y != 0){
        long c = y;
        y = x%y;
        x = c;
    }
    return a*b/x;
}
int main(){
    long a,b,x,y;
    cin>>a>>b>>x>>y;
    long X = b/x - a/x;
    if(a%x == 0)X++;
    long Y = b/y - a/y;
    if(a%y == 0)Y++;
    long Z = b/f(x,y) - a/f(x,y);
    if(a%f(x,y) == 0)Z++;
    cout << b-a - (X + Y - Z) + 1 << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
	string s;
	size_t k;
	map<string, bool> substrings;

	cin >> s >> k;

	for(int i = 1; i <= min(k, s.size()); ++i) {
		for(int j = 0; j < s.size() - (i - 1); ++j) {
			substrings[s.substr(j, i)] = true;
		}
	}

	auto it = substrings.begin();
	for(int i = 0; i < k - 1; ++i) ++it;
	cout << (it->first) << endl;
}


Measured memory_bytes: 1920
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};



main(){
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i+=2){
		int tmp=0;
		for(int j=1;j<=i;j++){
			if(i%j==0){
				//debug(i,j);
				tmp++;
			}
			
		}
		if(tmp==8){
			debug(i);
			ans++;
		}
	}
	dans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int N;
  char s[100];
  int count = 0;
  scanf("%d",&N);
  for(int i = 0;i < N;i++){
    scanf("%s",&s[i]);
  }
  for(int i = 0;i < N;i++){
    if(s[i] == 'R'){
      count++;
    }
    else{
      count--;
    }
  }
  if(count > 0){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t = (A-1) / D + 1;
    int a = (C-1) / B + 1;
    if(t >= a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;    
}

Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CAlchemist {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> v(n);
        priority_queue<double,vector<double>,greater<double>> pq;
        for(auto& i:v) in>>i,pq.push(i);
        double ans=0;
        fr(i,n-1){
            auto a=pq.top();pq.pop();
            auto b=pq.top();pq.pop();
            auto c=(a+b)/2;
            pq.push(c);
        }
        out<<pq.top()<<endl;
    }
};

int main() {
    CAlchemist solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

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

	std::vector<int> v(n);
	for (int& x : v) {
		std::cin >> x;
	}

	for (int i = 0; i < n; i++) {
		if (v[i] % 2 == 0) {
			if (v[i] % 3 == 0 || v[i] % 5 == 0) {
				continue;
			}
			else {
				std::cout << "DENIED" << std::endl;
				exit(0);
			}

		}
	}

	std::cout<< "APPROVED"<<std::endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

const int N = 55555;
bool isNotPrime[N];
int primes[N];
int nPrime;

bool isPrime(int k) {
  if(k < N) return !isNotPrime[k];
  REP(i, nPrime) {
    int p = primes[i];
    if(p == k) return true;
    if(k % p == 0) return false;
  }
  return true;
}


int main(void) {
  int n;
  cin >> n;
  isNotPrime[0] = isNotPrime[1] = true;
  REP(i, N) {
    if(!isNotPrime[i]) {
      primes[nPrime++] = i;
      for(int j = i + i; j < N; j += i) {
        isNotPrime[j] = true;
      }
    }
  }
  vector<int> vs;
  REP(i, nPrime) {
    int p = primes[i];
    if(p % 5 == 1) {
      vs.push_back(p);
    }
  }
  REP(i, n) {
    printf("%d%c", vs[i], i == n-1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // 一年の秒数
  string S;
  cin >> S;
 
  if(S == "SUN")
  {
    cout << 7 << endl;
  }
  if(S == "MON")
  {
    cout << 6 << endl;
  }
  if(S == "TUE")
  {
    cout << 5 << endl;
  }
  if(S == "WED")
  {
    cout << 4 << endl;
  }
  if(S == "THU")
  {
    cout << 3 << endl;
  }
  if(S == "FRI")
  {
    cout << 2 << endl;
  }
  if(S == "SAT")
  {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N;
  cin>>N;
  ll H[N];
  REP(i,N) cin>>H[i];
  bool CAN=false;
  
  if(N==1) CAN=true;
  else{
    for(int i=0; i<N-1; ++i){
      if(H[i]>H[i+1]+1) break;
      else if(H[i]==H[i+1]+1) H[i+1]++;
      if(i==N-2) CAN=true;
    }
  }
  
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 1024
/* nothing is impossible */
#include <bits/stdc++.h> 
 
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;                                                                                           
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}             
const ll N=1000008;
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  ll x[n],y[n],z[n];
  for(ll i=0;i<n;i++)
  {
    cin>>x[i]>>y[i]>>z[i];
  }
  for(ll cx=0;cx<=100;cx++)
  {
    for(ll cy=0;cy<=100;cy++)
    {
      set<ll> s;
      vi ty;
      for(ll i=0;i<n;i++)
      {
        if(z[i]<1)
        {
          ty.pb(i);
          continue;
        }
        ll o=z[i]+(abs(x[i]-cx)+abs(y[i]-cy));
        s.insert(o);
      }
      if((s.size())==1)
      {
        ll p;
        for(auto e:s)
          p=e;
        bool f=true;
        if(ty.size()>0)
        {
          for(auto q:ty)
          {
            ll re=p-(abs(x[q]-cx)+abs(y[q]-cy));
            if(re>0)
            {
              f=false;
              break;
            }
          }
        }
        if(!f)
        {
          continue;
        }
        cout<<cx<<" "<<cy<<" "<<p;
        return 0;
      }
    }
  }
  return 0;   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <sstream>
#include <stdio.h>
#include <cmath>
#include <cstdlib>
#include <algorithm> 
 #include <vector> 
using namespace std;
 
int main() {
  long long int A,B,V,W,T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    if(W < V){
  
        if(abs(A-B)<=(V-W)*T){
            cout << "YES" <<endl;
            return 0;
            
            
        }else{
            cout << "NO" <<endl;
             return 0;
         }
    
    }else{
       
            cout << "NO" <<endl;
             return 0;
       
    }

}

Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h>

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem1154 : Monday-Saturday Prime Factors **/
int main()
{
	int n;
	while (cin>>n, n!=1) {
		set<int> ans;
		REP(i, 2, n+1) {
			if ((i%7==1 || i%7==6) && n%i==0) {
				for (int j=2; j*j<=i; j++) {
					if ((j%7==1||j%7==6) && i%j==0) goto end;
				}
					ans.insert(i);
			end:;
			}
		}
		set<int>::iterator it = ans.begin();
		cout << n << ":";
		for (;it!=ans.end();it++)
			cout <<" " << *it;
		cout << endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);
      // #ifndef ONLINE_JUDGE
      //   freopen("input.txt", "r", stdin);
      //   freopen("output.txt", "w", stdout);
      // #endif
    string s,t; cin>>s>>t;
    int n=s.length(),m=t.length();
    vector<vector<int> > dp(n+1, vector<int> (m+1,0));

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j]=dp[i-1][j-1];
            if(s[i-1]==t[j-1])
                dp[i][j]++;

            dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
        }
    }

    // cout<<dp[n][m]<<"\n";

    int i=n,j=m;
    string ans;
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            ans+=s[i-1];
            i--;j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
    }
    reverse(all(ans));
    cout<<ans<<"\n";
    return 0;
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int p;
    int s=0, t=0, u=0;
    for(int i=0;i<n;i++){
        cin >> p;
        if(p<=a){
            s++;
        }else if(p<=b){
            t++;
        }else{
            u++;
        }
    }
    cout << min(s, min(t, u)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
const long double pi = acos(-1.0L);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}



int main(void){
	int n,i,j;
	long double l,t[3333],x=0.0,y=0.0;
	cin >> n >> l;
	for(i=0; i<n; ++i){
		cin >> t[i];
		for(j=0; j<i; ++j){
			x -= (cos((t[i]+t[j])*pi/l))*(i-j-1);
			y -= (sin((t[i]+t[j])*pi/l))*(i-j-1);
			x += (cos((t[i]+t[j])*pi/l))*(n-2-(i-j-1));
			y += (sin((t[i]+t[j])*pi/l))*(n-2-(i-j-1));
		}
	}
	x *= 6; x /= n; x /= (n-1); x /= (n-2);
	y *= 6; y /= n; y /= (n-1); y /= (n-2);
	cout << fixed << setprecision(50) << x << " " << y << endl;
	return 0;
}


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

#define ll long long
#define sz 100005
#define mod 10000

using namespace std;

ll visited[sz],level[sz];
vector<pair<ll, ll> >graph[sz];

int main()
{
    ll n,q,k,a,b,c;

    scanf("%lld",&n);

    for(ll i=1; i<n; i++)
    {
        scanf("%lld %lld %lld",&a,&b,&c);

        graph[a].push_back(make_pair(b,c));
        graph[b].push_back(make_pair(a,c));
    }

    scanf("%lld %lld",&q,&k);

    queue<ll>qq;

    memset(visited,0,sizeof(visited));

    visited[k]=1;
    level[k]=0;

    qq.push(k);

    while(!qq.empty())
    {
        ll u=qq.front();
        qq.pop();

        for(ll i=0; i<graph[u].size(); i++)
        {
            ll v=graph[u][i].first;
            ll w=graph[u][i].second;

            if(!visited[v])
            {
                visited[v]=1;
                level[v]=level[u]+w;
                qq.push(v);
            }
        }
    }

    while(q--)
    {
        scanf("%lld %lld",&a,&b);

        printf("%lld\n",level[a]+level[b]);
    }

    return (0);
}


Measured memory_bytes: 10752
import java.io.PrintWriter;
import java.util.*;
//https://qiita.com/p_shiki37/items/3902f4e3adc3aeb382f1

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int sl = S.length();
        long K = Long.parseLong(sc.next());
        sc.close();

        long count = 0;
        boolean all = true;
        char c = S.charAt(0);
        for (int i=0; i<sl-1; i++) {
            if (S.charAt(i) != c) {
                all = false;
                break;
            }    
        }
        if (all) {
            count = sl * K / 2;
            System.out.println(count);
            return;
        }
        int cf = 0;
        int ce = 0;
        if (S.charAt(sl - 1) == c) {
            for (int i=0; i<sl; i++) {
                if (S.charAt(i) == c) {
                    cf++;
                } else {
                    break;
                }
            }
            for (int i=sl-1; i>0; i--) {
                if (S.charAt(i) == c) {
                    ce++;
                } else {
                    break;
                }
            }
            count += cf / 2 + ce / 2 + (cf + ce) / 2 * (K - 1);

            String S1 = S.substring(cf, sl - ce);
            boolean sf = false;
            long count1 = 0;
            for (int i=0; i<S1.length()-1; i++) {
                if (S1.charAt(i) != S1.charAt(i+1)) {
                    sf = false;
                } else {
                    if (sf) {
                        sf = false;
                    } else {
                        sf = true;
                        count1++;
                    }
                }
            }
            count += K * count1;
            System.out.println(count);
            return;
        }
        boolean sf = false;
        for (int i=0; i<S.length()-1; i++) {
            if (S.charAt(i) != S.charAt(i+1)) {
                sf = false;
            } else {
                if (sf) {
                    sf = false;
                } else {
                    sf = true;
                    count++;
                }
            }
        }
        count *= K;
        System.out.println(count);
    }
}

Measured memory_bytes: 22356
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int n;
ll a, b;
ll h[maxn];

ll divv(ll x, ll y) {
    if (x % y == 0) return x / y;
    else return x / y + 1;
}

bool check(ll x) {
    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (divv(h[i], b) <= x) continue;
        ll delta = h[i] - x * b;
        ll cnt2 = divv(delta, a - b);
        cnt += cnt2;
    }
    return cnt <= x;
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    scanf("%d%lld%lld", &n, &a, &b);
    for (int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    ll ans = LL_INF;
    ll left = 0, right = LL_INF;
    while (left <= right) {
        ll mid = (left + right) / 2;
        if (check(mid)) {
            ans = min(ans, mid);
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    printf("%lld\n", ans);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();

    let mut f = false;
    let mut now = 0;
    let mut res = 0;
    for c in s.trim().chars() {
        if !f && c == 'A' {
            f = true;
        }

        if f {
            now += 1;
        }

        if f && c == 'Z' {
            res = now;
        }
    }

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


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  vector<bool> selected(m + 1, true);
  auto getLargestSportAndSize = [&]() {
    vector<int> sportSize(m + 1);
    int largestSport = -1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int sport = a[i][j];
        if (selected[sport]) {
          ++sportSize[sport];
          if (largestSport == -1 || sportSize[sport] > sportSize[largestSport]) {
            largestSport = sport;
          }
          break;
        }
      }
    }
    return make_pair(largestSport, sportSize[largestSport]);
  };
  auto largestSportAndSize = getLargestSportAndSize();
  int ans = largestSportAndSize.second;
  for (int i = 0; i < m - 1; ++i) {
    selected[largestSportAndSize.first] = false;
    largestSportAndSize = getLargestSportAndSize();
    ans = min(ans, largestSportAndSize.second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,count=0;
	cin>>n>>k;
	map<int,int> mp;
	for(int i=1;i<=k;i++ )
	{
		int d;
		cin>>d;
		for(int j=1;j<=d;j++)
		{
			int x;
			cin>>x;
			mp[x]++;
		}
	}
	for(int i=1;i<=n;i++)
	if(mp[i]==0)
	count++;
	cout<<count;
}

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

int main() {
    int n, d[100010];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> d[i];
    sort(&d[0], &d[n]);
    cout << max(0, d[n/2] - d[n/2-1]);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a[N],y,m,d;
char ch,ch1;
int main()
{
	cin >> y>>ch>>m>>ch>>d;
	cout << y+1<<ch;
	if(m<10)
	cout<<"0"<<m;
	else
	cout<<m;
	if(d<10)
	cout <<ch<<"0"<<d;
	else
	cout <<ch<<d;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
	int m,f,r;
	while(true){
		char result;
		std::cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m+f>=80){
			result='A';
		}else if(m+f>=65){
			result='B';
		}else if(m+f>=50){
			result='C';
		}else if(m+f>=30){
			result='D';
			if(r>=50){
				result='C';
			}
		}else{
			result='F';
		}
		if(m==-1||f==-1){
			result='F';
		}
		std::cout<<result<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	int A,B;

	cin >> A >> B;

	if (A>=13)
	{
		cout << B << endl;
	}
	else if (A>=6)
	{
		cout << B/2 << endl;
	}
	else cout << 0 << endl;

	return 0;
}

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

public class Main {

	private static final List<Integer> LIST = Arrays.asList(2, 5);

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int k = scanner.nextInt();
			for (Integer integer : LIST) {
				if (0 == (k % integer)) {
					System.out.println(-1);
					return;
				}
			}
			System.out.println(getResult(k));
		}
	}

	private static int getResult(int k) {
		if (0 == (k % 7)) {
			k /= 7;
		}
		long now = 1L;
		for (int i = 1;; i++) {
			if (0 == (now % k)) {
				return i;
			}
			now = (now * 10 + 1) % k;
		}
	}
}


Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N,rem;
  cin >> N;
  string S[N];
  int P[N],ans[N];
  for(int i=0;i<N;i++){
    cin >> S[i] >> P[i];
  }
  if(N==1){
    cout << "1" << endl;
  }
  else{
    for(int i=0;i<N;i++){
      rem=1;
      for(int j=0;j<N;j++){
        if(string(S[j]).compare(S[rem])<=0){
          if(string(S[j]).compare(S[rem])==0 && P[j]>P[rem] || string(S[j]).compare(S[rem])<0){
            rem=j;
          }
        }
      }
      ans[i]=rem+1;
      S[rem]="zzzzzzzzzzz",P[rem]=-1;
    }
    for(int i=0;i<N;i++){
      cout << ans[i] << endl;
    }
  }
}
          

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;



int main(void){
	int i;
	vector<string> vec(3);
	for(i=0;i<3;i++){
		cin >> vec[i];
	}
	for(i=0;i<3;i++){
		cout << vec[i][i];
	}
	cout << endl;
}

Measured memory_bytes: 256
n = int(input())
dp = [0 for _ in range(n+1)]
for i in range(1, n+1):  # iは金額
    dp[i] = i  # 初期化
    power = 1  # 累乗を初期化
    while power <= i:  # 累乗より小さい値の時はループに入る
        dp[i] = min(dp[i], dp[i - power] + 1)  # 漸化式
        power *= 6  # 6の累乗を更新
    power = 1  # 累乗を初期化
    while power <= i:  # 累乗より小さい時はループい入る
        dp[i] = min(dp[i], dp[i - power] + 1)  # 漸化式
        power *= 9  # 9の累乗を更新
print(dp[n])

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
 int n ;
 cin >> n ;
 int ans = 0 ;
	ans = ( n * (n+1) / 2 );
	cout << ans << endl;
}


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

int main() {
    int n, l;
    cin >> n >> l;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += l + i;
    }
    int eat = 100;
    for (int i = 0; i < n; i++) {
        if (abs(eat) > abs(l + i)) eat = l + i;
    }

    cout << sum - eat << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    const long long mx=1e18;
    long long a[n+5];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    if(a[1]==0){
        cout<<0<<endl;
        return 0;
    }
    long long ans=a[1],pre=a[1];
    for(int i=2;i<=n;i++){
        ans*=a[i];
        cerr<<ans<<' '<<pre<<endl;
        if(ans/a[i]!=pre or ans>mx or ans<0){
            cout<<"-1"<<endl;
            return 0;
        }
        pre=ans;
    }
    cout<<ans;
}


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin >> x;
        ans += ((i%2 == 1) && (x%2 == 1));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3604
num = int(input())
a_i = list(map(int, input().split()))
list.sort(a_i, reverse=True)
if num <= 3:
    print(sum(a_i[:num - 1]))
else:
    ans = sum(a_i[:2])
    for x in range(3, num):
        if x == 3: ans += a_i[1]
        else: ans += a_i[x // 2]
    print(ans)


Measured memory_bytes: 31612
x, n = map(int, input().split())
p = set(map(int, input().split()))
ans1 = 0
for i in range(x, -10, -1):
    if i not in p:
        ans1 = i
        break
ans2 = 0
for i in range(x, 110):
    if i not in p:
        ans2 = i
        break
if x - ans1 <= ans2 - x:
    print(ans1)
else:
    print(ans2)


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


#define MAX_N 110
int n;
int x[MAX_N], y[MAX_N], h[MAX_N];

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    while(cin >> n){
        for(int i = 1; i <= n; ++i){
            cin >> x[i] >> y[i] >> h[i];
            if(h[i] > 0) {
                swap(h[i], h[1]);
                swap(x[i], x[1]);
                swap(y[i], y[1]);
            }
        }
        for(int cx = 0; cx <= 100; ++cx){
            for(int cy = 0; cy <= 100; ++cy){
                int ch = h[1] + abs(x[1] - cx) + abs(y[1] - cy);
                bool is = true;
                for(int i = 2; i <= n; ++i){
                    if(max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) {
                        is = false;
                        break;
                    }
                }
                if(is){
                    cout << cx << " " << cy << " " << ch << endl;
                    return 0;
                }
            }
        }
    }
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

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

dp = {}

dp[1] = 0
dp[2] = abs(H[1]-H[0])

for i in range(3, N+1):
    li = []
    for j in range(1,min(K+1,i)):
        li.append(dp[i-j]+abs(H[i-1]-H[i-(j+1)]))
    dp[i] = min(li)

print(dp[N])

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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
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; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	int n,m;
	cin >> n >>m;
	int ans = (n *(n-1)) / 2 ;
	ans += (m * (m - 1))/2;
	cout << ans << endl;
}


Measured memory_bytes: 256
/*

*/
#include <bits/stdc++.h>

using namespace std;

#define ll           long long int
#define mp           make_pair
#define pb           push_back
#define fi           first
#define si           second
#define fastIO       ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n)       for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n)      for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n)       for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n)      for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m)    for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m)   for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m)   for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m)  for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
const int nax = 1e7;
const int mod = 1e9+7;



int main(){
fastIO
	int l, r, d, ans=0;
	cin>>l>>r>>d;
	for(int i=l; i<=r; i++){
		if(i % d == 0){ans++;}
	}
	cout<<ans;
}

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

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	vector<int> t(n);
	string x;
	for(int i=0; i<n; i++){
		cin >> s[i] >> t[i];
	}
	cin >> x;

	bool sleep = false;
	int ans = 0;
	for(int i=0; i<n; i++){
		if(sleep) ans += t[i];
		if(s[i]==x) sleep = true;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;


int main()
{
	char ch;
	int idx = 0, chars[26];

	for (int i = 0;i < 26;i++) {
		chars[i] = 0;
	}

	while (cin >> ch)
	{
		

		if (!isalpha(ch)) continue;
		else if (isupper(ch)) {
			idx = ch - 'A';
			chars[idx++] += 1;
		}
		else {
			idx = ch - 'a';
			chars[idx++] += 1;
		}
	}

	for (int i = 0;i < 26;i++) {
		printf("%c : %d\n", i + 97, chars[i]);
	}

    return 0;
}



Measured memory_bytes: 3144
#include "bits/stdc++.h"
using namespace std;

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

    deque<int> dq;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (i & 1)
            dq.push_front(a);
        else
            dq.push_back(a);
    }

    if (n & 1) reverse(dq.begin(), dq.end());

    for (int i = 0; i < n; i++) {
        cout << dq[i] << " \n"[i == n - 1];
    }

    return 0;
}

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


int main(){
	int s;
	cin >> s;
	
	
	set<int> found;
	found.insert(s);
	while(true){
		if(s%2==0) s /= 2;
		else s = 3*s + 1;
		if(found.find(s) != found.end()) break;
		else found.insert(s);
	}
	
	cout << found.size() + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int X,A,B;
	cin >> X >> A >> B;
	if(A>=B){
		cout << "delicious" << endl;
	}else if(B-A<=X){
		cout << "safe" <<endl;
	}else if(X<B-A){
		cout << "dangerous" << endl;
	}
	return 0;
	}

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

using namespace std;

const int MAXX = 100005;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> X(MAXX, 0), R(M, 0);
  for (int i = 0; i < N; i++) {
    int e;
    cin >> e;
    R[e % M]++;
    X[e]++;
  }
  int res = 0;
  res += R[0] / 2;
  R[0] %= 2;
  if (M % 2 == 0) {
    res += R[M / 2] / 2;
    R[M / 2] %= 2;
  }
  for (int i = 1; i < M / 2 + (M % 2 == 0 ? 0 : 1); i++) {
    int c = min(R[i], R[M - i]);
    res += c;
    R[i] -= c, R[M - i] -= c;
  }
  for (int i = 0; i < MAXX; i++) {
    int c = min(X[i] / 2, R[i % M] / 2);
    res += c;
    R[i % M] -= c * 2;
  }
  cout << res << '\n';
  return 0;
}


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


int main() {
  long int a=1;
  long int b=1;
  long int c=1;
  int N;
  cin>> N;
  if(N>1){
  for(int i=0;i<N;i++){
a*=10;
a%=1000000007;
}
  for(int i=0;i<N;i++){
b*=9;
b%=1000000007;
}
    for(int i=0;i<N;i++){
c*=8;
c%=1000000007;
}
int d=a-b-b+c;
if(d<0){d+=1000000007;}
    if(d<0){d+=1000000007;}

cout<<d<<endl;}
  else{cout<<0<<endl;}
}

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


int main() {
  int n;
  cin >> n;
  int a;
  if(n<600) a = 8;
  else if(n<800) a = 7;
  else if(n<1000) a = 6;
  else if(n<1200) a = 5;
  else if(n<1400) a = 4;
  else if(n<1600) a = 3;
  else if(n<1800) a = 2;
  else a = 1;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3612