akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int INF = 1e7;

const int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

void dijkstra(Graph &g, int s, Array &d)
{
	d.assign(g.size(), INF);
	d[s] = 0;
	typedef pair<Weight, int> P;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		Weight dist = que.top().first;
		int v = que.top().second;
		que.pop();
		if (d[v] < dist) continue;
		REP(i, g[v].size())
		{
			Edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int h, w;
	while (cin >> w >> h, h)
	{
		Graph g(w * h);
		REP(i, h * 2 - 1)
		{
			if (i % 2 == 0)
			{
				int x = i / 2;
				REP(j, w - 1)
				{
					int a; cin >> a;
					if (a == 0)
					{
						add_edge(g, place(x, j, w), place(x, j + 1, w), 1);
						add_edge(g, place(x, j + 1, w), place(x, j, w), 1);
					}
				}
			}
			else
			{
				int x = i / 2;
				REP(j, w)
				{
					int a; cin >> a;
					if (a == 0)
					{
						add_edge(g, place(x, j, w), place(x + 1, j, w), 1);
						add_edge(g, place(x + 1, j, w), place(x, j, w), 1);
					}
				}
			}
		}
		Array d;
		dijkstra(g, 0, d);
		cout << (d[w * h - 1] >= INF ? 0 : d[w * h - 1] + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
#include<stdlib.h>
long long int a[100005], b[100005];
int asc(const void* x, const void* y)
{
	if (b[*(int*)x] < b[*(int*)y])return 1;
	if (b[*(int*)x] > b[*(int*)y])return -1;
	return 0;
}
int q[100005];
void qq()
{
	int i;
	for (i = 0; i < 100005; i++)
		q[i] = i;
	return;
}
int r(int n)
{
	if (n < 0)
		return -1;
	if (q[n] == n)
		return n;
	if (q[n] < 0)
		return -1;
	return q[n] = r(q[n]);
}
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int i, j;
	for (i = 0; i < n; i++)
		scanf("%lld %lld", &a[i], &b[i]);
	int p[100005];
	for (i = 0; i < m; i++)
		p[i] = 0;
	long long int ans = 0;
	int c[100005];
	for (i = 0; i < n; i++)
		c[i] = i;
	qsort(c, n, sizeof(int), asc);
	qq();

	for (i = 0; i < n; i++)
	{
		j = r(m - a[c[i]]);
		if (j >= 0)
		{
			p[j] = 1;
			q[j]--;
			ans += b[c[i]];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2556
n = int(input())
s = input()
S = []

if n == 2:
    if s[0] == s[1]:
        print(1)
        exit()
    else:
        print(0)
        exit()

for i in s:
    S.append(i)

ans = []

for j in range(1, n-1):
    count = 0
    l, r = set(S[:j]), set(S[j:])
    for k in l:
        if k in r:
            count += 1
    ans.append(count)

print(max(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  ll n; cin >> n;
  map<string, ll> m;
  ll cnt=1;
  auto dfs = [&](auto dfs, set<ll> r, string s){
    if(r.size()<=0) {
      if(debug){
        cout << s << ":" << cnt << endl;
      }
      m[s]=cnt;
      cnt++;
      return;
    }
    for(auto p:r){
      set<ll> q = r;
      q.erase(p);
      string u = s;
      u.append(to_string(p));
      dfs(dfs, q, u);
    }
  };
  set<ll> r;
  rep1(i,n){
    r.insert(i);
  }
  dfs(dfs,r,"");
  string p, q;
  rep(i,n){
    string s; cin >> s;
    p.append(s);
  }
  rep(i,n){
    string s; cin >> s;
    q.append(s);
  }
  cout << abs(m[p]-m[q]);
  return 0;
}


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

using namespace std;

int main(){
  int antenna[5];
  int k;
  
  for(int i = 0; i < 5; i++){
  	cin >> antenna[i];
  }
  
  cin >> k;
  
  if(antenna[4] - antenna[0] > k){
  	cout << ":(" << endl;
  }else{
  	cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
using namespace std;
long long n,q,a,b,c,x,y,k,dist[N];
vector<pair<long long,long long> > pt[N];
vector<long long> ans;
bool book[N]={};
void dfs(long long x,long long pre)
{
	dist[x]=pre;
	long long i;
	for(i=0;i<pt[x].size();i++)
	{
		if(!book[pt[x][i].first])
		{
			book[pt[x][i].first]=true;
			dfs(pt[x][i].first,pre+pt[x][i].second);
		}
	}
}
int main(){
	long long i;
	cin>>n;
	for(i=0;i<n-1;i++)
	{
		cin>>a>>b>>c;
		pt[a].push_back(make_pair(b,c));
		pt[b].push_back(make_pair(a,c));
	}
	cin>>q>>k;
	book[k]=true;
	dfs(k,0);
	for(i=0;i<q;i++)
	{
		cin>>x>>y;
		ans.push_back(dist[x]+dist[y]);
	}
	for(i=0;i<ans.size();i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 15348
n, k = map(int, input().split())                            
array = list(map(int, input().split()))
 
def jadgesuruo():
    for i in range(k):
        if str(n).find(str(array[i])) >= 0:
            return False
            break
    return True
 
while True:
    if jadgesuruo():
        print(n)
        break
    else:
        n = n + 1


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second

// 1次元vectorの出力
template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}

// 2次元vectorの出力
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint perm(int n, int r){
	if(r == 0) return mint(1);
	mint res(n);
	for(int i=n-1; i>n-r; i--){
		res *= i;
	}
	return res;
}

mint ans;
int n,k;

void dfs(int node, vector<vector<int>> &tree, int par){
	ans *= perm(k-2, tree[node].size()-1);
	for(int child: tree[node]){
		if(child != par){
			dfs(child, tree, node);
		}
	}
}

int main(void){
	cin >> n >> k;
	vector<vector<int>> tree(n,vector<int>());
	Rep(n-1){
		int a,b; cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	ans += k;
	ans *= perm(k-1, tree[0].size());
	for(int node: tree[0]){
		dfs(node, tree, 0);
	}
	cout << ans << endl;
}

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

int main()
{
	int N = 0, ans = 0;
	std::cin >> N;

	std::vector<int> A(N);
	std::vector<int> B(N);
	std::vector<int> C(N);

	for (int i = 0; i < N; i++){
		int a = 0;
		std::cin >> a;
		A[i]= a;
	}
	for (int i = 0; i < N; i++){
		int a = 0;
		std::cin >> a;
		B[i] = a;
	}
	for (int i = 0; i < N-1; i++){
		int a = 0;
		std::cin >> a;
		C[i] = a;
	}
	
	for (int i = 0; i < N; i++){

			ans += B[A[i] - 1];

		if (i > 0){
			if (A[i] == A[i - 1] + 1){

				ans += C[A[i-1] - 1];

			};
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,l=-1,r,m;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        l=max(l,a[i]);
    }
    r=1000000000;
    m=(l+r)/2;
    while(l!=r){
        int count=0;
        int tmp=0;
        for(int i=0;i<n;i++){
            tmp+=a[i];
            if(tmp>m){
                i--;
                tmp=0;
                count++;
            }
        }
        count++;
        if(count>k){
            l=m+1;
            m=(l+r)/2;
        }else{
            r=m;
            m=(l+r)/2;
        }
    }
    cout<<m<<endl;
}



Measured memory_bytes: 3128
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

int n, ans;

int dfs(int A, int K) {
	if(A % K == 0) return A/K;
	if(A < K) return 0;
	int d, m, t;
	d = A/K; m = d*K;
	t = (A-m)%(d+1) + m;
	if(t == m) return d;
	return dfs(t-d-1, K);
	
}

int main() {
	int i, A, K;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%d%d", &A, &K);
		ans ^= dfs(A, K);
//		printf("%d\n", ans);
	}
	if(ans) puts("Takahashi");
	else puts("Aoki");
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_HW 1000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int H, W, A, B;
bool res[MAX_HW][MAX_HW];

bool solve() {
    if(A > W / 2) return false;
    if(B > H / 2) return false;
    for(int i = 0; i < B; ++i)
        for(int j = A; j < W; ++j)
            res[i][j] = true;
    for(int i = B; i < H; ++i)
        for(int j = 0; j < A; ++j)
            res[i][j] = true;
    return true;
}


int main(int argc, char **argv) {
    cin >> H >> W >> A >> B;

    if(solve()) {
        for(int i = 0; i < H; ++i) {
            for(int j = 0; j < W; ++j)
                cout << res[i][j];
            cout << endl;
        }

    } else
        cout << "No" << endl;

}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#define maxn 200001
#define p 998244353
#define ll long long
#define pint pair<int,int>
using namespace std;
pint dots[maxn],max_stack[maxn];
int n,cnt=0;
ll ans[maxn];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>dots[i].first>>dots[i].second;
    sort(dots,dots+n);
    max_stack[cnt++]={n-1,n-1};
    ans[n-1]=2;
    ans[n]=1;
    for(int i=n-2;i>=0;i--){
        int to=upper_bound(dots,dots+n,pint(dots[i].first+dots[i].second,-20000000))-dots-1;
        int max_to=(to==i?i:
        max(to,(upper_bound(max_stack,max_stack+cnt,pint(to,2000000),
        [](const pint& p1,const pint& p2){return p1.first>p2.first;})-1)->second));
        int tow=i;
        while(cnt>0){
            if(max_stack[cnt-1].second>max_to)break;
            tow=max_stack[cnt-1].first;
            cnt--;
        }
        max_stack[cnt++]={tow,max_to};
        ans[i]=(ans[i+1]+ans[max_to+1])%p;
    }
    cout<<ans[0];
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int cnt=0;
    int ans=0;
    for(auto &v:s)
    {
        if(v=='R')
            cnt++;
        else
        {
            ans=max(ans,cnt);
            cnt=0;
        }
    }
    ans=max(ans,cnt);
    cout<<ans<<'\n';



}


Measured memory_bytes: 3668
float x[21],y[21],S;main(n){for(;~scanf("%f,%f",x+n,y+n);y[n]=*y)x[++n]=*x;for(;--n;)S+=(x[n]-x[n+1])*(y[n]+y[n+1]);exit(!printf("%f\n",S/2));}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String N = sc.next();
		char n = N.charAt(N.length()-1);

		if(n == '3')
			System.out.println("bon");
		else if(n == '0' || n == '1' || n == '6' || n == '8')
			System.out.println("pon");
		else
			System.out.println("hon");


	}
}


Measured memory_bytes: 35684
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int rt=INF;

class UnionFind{
    private:
        int n;
        vector<int> uni;
    public:
        UnionFind(int _n){
            n = _n;
            uni.clear();
            uni.resize(n,-1);	// 値が負であれば根であり、かつ-1*値は頂点の数。値が正であればそれが親を表す。
        }
        int root(int x){
            if(uni[x]<0) return x;
            return uni[x] = root(uni[x]);
        }
        bool same(int x, int y){
            return root(x)==root(y);
        }
        void unite(int x, int y){
            x = root(x);
            y = root(y);
            if(x==y) return;
            if(x>y) swap(x,y);
            uni[x] += uni[y];
            uni[y] = x;
            if(rt>x) rt=x;
        }
        int getSize(int x){
            return -uni[root(x)];
        }
        void print(){
            for(auto x:uni) cout<<x<<" ";
            cout<<endl;
        }
};

int N,M;
UnionFind un(200009);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    rep1(a,N){
        int K,l; cin>>K;
        rep(i,K){
            cin>>l;
            un.unite(a,N+l);
        }
    }
    
    rep1(a,N){
        if(!un.same(1,a)){
            cout1("NO");
            return 0;
        }
    }
    cout1("YES");
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long MOD = (long) (Math.pow(10, 9) + 7);
        int n = sc.nextInt();
        int array[] = new int[100002];
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            array[x]++;
            array[x + 1]++;
            array[x + 2]++;
            max = Math.max(max, Math.max(array[x + 1], array[x + 2]));
            max = Math.max(max, array[x]);
        }
        System.out.println(max);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

    public static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }
}


Measured memory_bytes: 60860
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD =  1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;

int P[55];
int T[55];

int solve( int n, int x ){
  if( n == 0 ){
    if( x == 1 ) return 1;
    else return 0;
  }else if( x == 1 ) return 0;
  if( T[n] == x ) return P[n];
  else if(T[n]/2+1 <= x ) return P[n-1]+1 + solve(n-1, x-T[n]/2-1);
  else return solve(n-1, x-1);
}

signed main(){
  int N, X;
  cin >> N >> X;
  T[0] = 1;
  P[0] = 1;
  for( int i = 1; i <= N; i++ ){
    T[i] = 2*T[i-1]+3;
    P[i] = 2*P[i-1]+1;
  }

  cout << solve(N, X) << endl;

}


Measured memory_bytes: 3588
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    double h, a;
    cin >> h >> a;
    double num = h / a;
    cout << ceil(num) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))

cnt = 0
tmp = [-1,-1]
for i in range(n):
  if p[i] == i+1:
    if i+1 == tmp[0]+1 and p[i]==tmp[1]+1:
      cnt+=0
      tmp = [-1, -1]      
    else:
      cnt+=1
      tmp = [i+1,p[i]]
#    print(p[i],tmp,cnt)
print(cnt)

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;++i)
        cin >> h[i];
    vector<int> dp(n);
    dp[0] = 0;
    for(int i=1;i<n;++i)
    {
        int z = M;
        for(int j=max(0LL, i-k);j<i;j++)
            z = min(z, dp[j] + abs(h[i] - h[j]));
        dp[i] = z;
    }
    cout << dp[n-1] << "\n";
    return 0;
}




Measured memory_bytes: 1792
#include"bits/stdc++.h"
    using namespace std;
    int flag[10000100];
    int main(){
    	int n;
    	cin>>n;
    	for(int i=1;i<333336;i++){
    		flag[3*i]=1;
    		flag[5*i]=1;
    	}
    	long long ans=0;
    	for(int i=0;i<=n;i++){
    		if(!flag[i])ans+=i;
    	}
    	cout<<ans<<endl;
    } 

Measured memory_bytes: 10160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vector<pair<ll,ll>>a(n),c(n);
  vector<ll>small[n];
  for(int i=0; i<n; i++) cin >> a[i].second >> a[i].first;
  for(int i=0; i<n; i++) cin >> c[i].first >> c[i].second;
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());
  vector<bool>pea(n,false);
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(a[j].first<c[i].second && a[j].second<c[i].first){
       small[i].push_back(j);
      }
    }
  }
  
  ll count=0;
  for(int i=0; i<n; i++){
    ll Size = small[i].size();
    for(int j=Size-1; j>=0; j--){
      if(pea[small[i][j]]) continue;
      pea[small[i][j]]=true;
      count++;
      break;
    }
  }
  
  cout << count << endl;
  
}
  
  
  


Measured memory_bytes: 256
/*Lucky_Glass*/
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    for(int a=1;a<=9;a++)
        if(n%a==0 && n/a<=9){
            printf("Yes\n");
            return 0;
        }
    printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// Tenka1 Programmer Beginner Contest 2019-C, 946, 
	int n;
	string s;
	cin >> n >> s;
	vector<int> wsum(n + 1, 0), bsum(n + 1, 0);
	bsum[0] = 0;
	wsum.back() = 0;
	int ans = iINF;
	for (int i = 1; i <= n; ++i) {
		if (s[i - 1] == '#') bsum[i] = bsum[i - 1] + 1;
		else bsum[i] = bsum[i - 1];
		
		if (s[n - i] == '.') wsum[n - i] = wsum[n + 1 - i] + 1;
		else wsum[n - i] = wsum[n + 1 - i];
}
	rep(i, n + 1) {
		ans = min(ans, wsum[i] + bsum[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5236
H, W, K = map(int, input().split())
c = []
for i in range(H):
    c.append(input())
H_flag = [0 for i in range(H)]
W_flag = [0 for j in range(W)]
ans = 0
for i in range(2 ** H):
    for k  in range(H):
        H_flag[k] = i % 2
        i = i // 2
    for j in range(2 ** W):
        for l in range(W):
            W_flag[l] = j % 2
            j = j // 2
        tmp_black = 0
        for x in range(H):
            for y in range(W):
                if H_flag[x] == 0 and W_flag[y] == 0:
                    if c[x][y] == '#':
                        tmp_black += 1
        if tmp_black == K:
            ans += 1
print(ans)

Measured memory_bytes: 9224
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define double long double
#define PT(x) cout << (#x) << " is " << (x) << endl;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int M = 1000000007;
void PV(vi v){ for(int i=0 ; i<v.size() ; i++) cout<< v[i] << " "; cout<< endl;}
void PA(int v[],int n){ for(int i=0 ; i<n ; i++)cout<< v[i] << " " ; cout<< endl;}

signed  main(){
    SPD_emergency
  // int t; cin>>t; while(t--)
    {
     int n;
     cin>>n;
     int x = n%500;
     int y = n/500;
     x=x/5;
     int ans = y*1000 + x*5;
     cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
int main() {
	int N, M, X, ans = INF;
	scanf("%d %d %d", &N, &M, &X);
	int C[N], A[N][M];
	for (int i = 0; i < N; ++i) {
		scanf("%d", &C[i]);
		for (int j = 0; j < M; ++j) scanf("%d", &A[i][j]);
	}
	for (int i = 0; i < (1 << N); ++i) {
		int cost = 0, u[M];
		fill_n(u, M, 0);
		for (int j = 0; j < N; ++j) {
			if ((1 << j) & i) {
				cost += C[j];
				for (int k = 0; k < M; ++k) u[k] += A[j][k];
			}
		}
		if (*min_element(u, u + M) >= X) ans = min(ans, cost);
	}
	if (ans == INF) printf("-1");
	else printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 1010

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
int n, m;
char a[N][N];
ll dp[N][N];
ll dpf(int i, int j)
{
	if(i > n || j > m)
		return 0;
	if(i == n && j == m)
		return 1;
	if(dp[i][j] >= 0)
		return dp[i][j];
	dp[i][j] = 0;
	if(a[i + 1][j] == '.')
		dp[i][j] = (dp[i][j] + dpf(i + 1, j)) % MOD;
	if(a[i][j + 1] == '.')
		dp[i][j] = (dp[i][j] + dpf(i, j + 1)) % MOD;
	return dp[i][j];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	// memset(dp, -1, sizeof(dp));	
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i] + 1;
	}
	dp[n + 1][m] = 1;
	for(int i = n; i > 0; --i)
	{
		for(int j = m; j > 0; --j)
		{
			if(a[i][j] == '.')
				dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
		}
	}
	ll ans = dp[1][1];
	cout << ans << "\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long double pi=3.14159265358979323846;
#define x  first
#define y  second
#define deb(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

bool isPar(string s)
{
    ll n=s.size();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        {
            return 0;
        }
    }
    return 1;
}

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

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ///freopen("ss.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
       double n,d,x,y,c=0;
       cin>>n>>d;
       while(n--)
       {
           cin>>x>>y;
           c+=(double)sqrt(x*x + y*y)<=d;
       }
        cout<<c;
    }
    return 0;
}


Measured memory_bytes: 3860
n = gets.to_i
p = []
max = -1e10
c_max = -1e10
n.times do
  p.push(gets.to_i)
end

for i in 0..n-2
  if p[i] >= c_max
    c_max = p[i+1..n-1].max
  end
  max = c_max - p[i] if max < c_max - p[i]
end

puts max



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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

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

    ll n,x,y[100001],a,b;
    cin >> n >> x;
    rep(i,n) cin >> y[i];
    a = abs(x-y[0]);
    REP(i,1,n){
        b = abs(x-y[i]);
        a = gcd(a,b);
    }
    cout << a << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
using namespace std;

int main () {
	int x,y,groupx,groupy ;
	cin >> x >> y;
	if (x==2){
		groupx=1;
	}else if (x==4 || x==6 || x==9 || x==11){
		groupx=2;
	}else {
		groupx=3;
	}
	if (y==2){
		groupy=1;
	}else if (y==4 || y==6 || y==9 || y==11){
		groupy=2;
	}else {
		groupy=3;
	}
	if (groupx == groupy){
		cout << "Yes"<<endl;
	}else {
		cout << "No" <<endl;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
 
using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)
 
// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft
 
// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}
 
// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)
 
// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323
 
int main() {
    string str;
    bool flag = false;
    cin >> str;
    F(i, 0, 3){
       char c = str[i];
       if(c == '7')flag = true;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
 

Measured memory_bytes: 3624
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#include<bits/stdc++.h>
#define fr first
#define sc second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define forn(i,n) for(int i =1;i<= (n);++i)
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
const int inf = 1e9+7;
const int nmax = 500005;
const ll linf = LLONG_MAX;
const ll mod = 1000000007;

int n, mn = inf , a , r;
int main(){
    fast;
    cin >> n;
    forn(i,n){
        cin >> a;
        if(a < mn){
            mn = a;
            r++;
        }
    }
    cout << r << '\n';
}


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

def main():
  U = 2*10**6+2
  MOD = 10**9+7

  fact = [1]*(U+1)
  fact_inv = [1]*(U+1)

  for i in range(1,U+1):
      fact[i] = (fact[i-1]*i)%MOD
  fact_inv[U] = pow(fact[U], MOD-2, MOD)

  for i in range(U,0,-1):
      fact_inv[i-1] = (fact_inv[i]*i)%MOD

  def comb(n, k):
      if k < 0 or k > n:
          return 0
      z = fact[n]
      z *= fact_inv[k]
      z %= MOD
      z *= fact_inv[n-k]
      z %= MOD
      return z

  ans = 0
  r1, c1, r2, c2 = map(int, input().split())
  for i in range(c1, c2+1):
    ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  print(ans%MOD)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 161268
#![allow(non_snake_case,unused_imports,dead_code)]
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    input!{
        N:usize,
        AB:[(Usize1,Usize1);N-1],
    }

    let mut E = vec![Vec::new();N];
    for &(a,b) in &AB{
        E[a].push(b);
        E[b].push(a);
    }
    let D = bfs_dist(N,&E,0);
    let n = subtree_size(N, &E, 0);
    let d = D[N-1]/2+1;

    let mut i = N-1;
    while D[i] != d{
        for &j in &E[i]{
            if D[j]<D[i]{
                i = j;
                break
            }
        }
    }

    if n[i] as usize >= (N+1)/2{
        println!("Snuke");
    } else {
        println!("Fennec");
    }

}

fn subtree_size(N:usize,E:&Vec<Vec<usize>>,root:usize) -> Vec<isize>{
    let mut n = vec![-1;N];
    _subtree_size(N,E,&mut n,root,root);
    n
}
fn _subtree_size(N:usize,E:&Vec<Vec<usize>>,n:&mut Vec<isize>,i:usize,p:usize) {
    let mut cnt = 1;
    for &j in &E[i]{
        if j==p{continue;}
        if n[j]==-1 {_subtree_size(N,E,n,j,i);}
        cnt += n[j];
    }
    n[i] = cnt;
}


fn bfs_dist(N:usize,E:&Vec<Vec<usize>>,start:usize) -> Vec<isize>{
    let mut d = vec![-1;N];
    let mut q = VecDeque::new();
    q.push_back(start);
    d[start] = 0;
    while let Some(i) = q.pop_front(){
        for &j in &E[i]{
            if d[j]!= -1{continue;}
            d[j] = d[i]+1;
            q.push_back(j);
        }
    }
    d
}

Measured memory_bytes: 19476
import java.util.Scanner
object Main extends App {
  val sc = new Scanner(System.in)
  val s = sc.next
  val (l, r) = s.splitAt(2)
  def mon(i: Int): Boolean = 1 <= i && i <= 12
  println((mon(l.toInt), mon(r.toInt)) match {
    case (true, true) => "AMBIGUOUS"
    case (true, false) => "MMYY"
    case (false, true) => "YYMM"
    case (false, false) => "NA"
  })
}

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

struct card{
    char suit;
    int value;
};

void bubbleSort(card C[], int n);
void selectionSort(card C[], int n);
bool isSame(card A[], card B[], int n);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    card A[36], B[36];
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>A[i].suit>>A[i].value;
        B[i]=A[i];
    }
    bubbleSort(A, n);
    selectionSort(B, n);
    
    for(int i=0; i<n-1; i++) cout<<A[i].suit<<A[i].value<<' ';
    cout<<A[n-1].suit<<A[n-1].value<<'\n'<<"Stable\n";
    for(int i=0; i<n-1; i++) cout<<B[i].suit<<B[i].value<<' ';
    cout<<B[n-1].suit<<B[n-1].value<<'\n';
    if(isSame(A, B, n)) cout<<"Stable\n";
    else cout<<"Not stable\n";
    return 0;
}

void bubbleSort(card C[], int n)
{
    for(int i=0; i<n; i++) {
        for(int j=n-1; j>i; j--) {
            if(C[j].value<C[j-1].value) swap(C[j], C[j-1]);
        }
    }
}

void selectionSort(card C[], int n)
{
    for(int i=0; i<n; i++) {
        int mini=i;
        for(int j=i+1; j<n; j++) {
            if(C[j].value<C[mini].value) mini=j;
        }
        if(mini!=i) swap(C[mini], C[i]);
    }
}

bool isSame(card A[], card B[], int n)
{
    for(int i=0; i<n; i++) {
        if(A[i].suit!=B[i].suit) return false;
    }
    return true;
}

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

using namespace std;

typedef long long ll;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


double const eps = 1e-10;
ll const mod = 1e9+7;

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

    string s1,s2,s3;
    string result = "";
    cin >> s1 >> s2 >> s3;
    result = toupper(s1[0]);
    result += toupper(s2[0]);
    result += toupper(s3[0]);
    cout << result;


    return 0;

    // 274751WM
}


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

const int maxn = 200;
const double pi = acosl(-1.0);

using namespace std;

int n,x[maxn],y[maxn],res;

int main() {
  //  freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=0;i<n;i++) cin>>x[i]>>y[i];
    for (int i=0;i<n;i++) {
        vector<double> angle;
        for (int j=0;j<n;j++)
            if (i!=j) angle.push_back(atan2(y[j]-y[i],x[j]-x[i]));
        sort(angle.begin(),angle.end());
        double mx=0;
        for (int j=0;j<angle.size();j++) mx = max(mx,angle[j+1] - angle[j]);
        mx = max(mx, angle[0] - angle[angle.size()-1] + 2*pi);
        double res = (mx > pi ? (mx-pi)/(2*pi) : 0.0);
        cout<<setprecision(17)<<res<<endl;
    }
}


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

int main() {
    string S, T;
    cin >> S >> T;

    //答えansを仮置きする。
    //これが十分に大きくないと不正解となるので、
    //この値なら絶対に正しい答えが出る、という値を仮置きすること
    int ans = T.size();

    //Sの何文字目から調べるかを全探索する
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
N = int(input())
S = list(input())

answer = []
newN = N % 26
alp = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
for i in S:
  for num, j in enumerate(alp):
    if i == j:
      k = num + newN
      k = k % 26
      answer.append(alp[k])
      break
answer2 = ''.join(answer)
print(answer2)

Measured memory_bytes: 39792
#include<stdio.h>
int main()
{
    int a,b,c,x,y,z,s;
    scanf("%d %d %d",&a,&b,&c);
    if(a>=b && a>=c)
    {
        x=a;}
    else if(b>=a && b>=c)
    {
        x=b;}
    else if(c>=a && c>=b)
    {
        x=c;
    }
    if(a<=b && a<=c)
    {
        z=a;}
    else if(b<=a && b<=c)
    {
        z=b;}
    else if(c<=a && c<=b)
    {
        z=c;
    }
    if(a!=x && a!=z)
    {
        y=a;}
        if(b!=x && b!=z)
    {
        y=b;}
        if(c!=x && c!=z)
    {
        y=c;}
        s=(x-y)+(y-z);
        printf("%d\n",s);
       
        return 0;
    }

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

string s, t;

string lcs(int i, int j, vector<vector<int>>& dp) {
  if (dp[i][j] == 0) return "";
  if (s[i - 1] == t[j - 1]) {
    string tmp = lcs(i - 1, j - 1, dp);
    tmp.push_back(s[i - 1]);
    return tmp;
  }
  if (dp[i][j] == dp[i - 1][j]) return lcs(i - 1, j, dp);
  return lcs(i, j - 1, dp);
}

int main() {
  cin >> s >> t;
  vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1, 0));
  for (int i = 1; i <= s.length(); i++) {
    for (int j = 1; j <= t.length(); j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  cout << lcs(s.length(), t.length(), dp);
  return 0;
}

Measured memory_bytes: 35968
n=int(input())
name=[]
for i in range(n):
    name.append(input().split(" "))
m, a, r, c, h=0, 0, 0, 0, 0
for w in range(n):
    if name[w][0][0]=='M':
        m+=1
    if name[w][0][0]=='A':
        a+=1
    if name[w][0][0]=='R':
        r+=1
    if name[w][0][0]=='C':
        c+=1
    if name[w][0][0]=='H':
        h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Measured memory_bytes: 26980
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
char S[200010];
int main(){
	scanf("%s",S+1);int n=strlen(S+1),t=0,s=0;
	for(int i=1;i<=n;++i)
		if(S[i]=='S')++t;
		else if(t)--t;
		else ++s;
	printf("%d\n",2*s);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int N, M, X, fee[105];

int main() {
	scanf("%d%d%d", &N,&M,&X);
	for (int i = 0; i < M; i++) {
		int temp;
		scanf("%d", &temp);
		fee[temp] = 1;
	}

	int sum1 = 0;
	int sum2 = 0;

	for (int i = 0; i <= N; i++) {
		if (i < X) {
			sum1 += fee[i];
		}
		else sum2 += fee[i];
	}

	printf("%d", min(sum1, sum2));

}





/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <iostream>

int main(int argc, char* argv[])
{
    int time;
    int hour, min, sec;
    std::cin >> time;
    
    if (0 <= time && time < 86400){
        hour = time / 3600;
        min = (time % 3600) / 60;
        sec = (time % 3600) % 60;
    
        std::cout << hour << ":" << min << ":" << sec << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
vector<int> ans[maxn];
LL n;

void solve(int k) {
    int cur=1;
    puts("Yes");
    printf("%d\n", k);
    for (int i=1;i<=k;i++)
        for (int j=i+1;j<=k;j++) {
            ans[i].push_back(cur);
            ans[j].push_back(cur);
            cur++;
        }

    for (int i=1;i<=k;i++) {
        printf("%d ", (int)ans[i].size());
        for (auto j:ans[i]) printf("%d ", j);
        puts("");
    }
}

int main() {
    scanf("%lld",&n);
    bool f=false;
    for (int i=1;i<=1000;i++)
        if ((LL)i*(i-1)/2==n) {
            solve(i);
            f=true;
            break;
        }

    if (!f) puts("No");
    return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    int n, m; cin >> n >> m;
    ll x[n], y[n], z[n];
    rep(i, n){
        cin >> x[i] >> y[i] >> z[i];
    }

    pair<ll, ll> ppp[n], ppn[n], pnp[n], pnn[n], 
                 npp[n], npn[n], nnp[n], nnn[n];

    rep(i, n){
        ppp[i] = {   x[i] + y[i] + z[i], i};
        ppn[i] = {   x[i] + y[i] - z[i], i};
        pnp[i] = {   x[i] - y[i] + z[i], i};
        pnn[i] = {   x[i] - y[i] - z[i], i};
        npp[i] = { - x[i] + y[i] + z[i], i};
        npn[i] = { - x[i] + y[i] - z[i], i};
        nnp[i] = { - x[i] - y[i] + z[i], i};
        nnn[i] = { - x[i] - y[i] - z[i], i};
    }

    sort(ppp, ppp+n, greater<pair<ll, ll>>());
    sort(ppn, ppn+n, greater<pair<ll, ll>>());
    sort(pnp, pnp+n, greater<pair<ll, ll>>());
    sort(pnn, pnn+n, greater<pair<ll, ll>>());
    sort(npp, npp+n, greater<pair<ll, ll>>());
    sort(npn, npn+n, greater<pair<ll, ll>>());
    sort(nnp, nnp+n, greater<pair<ll, ll>>());
    sort(nnn, nnn+n, greater<pair<ll, ll>>());

    ll pppmax = 0, ppnmax = 0, pnpmax = 0, pnnmax = 0, 
       nppmax = 0, npnmax = 0, nnpmax = 0, nnnmax = 0;

    rep(i, m){
        pppmax += ppp[i].first;
        ppnmax += ppn[i].first;
        pnpmax += pnp[i].first;
        pnnmax += pnn[i].first;
        nppmax += npp[i].first;
        npnmax += npn[i].first;
        nnpmax += nnp[i].first;
        nnnmax += nnn[i].first;
    }

    ll vmaxp = max(max(pppmax, ppnmax), max(pnpmax, pnnmax));
    ll vmaxn = max(max(nppmax, npnmax), max(nnpmax, nnnmax));

    cout << max(vmaxp, vmaxn) << endl;

    return 0;
}

Measured memory_bytes: 384