akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 20
#define maxm maxn*(maxn-1)/2
#define p 1000000007
template <typename T>inline T read()
{
	register T sum=0;
	char cc=getchar();
	int sym=1;
	while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
	if(cc=='-')sym=-1,cc=getchar();
	sum=sum*10+cc-'0';
	cc=getchar();
	while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
	return sym*sum;
}
template <typename T>inline T read(T &a)
{
	a=read<T>();
	return a;
}
long long n,m,a[maxm],b[maxm],c[(1<<maxn)],d[(1<<maxn)],fc[maxm],f[2][(1<<maxn)],ans;
int main()
{
	n=read<int>(),m=read<int>();
	fc[0]=1;
	for(int i=1;i<=maxm;i++)
		fc[i]=(fc[i-1]*2)%p;
	for(int i=1;i<=m;i++)
		a[i]=read<int>()-1,b[i]=read<int>()-1;
	for(int i=0;i<(1<<n);i++)
		for(int j=1;j<=m;j++)
		{
			if((i&(1<<a[j]))&&(i&(1<<b[j])))c[i]++;
			if((i&(1<<a[j]))||(i&(1<<b[j])))d[i]++;
		}
	for(int k=0;k<2;k++)
		for(int i=0;i<(1<<n);i++)
		{
			if(!(i&(1<<k)))continue;
			f[k][i]=fc[c[i]];
			for(int j=(i-1)&i;j>0;j=(j-1)&i)
				if(j&(1<<k))f[k][i]=(f[k][i]-1ll*fc[c[i-j]]*f[k][j]%p+p)%p;
		}
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<(1<<n);j++)
			if(!(i&j)&&c[i]+c[j]==c[i|j])
				ans=(ans+(fc[m-d[i|j]]*(f[0][i]*f[1][j])%p)%p)%p;
	printf("%lld\n",(fc[m]-ans+p)%p);
	return 0;
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll INF64 = 1e18;

template <typename T>
string to_string(const vector<T> &v) {
  string ret = "<";
  for (auto it : v) {
    ret += to_string(it) + ", ";
  }
  ret.pop_back(); ret.pop_back();
  ret += ">";
  return ret;
}

void debug_print() { cerr << endl; }

template <typename T, typename ...U>
void debug_print(T t, U... u) {
  cerr << " " << to_string(t);
  debug_print(u...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_print(__VA_ARGS__)
const int N = 1e5 + 5;

//struct node {
  //int type; //0 change, 1 push
  //int idx = 0, val = 0; //in case of change
//};

vector<int> v;
//node arr[2 * N];
vector<int> adjList[2 * N];
ll ans[2 * N];
int val[2 * N];

void solve(int cur, int par = -1) {
  int lb = lower_bound(all(v), val[cur]) - v.begin();
  if (lb == v.size()) {
    v.pb(val[cur]);
    ans[cur] = v.size();
    for (auto it : adjList[cur]) {
      if (it == par)
        continue;
      solve(it, cur);
    }
    v.pop_back();
  } else {
    int tmp = v[lb];
    v[lb] = val[cur];
    ans[cur] = v.size();
    for (auto it : adjList[cur]) {
      if (it == par)
        continue;
      solve(it, cur);
    }
    v[lb] = tmp;
  }
}
    
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) 
    cin >> val[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adjList[a].pb(b);
    adjList[b].pb(a);
  }
  solve(1);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }  
  return 0;
}


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

const int N = 100+7;
int a[N];

int main()
{
	ll n,k;
	scanf("%lld %lld",&n,&k);
	
	n%=k;
	
	printf("%lld\n",min(abs(n-k),n));
}


Measured memory_bytes: 256
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	var N = parseInt(input[0], 10);
	var S = input[1][0];
	var vec_S = S.split("");
	var tmpAns = 0;
	for (var i = 0; i < N; i++){
		if (vec_S[i] !== "W") tmpAns ++;
	}
	var ans = tmpAns;
	for (var i = 0; i < N; i++){
		if (vec_S[i] === "E") tmpAns --;
		else tmpAns ++;
		ans = Math.min(ans, tmpAns);
	}
	console.log(ans);
}
  
Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 37820
#include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #include<string>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<numeric>
     
    #define rep(n) for(int i=0;i<n;i++)
    #define repp(j, n) for(int j=0;j<n;j++)
    #define reppp(i, m, n) for(int i=m;i<=n;i++)
    #define all(c) c.begin(), c.end()
    #define rall(c) c.rbegin(), c.rend()
    #define pb(x) push_back(x)
    #define eb(x,y) emplace_back(x,y)
    #define MOD 1000000007
    #define MAX 1000000001
    #define INF 1410065408
    #define EPS 1e-9
    #define DEBUG 0
     
    using namespace std;
    typedef long long ll;
    typedef pair<ll, ll> Pll;
    typedef pair<int, int> Pii;
    struct edge{int from, to; ll cost;};
     
    signed main(){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        cout << max(0, min(b,d)-max(a,c));
     
    }

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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 {
		mint res(*this);
		return res /= a;
	}

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

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

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];

	vector<ll> T(N + 1, 0);
	repn(i, N)T[A[i]]++;
	sort(T.begin(), T.end());

	vector<ll> f(N + 2);
	f[0] = 0;
	
	repn(i, N+1) {
		auto itr = lower_bound(T.begin(), T.end(), i);
		ll x = N - distance(T.begin(), itr) + 1;
		f[i] = f[i - 1] + x;

		//cout << f[i] << endl;
	}

	repn(i, N+1) f[i] /= i;

	vector<ll> ans(N + 1, 0);

	repn(i, N) {
		for (ll j = f[i + 1] + 1; j <= f[i]; j++) { ans[j] = i; }
	}

	repn(i, N) cout << ans[i] << endl;
	
	system("PAUSE");

}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n;cin>>n;
  cout<<n*(n-1)/2<<endl;

  return 0;
}


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

using namespace std;

int getLCM(int, int);
int getGCD(int, int, int);

int main(int argc, char *argv[]) {
  int x, y;
  vector<int> result;

  while (cin >> x >> y) {
    int lcm = getLCM(x, y);
    int gcd = getGCD(x, y, lcm);
    result.push_back(lcm);
    result.push_back(gcd);
  }
  for (int i = 0; i < result.size()/2; i++)
    cout << result[i*2] << ' ' << result[i*2+1] << endl;
  return 0;
}

int getLCM(int x, int y) {
  int tmp;

  if (x < y) {
    tmp = y;
    y = x; 
    x = tmp;
  }
  while (x % y != 0) {
    tmp = x % y;
    x = y;
    y = tmp;
  }
  return y;
}


int getGCD(int x, int y, int lcm) {
  x /= lcm;
  y /= lcm;
  return x * y * lcm;
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vll path;
//***********//
int main() {
	ll A;
	cin >> N >> A;
	vl X(N);
	for (i = 0; i < N; i++) cin >> X[i];
	vector<vll> dp(N + 1, vll(N + 1, vl(2501, 0)));
	dp[0][0][0] = 1;
	for (i = 0; i < N; i++) {
		for (j = 0; j <= i; j++) {
			for (k = 0; k <= 2500; k++) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k+X[i]<=2500) dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];
			}
		}
	}
	for (j = 1; j <= N; j++) ans += dp[N][j][j * A];
	co(ans);
}

Measured memory_bytes: 55244
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    double N;
    int status=0;
    int count=0;
    cin>>N;
    for(int i = 1;i<=N;i++){
    int status = floor(log10(i));
        if(status%2==0)count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 2000000000;
int main() {
	int n; cin >> n;
	int m[101][101];
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)
		cin >> m[i][j];
	int res = 0;
	int *d = new int[n];
	fill(d, d + n, INF); 
	d[0] = 0;
	bool *visit = new bool [n];
	fill(visit, visit + n, false);
	priority_queue <P, vector<P>, greater<P> > q;
	q.push(P(d[0], 0));
	while (!q.empty()) {
		int f = q.top().first, s = q.top().second;
		q.pop();
		if (visit[s]) continue;
		visit[s] = true;
		res += f;
		for (int i = 0; i < n; i++) {
			if (!visit[i]) {
				if (m[s][i] != -1) {
					if (m[s][i] < d[i]) {
						d[i] = m[s][i];
						q.push(P(d[i], i));
					}
				}
				}
			}
		}
	cout << res << endl;
	delete[] d, visit;
	return 0;
}

Measured memory_bytes: 3108
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    int ret = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int a = A[i];
            int b = A[j];

            auto it = lower_bound(A.begin(), A.end(), a + b);
            int num = it - A.begin();

            int ans = num - j - 1;
            if (ans > 0) ret += ans;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll k;
    cin >> k;
    vector <ll> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[k-1] << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int m = sc.NextInt();
        int x = sc.NextInt();
        int[] a = sc.IntArray();

        int answer1 = 0;
        for (int i = x; i <= n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (a[j] == i)
                {
                    answer1++;
                }
            }
        }
        int answer2 = 0;
        for (int i = 0; i <= x; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (a[j] == i)
                {
                    answer2++;
                }
            }
        }

        int answer = Math.Min(answer1, answer2);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
import sys
from collections import deque
l,n=map(int,input().split())
c=n
tree1=[int(i) for i in sys.stdin]
reversed_tree1=[l-i for i in reversed(tree1)]
tree=deque(tree1)
reversed_tree=deque(reversed_tree1)
if n%2 == 0:
  ans= sum(tree1)*2 + l*(n-1) +tree1[n//2] - sum(tree1[n//2:])*4
  ans2= sum(reversed_tree1)*2 + l*(n-1) +reversed_tree1[n//2] - sum(reversed_tree1[n//2:])*4
  n-=1
  c-=1
  ans3= ans-tree.popleft()*2-l+tree[n//2]*2
  ans= max(ans,ans3)
  ans4= ans2-reversed_tree.popleft()*2-l+(reversed_tree[n//2])*2
  ans2= max(ans2,ans4)
else:
  ans= sum(tree1)*2 + l*(n-1) - tree1[n//2] - sum(tree1[((n//2)+1):])*4
  ans3=ans
  ans2= sum(reversed_tree1)*2 + l*(n-1) - reversed_tree1[n//2] - sum(reversed_tree1[((n//2)+1):])*4
  ans4=ans2
for i in range(n//2):
  n-=1
  ans_stack= ans3-tree.popleft()*2-l+tree[(n-1)//2]+tree[(n+1)//2]
  ans= max(ans_stack,ans)
  ans3=ans_stack
  n-=1
  ans_stack= ans3-tree.popleft()*2-l+tree[n//2]*2
  ans=max(ans_stack,ans)
  ans3=ans_stack
n=c
for i in range(n//2):
  n-=1
  ans_stack= ans4-reversed_tree.popleft()*2-l+reversed_tree[(n-1)//2]+reversed_tree[(n+1)//2]
  ans2=max(ans_stack,ans2)
  ans4=ans_stack
  n-=1
  ans_stack= ans4-reversed_tree.popleft()*2-l+reversed_tree[n//2]*2
  ans2=max(ans2,ans_stack)
  ans4=ans_stack
print(max(ans,ans2))

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 5e5 + 5;

char s[MAXN];
int ans[MAXN];

void solve(){
	int n;
	scanf("%s", &s[1]);
	n = strlen(s + 1) + 1;
	s[0] = '>';
	s[n] = '<';
	REPN(i, 1, n) {
		if (s[i - 1] == '>' && s[i] == '<') {
			int j;
			for(j = i - 1; j > 0 && s[j - 1] == '>'; j--) {
				ans[j] = ans[j + 1] + 1;
				//printf("%d %d\n", j, ans[j]);
			}
			if (j > 0) {
				ans[j] = max(ans[j - 1], ans[j + 1]) + 1;
			}
			for(j = i + 1; j <= n && s[j] == '<'; j++) {
				ans[j] = ans[j - 1] + 1;
			}
		}
	}
	ll sum = 0ll;
	REPN(i, 1, n) {
		//printf("%d ", ans[i]);
		sum += ans[i];
	}
	cout << sum << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2816
#include<iostream>
#include<set>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=500009;

int n,k,ind[N];
int p[N],q[N];
set<int> f,b;
vector<int> g[N];

typedef set<int>::iterator it;

int main()
{
	n=read();
	k=read();

	for(int i=1;i<=n;i++)
		q[p[i]=read()]=i;
	for(int i=1;i<k;i++)
		f.insert(p[i]);
	for(int i=1;i<=n;i++)
	{
		if(i+k-1<=n)
			f.insert(p[i+k-1]);
		if(i)
			f.erase(p[i-1]);

		b.insert(p[i]);
		if(i>k)
			b.erase(p[i-k]);

		it cur=f.upper_bound(p[i]);
		if(cur!=f.end())
			g[q[*cur]].push_back(i),ind[i]++;
		cur=b.upper_bound(p[i]);
		if(cur!=b.end())
			g[q[*cur]].push_back(i),ind[i]++;
	}

	f.clear();
	for(int i=1;i<=n;i++)
		if(!ind[i])
			f.insert(-i);

	int top=0;
	while(f.size())
	{
		int u=-(*f.begin());
		p[++top]=u;
		f.erase(f.begin());
		for(int i=0,ed=g[u].size();i<ed;i++)
			if(--ind[g[u][i]]==0)
				f.insert(-g[u][i]);
	}

	for(int i=1;i<=n;i++)
		q[p[i]]=n-i+1;
	for(int i=1;i<=n;i++)
		printf("%d\n",q[i]);
	return 0;
}


Measured memory_bytes: 60800
n,a,b=map(int,input().split())
x=pow(2,n,10**9+7)
s=1
for i in range(a):
    s=s*(n-i)*pow((1+i),10**9+5,10**9+7)
    s=s%(10**9+7)
t=1
for i in range(b):
    t=t*(n-i)*pow((1+i),10**9+5,10**9+7)
    t=t%(10**9+7)
ans=(x-s-t-1)%(10**9+7)
print(ans)

Measured memory_bytes: 73488
#include<stdio.h>

int a[100005];
long long int two[100005];
long long int three[100005];
long long int mod = 1000000007;

int main() {
  char s[100005];
  scanf("%s", s);

  int n = strlen(s);

  two[0] = 1;
  three[0] = 1;
  for (int i = 1; i <= n; i++) {
    two[i] = (two[i-1] * 2) % mod;
    three[i] = (three[i-1] * 3) % mod;
  }

  long long int ans = 0;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ans = (ans + three[n-i-1] * two[count]) % mod;
      count++;
    }
  }
  ans = (ans + two[count]) % mod;

  printf("%lld\n", ans);
  return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    vector<vector<int>> dist(n, vector<int>(n, iinf));

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        dist[i][i] = 0;
        for (int j = 0; j < n; ++j) {
            if (s[j] == '1' && i < j) {
                graph[i].push_back(j);
                graph[j].push_back(i);
                dist[i][j] = dist[j][i] = 1;
            }
        }
    }

    vector<int> assignment(n, -1);
    assignment[0] = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int from = que.front(); que.pop();
        for (int to : graph[from]) {
            if (assignment[to] == -1) {
                assignment[to] = assignment[from] ^ 1;
                que.push(to);
            }
            else if (assignment[to] != (assignment[from] ^ 1)) {
                cout << -1 << endn;
                return;
            }
        }
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                mins(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            maxs(ans, dist[i][j]);
        }
    }
    cout << ans + 1 << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 640
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

signed main() {
  int h, w;
  cin >> h >> w;
  vector<vs> v(h, vs(w));
  REP(i, h) REP(j, w) cin >> v[i][j];
  REP(i, h) REP(j, w) {
    if (v[i][j] == "snuke") {
      char c = j + 'A';
      cout << c << i + 1 << endl;
    }
  }

  return 0;
}


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m , c;
  cin >> n >> m >> c;
  int b[m];
  int a[n][m];
  rep(j,m) cin >> b[j];
  rep(i,n)rep(j,m) cin >> a[i][j];
  int ans = 0;
  rep(i,n) {
    int sum = c;
    rep(j,m) {
      sum +=a[i][j]*b[j];
    }
    if(sum>0) ans++;
  }
   cout << ans << endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, M, l[200005];
struct edge
{
    int to, cost;
};
vector<edge> G[100005];
bool used[100005];
int d[100005];
PQG que;

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int r, c;
        cin >> l[i] >> r >> c;
        G[l[i]].pb({r, c});
        used[r] = true;
    }
    if(M == 0){
        printf("Yes\n");
        return 0;
    }
    for(int i = 0; i < M; i++){
        if(!used[l[i]]){
            G[0].pb({l[i], 0});
            used[l[i]] = true;
            //printf("root:%lld\n", l[i]);
        }
    }
    if(G[0].empty()){
        printf("No\n");
        return 0;
    }
    for(int i = 0; i <= N; i++){
        d[i] = INF;
    }
    que.push(mk(0, 0));
    bool flag = false;
    while(!que.empty()){
        int dis = que.top().first;
        int pos = que.top().second;
        que.pop();
        if(d[pos] != INF){
            if(d[pos] != dis){
                printf("No\n");
                return 0;
            }
        }
        for(int i = 0; i < (int)G[pos].size(); i++){
            edge e = G[pos][i];
            if(d[e.to] == INF){
                d[e.to] = dis + e.cost;
                que.push(mk(d[e.to], e.to));
            }
            else{
                if(d[e.to] != dis + e.cost){
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
    printf("Yes\n");

    return 0;
}
/*


*/


Measured memory_bytes: 12272
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll inverse(ll x) {
  return power(x, MOD - 2);
}

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n || k < 0) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  initFact(200010);
  int B, W;
  while (cin >> B >> W) {
    ll p = 0, q = 0;
    for (int i = 0; i < B + W; i++) {
      if (i > 0) {
        p += choose(i - 1, B - 1) * power(inverse(2), i) % MOD;
        p %= MOD;
        q += choose(i - 1, W - 1) * power(inverse(2), i) % MOD;
        q %= MOD;
      }
      ll res = (1 - p + q + MOD) * inverse(2) % MOD;
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 5376
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

// 1-indexed

int n; // range
int s[4 * 100005]; // n=1e5
int t;

int hyoka(int a, int b) { // sum
  return a + b;
}

//?????????
// INF????????????¨?????????

void sset(int n, vi d) {
  int i;
  for (t = 1; t < n; t *= 2)
    ;
  for (i = 0; i < n; i++) s[t + i] = d[i];
  for (; i < t; i++) s[t + i] = 0;
  for (i = t - 1; i; i--) s[i] = hyoka(s[i * 2], s[i * 2 + 1]);
}

// update
// i????????????°??????x?????????
void sud(int i, int n) {
  for (s[i += t] += n; i /= 2;) s[i] = hyoka(s[i * 2], s[i * 2 + 1]);
}

//??????¨?????????
//[a,b)????????????¨sout(a,b,1,0,t);
int sout(int a, int b, int i, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return s[i];
  return hyoka(sout(a, b, i * 2, l, (l + r) / 2), sout(a, b, i * 2 + 1, (l + r) / 2, r));
}

int main(void) {
  int i, j;
  int q;
  cin >> n >> q;
  vi d(n, 0);
  sset(n, d);
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << sout(x - 1, y, 1, 0, t) << endl;
    else
      sud(x - 1, y);
  }
}

Measured memory_bytes: 4644
S = input()
t = input()
neq = len(t)
for i in range(len(S)-len(t)+1):
  neq_temp = 0
  for j in range(len(t)):
    if S[i+j]!=t[j]:
      neq_temp += 1
  neq = min(neq,neq_temp)
print(neq)

Measured memory_bytes: 9068
N = gets.to_i
s1 = gets.chomp.split('')
s2 = gets.chomp.split('')

# Vertical=1
dominos = []
while s1.length > 0
    if s1.length == 1 || s1[0] != s1[1]
        dominos.push(1)
        s1.shift
    else
        dominos.push(0)
        s1.shift(2)
    end
end

MOD = 10**9+7

ans = dominos[0] == 1 ? 3 : 6
prev = dominos[0]
dominos.shift

dominos.each do |d|
    ans *= case [prev, d]
    when [0, 0]; 3
    when [0, 1]; 1
    when [1, 0]; 2
    when [1, 1]; 2
    end
    ans %= MOD
    prev = d
end

puts ans

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


int main() {
int N;
  cin >>N;
  
  vector<int> value(N);
  for(int i=0;i<N;i++){
    cin>>value[i];
  }
  vector<int> cost(N);
  for(int i=0;i<N;i++){
    cin>>cost[i];
  }
  
  int sum=0;
  for(int i=0;i<N;i++){
    if(value[i]-cost[i]>0){
      sum+=value[i]-cost[i];
    }
  }
  
  cout<<sum<<endl;
  
  
  
  

}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <cstdlib>
#define PI acos(-1.0)
#define ll long long int
#define db double
#define ull unsigned long long int
#define Fill(x,y) memset(x,y,sizeof(x))
#define bug printf("!!!!!!\n");
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define sz(a) (int)(a).size()
using namespace std;
const db eps = 1e-6;
const int inf = 0x3f3f3f3f; //用这个可以直接mem
const ll INF = 1e18;
const int mod = 1e9+7;
const int maxn = 1e4+5;
int cas=1;
ll a[maxn];
ll b[maxn];
void solve()
{
    int n; cin >> n ;
    for (int i = 1 ; i <= n ; i ++) {
        cin >> a[i];
    }
    for (int i = 1 ; i <= n ; i ++) {
        cin >> b[i];
    }
    ll sum1 = 0 , sum2 = 0 ;
    for (int i = 1 ; i <= n ; i ++) {
        if (a[i] == b[i]) continue;
        if (a[i] < b[i]) {
            sum1 += (b[i] - a[i]) / 2;
        }
        else sum2 += a[i] - b[i];
    }
    if (sum1 >= sum2) cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main()
{
   //  freopen("in.txt","r",stdin);
    //  freopen("out.txt","w",stdout);
    int t = 1 ;
    //scanf("%d",&t);
    while(t--){
       // printf("Case %d: ", cas++);
        solve();
        //printf("\n");
    }
}









Measured memory_bytes: 384
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var s = cin.ReadLine;

            char[] sChrAry = s.ToCharArray();

            IEnumerable<int> AChrAry = sChrAry.Select((p, i) => new { Content = p, Index = i })
                                    .Where(x => x.Content == 'A')
                                    .Select(x => x.Index);
            IEnumerable<int> ZChrAry = sChrAry.Select((p, i) => new { Content = p, Index = i })
                                    .Where(x => x.Content == 'Z')
                                    .Select(x => x.Index);

            WriteLine(ZChrAry.Last() -  AChrAry.First() + 1);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 14556
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

struct Edge{
    ll from;
    ll to;
    ll cost;
    Edge(ll u, ll v, ll c) : from(u), to(v), cost(c){}
};

ostream &operator<<(ostream &s, Edge e){
    s << "<" << e.from << ", " << e.to << ", " << e.cost << " >";
    return s;
}

vector<vector<Edge>> G;
vector<ll> dist;
vector<ll> used;
void init(ll n){
    G.resize(3*n);
    dist.resize(3*n, INF);
    used.resize(3*n, 0);
}

void dijkstra(ll s){
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(P(0, s));
    while(pq.size()){
        P p = pq.top(); pq.pop();
        ll d = p.first;
        ll v = p.second;
        if(used[v] or d>dist[v]) continue;
        used[v] = 1;
        for(ll i=0; i<G[v].size(); i++){
            Edge edge = G[v][i];
            if(used[edge.to])continue;
            if(dist[edge.to]>dist[v]+edge.cost){
                dist[edge.to] = dist[v]+edge.cost;
                pq.push(P(dist[edge.to], edge.to));
            }
        }
    }
}

void bfs(ll s){
    queue<ll> q;
    q.push(s);
    while(q.size()){
        ll v = q.front(); q.pop();
        if(used[v]) continue;
        used[v] = 1;
        for(ll i=0; i<G[v].size(); i++){
            ll nv = G[v][i].to;
            if(used[nv]) continue;
            q.push(nv); 
            dist[nv] = dist[v] + 1;
        }
    }
}

signed main(){
    ll N, M;
    cin>>N>>M;
    init(N);
    REP(i, M){
        ll u, v;cin>>u>>v;
        u--,v--;
        REP(j, 3){
            G[j*N+u].emplace_back(Edge(u, ((j+1)%3)*N+v, 1));
        }
    }
    ll S, T; cin >> S >> T;
    S--, T--;
    dist[0*N+S] = 0;
    dijkstra(S);
    if(dist[0*N+T]==INF) cout<<-1<<endl;
    else cout << dist[T]/3 << endl;
    return 0;
}

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

#define ll long long

int main() {
  ll N, M;
  cin >> N >> M;
  
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  
  vector<pair<ll, ll>> change_vec;
  
  for (int i = 0; i < M; i++) {
    ll B, C;
    cin >> B >> C;
    
    change_vec.push_back({C, B});
    
  }
  
  sort(change_vec.begin(), change_vec.end());

  ll index = 0;
  ll m = change_vec.size();
  

  for (ll i = m-1; i >= 0; i--) {
    pair<ll, ll> p = change_vec[i];
    
    
    for (ll j = 0; j < p.second; j++) {
    
      if (A[index] < p.first) {
        A[index] = p.first;
        index++;
      } else {
        break;
      }
      
    }
    
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i];
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 6128
/*input
4 4 2
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[505][505],n,h,w;
void show(){
	for(int i=0;i<h;++i,cout<<'\n')
		for(int j=0;j<w;++j)
			if(a[i][j]==1) cout<<'R';
			else if(a[i][j]==2) cout<<'Y';
			else if(a[i][j]==3) cout<<'G';
			else if(a[i][j]==0) cout<<'B';
}
int main(){
	long long d,p,x=0,y=0,dx=0,dy=0,xx=0,yy=0;
	cin>>h>>w>>d;
	if(d%2){
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j)
				a[i][j]=(i+j)%2;
		}
	}
	else{
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j){
				if(((i+j)/d)%2){
					a[i][j]=2;
				}
				if(((i-j+w)/d)%2)
					a[i][j]++;
			}
		}
	}
	show();
}

Measured memory_bytes: 2432
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>

using namespace std;


	int n,m;
	int masu[17][17];
	int ura[17][17];
	
int motom(){
		for(int i=0;i<17;i++){
			for(int j=0;j<17;j++){
				masu[i][j]=0;
			}
		}
		for(int i=1;i<=m;i++){
			switch(ura[1][i]){
				case 0:masu[1][i]+=1;break;
				case 1:masu[1][i]+=0;break;
				case 2:masu[1][i]+=1;break;
			}
		}
		for(int i=1;i<n;i++){
			for(int j=1;j<=m;j++){
				if(ura[i][j]==0){
					if(ura[i+1][j-1]==0){
						masu[i+1][j-1]+=masu[i][j];
					}
					if(ura[i+1][j]!=1){
						masu[i+1][j]+=masu[i][j];
					}
					if(ura[i+1][j+1]==0){
						masu[i+1][j+1]+=masu[i][j];
					}
				}else if(ura[i][j]==2){
					if(ura[i+2][j]!=1){
						masu[i+2][j]+=masu[i][j];
					}
				}
			}
		}
		
		int cont=0;
		for(int i=n;i<=n+1;i++){
			for(int j=1;j<=m;j++){
				cont+=masu[i][j];
			}
		}
		return cont;
}
int contt;
void saiki(int x,int y){
	if(y<1||y>m){
		return;
	}
	
		masu[x][y]++;
	if(x>n-1){
		contt++;
		return;
	}
	if(ura[x][y]==0){
		if(ura[x+1][y-1]==0){
			saiki(x+1,y-1);
		}
		if(ura[x+1][y]!=1){
			saiki(x+1,y);
		}
		if(ura[x+1][y+1]==0){
			saiki(x+1,y+1);
		}
	}
	if(ura[x][y]==2){
		if(ura[x+2][y]!=1){
			saiki(x+2,y);
		}
	}
}
int simu(){
		for(int i=0;i<17;i++){
			for(int j=0;j<17;j++){
				masu[i][j]=0;
			}
		}
	contt=0;
	for(int i=1;i<=m;i++){
		if(ura[1][i]!=1){
			saiki(1,i);
		}
	}
	/*
	puts("");
	for(int i=1;i<=n+1;i++){
		for(int j=1;j<=m;j++){
			printf("%d ",masu[i][j]);
		}
		puts("");
	}*/
	return contt;
}

int main(){
	srand(time(NULL));
	int cc=0;
	while(1){
		scanf("%d%d",&m,&n);
		if(n==0 && m==0){
			break;
		}
		for(int i=0;i<17;i++){
			for(int j=0;j<17;j++){
				masu[i][j]=0;
				ura[i][j]=0;
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				scanf("%d",&ura[i][j]);
			}
		}
		int aa=motom();
		
		printf("%d\n",aa);
	}
	
}

Measured memory_bytes: 0
N = gets.to_i

c = Array.new(2*N)

(2*N).times do |i|
	c[i]=i+1
end

T = gets.to_i

T.times do
	n = gets.to_i

	if n == 0
		cc = c.dup
		(N).times do |i|
			c[2*i] = cc[i]
			c[2*i+1] =  cc[N+i]
		end
	else
		c1 = c.values_at(0..n-1)
		c2 = c.values_at(n..2*N-1)
		c = c2+c1
	end
end

c.each do |v|
	puts v
end

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

using namespace std;

int main() {

    int h, w;
    cin >> h >> w;
    string s, r;


    for (int i = 0; i < h; ++i) {
        cin >> s;

        r += s;
        r += "\n";
        r += s;
        r+="\n";

    }
    cout << r;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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


/*
int V; //頂点数
std::vector<std::vector<edge>> G;  std::vector<int> G;
std::vector<int> d; //sからの距離
*/

struct edge{
    int to, cost;
    edge(int To, int Cost): to(To), cost(Cost){}
};

void dijkstra(std::vector<std::vector<edge>>& G, std::vector<int>& d, int s){
    //pair<int, int> first: 距離　second: 頂点
    std::priority_queue<std::pair<int, int>,
                        std::vector<std::pair<int, int>>,
                        std::greater<std::pair<int, int>>> que;
    int V(G.size());
    d.resize(V, INF+3);
    d[s] = 0;
    que.push({0, s});

    while(!que.empty()){
        std::pair<int, int> p(que.top()); que.pop();
        int v(p.second);
        if(d[v] < p.first) continue;
        for(edge &e: G[v]){
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
            }
        }
    }
}
int main(){
    int V, E, r; std::cin >> V >> E >> r;
    std::vector<std::vector<edge>> G(V);
    {
        int s, t, d; 
        for(int i(0); i < E; ++i){
            std::cin >> s >> t >> d;
            G[s].emplace_back(t, d);
        }
    }
    std::vector<int> d;
    dijkstra(G, d, r);
    for(int i(0); i < V; ++i){
        if(d[i] > INF) std::cout << "INF";
        else std::cout << d[i];
        std::cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 12904