akhauriyash/Code-Regression huggingface dataset:
def check(row)
    return [[],0] if !row || row[2] == 0
    ret = []
    if row[2] == row[1]
        if row[1] == row[0]
            ret.concat([0,1,2])
        end
        if row[2] == row[3]
            ret.concat([1,2,3])
        end
    end
    if row[2] == row[3]
        if row[3] == row[4]
            ret.concat([2,3,4])
        end
        if row[1] == row[2]
            ret.concat([1,2,3])
        end
    end
    ret = ret.uniq
    score = ret.map{|i| row[i]}.inject(:+) || 0
    return [ret, score]
end
def pp(f)
    puts
    f.transpose.reverse.each do |r|
        r.each do |c|
            print c.to_s + " "
        end
        puts
    end
end

loop do
    h = gets.to_i
    break if h == 0
    f = h.times.map{gets.split.map(&:to_i)}
    f = f.reverse.transpose
    score = 0
    b = true
    while b
        b = false
        ds = Array.new(h)
        0.upto(h) do |i|
            ds[i], p = check f.transpose[i]
            if p
                score += p
                b = true if p > 0
            end
        end
        ds.reverse.each_with_index do |dd,i|
            dd.each do |d|
                f[d].delete_at(h-i)
                f[d].push(0)
            end
        end
        break if !b
    end
    puts score
end

Measured memory_bytes: 6164
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>

#define rep(i,p,n) for(int i=p;i<n;i++)
#define lli long long int
#define vi vector<int> 

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}


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

	rep(i, 0, n) {
		rep(j, 0, m) {
			string s;
			cin >> s;
			if (s == "snuke") {
				cout << (char)('A' + j) << i+1 << endl;
			}
		}
	}



	return 0;
}

Measured memory_bytes: 256
X,Y,A,B,C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

AD = P[:X] + Q[:Y] + R
AD.sort(reverse=True)
print(sum(AD[:(X+Y)]))
exit(0)

### zanshi
ans = sum(P[:X]) + sum(Q[:Y])

pi, qi, ri = X-1, Y-1, 0
for _ in range(C+10):
  if P[pi] < R[ri] and P[pi] <= Q[qi]:
    ans += R[ri] - P[pi]
    pi, ri = pi-1, ri+1
  elif Q[qi] < R[ri] and P[pi] >= Q[qi]:
    ans += R[ri] - Q[qi]
    qi, ri = qi-1, ri+1
  if pi < 0 or qi < 0 or ri >= C:
    break
print(ans)

Measured memory_bytes: 23360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mx 10000000
ll cn[100000009];
void asif()
{
    /*if(n==1)return 1;
    if(n==2)return 2;
    if(n==3)return 2;*/
    for(ll i=1; i<=mx; i++)
    {

        for(ll j=i;j<=mx;j+=i)cn[j]++;
    }
}
int main()
{
    asif();
    ll t,n,i,j,ss=0;
    cin>>t;
    for(i=1;i<=t;i++)
    {
        ss+=(i*cn[i]);
    }
    cout<<ss<<endl;
}


Measured memory_bytes: 81716
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

double a[100];
signed main(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }   
    sort(a,a+n,greater<int>());
    int x = n;
    rep(i,x-1){
        n--;
        a[n-1] = (a[n-1] + a[n]) / 2;
        a[n] = 0;
        sort(a,a+n,greater<int>());
    }   
    cout << fixed << a[0] << '\n';
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n=input()
a=list(map(int,input().split()))
b=Counter(a)
n=int(input())
ans=sum(a)
for i in range(n):
    x,y=map(int,input().split())
    ans+=b[x]*(y-x)
    print(ans)
    b[y]+=b[x]
    b[x]=0

Measured memory_bytes: 24140
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

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

int main(void){
	int a;
	std::cin >> a;
	std::cout << (a*a*a+a*a+a) << std::endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define NIL -1
#define MAX 200005
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long int ll;
using namespace std;

vector<int> to[MAX];
vector<int> ans;

void dfs(int v,int p=-1){
    for(int u : to[v]){
        if(u==p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        --a;--b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q){
        int p,x;
        cin>>p>>x;
        --p;
        ans[p]+=x;
    }
    dfs(0);

    rep(i,n) cout<<ans[i]<<endl;
 //   system("pause");
    return 0;
}

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

int main(){
    string S;
    int i;
    bool easy=true;

    cin>>S;

    for(i=0;i<S.size();i++){
        if(i%2==0){
            if(S[i]!='R' && S[i]!='U' && S[i]!='D'){
                easy=false;
                break;
            }
        }else{
            if(S[i]!='L' && S[i]!='U' && S[i]!='D'){
                easy=false;
                break;
            }
        }
    }

    if(easy==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

public class Main {

	// インク滴を落とすマス
	private int[][] cell = new int[10][10];

	public static void main(String[] args) throws Exception {
		new Main().execute();
	}

	/**
	 * 計算実行
	 */
	private void execute() throws IOException {

		// 標準入力
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		// 標準入力を１行ずつ処理
		String line = null;
		while ((line = reader.readLine()) != null) {
			String[] inkInfo = line.split(",");

			// インクを落とした結果を紙に反映
			calcInkDropPoint(Integer.parseInt(inkInfo[0]),
					Integer.parseInt(inkInfo[1]), Integer.parseInt(inkInfo[2]));
		}

		// 結果を出力
		outputInkDropPoint();

	}

	/**
	 * インク滴を落とした結果を紙に反映
	 * 
	 * @param x
	 *            X座標
	 * @param y
	 *            Y座標
	 * @param size
	 *            インク滴のサイズ
	 */
	private void calcInkDropPoint(int x, int y, int size) {

		// インクが落ちた箇所にポイント加算
		cell[x][y] += 1;

		// 小の滴が落ちた座標にポイント加算
		addPoint(x + 1, y);
		addPoint(x - 1, y);
		addPoint(x, y + 1);
		addPoint(x, y - 1);

		// 中の滴が落ちた座標にポイント加算
		if (size > 1) {
			addPoint(x + 1, y + 1);
			addPoint(x - 1, y + 1);
			addPoint(x + 1, y - 1);
			addPoint(x - 1, y - 1);
		}

		// 大の滴が落ちた座標にポイント加算
		if (size > 2) {
			addPoint(x + 2, y);
			addPoint(x - 2, y);
			addPoint(x, y + 2);
			addPoint(x, y - 2);
		}

	}

	/**
	 * インク滴を落とした結果を出力 「色のついていない部分のマス目の個数」と「１番濃いマス目の濃さ」を出力する。
	 */
	private void outputInkDropPoint() {

		int totalCell = 0;
		int maxPoint = 0;

		for (int i = 0; i < cell.length; i++) {
			for (int j = 0; j < cell[i].length; j++) {

				// 色のついていないセル個数を計算
				if (cell[i][j] == 0) {
					totalCell += 1;
				}

				// 最高得点の計算
				if (cell[i][j] > maxPoint) {
					maxPoint = cell[i][j];
				}
			}
		}

		// 結果を標準出力
		System.out.println(totalCell);
		System.out.println(maxPoint);
	}

	/**
	 * インク滴が滲む範囲か判定
	 * 
	 * @param direction
	 *            座標
	 * @return 判定結果(true:範囲内、false:範囲外)
	 */
	private boolean isInsideOfCell(int direction) {
		return (direction >= 0) && (direction < 10);
	}

	/**
	 * インク滴が滲む範囲であれば加算
	 * 
	 * @param x
	 *            X座標
	 * @param y
	 *            Y座標
	 */
	private void addPoint(int x, int y) {
		// 範囲内であれば加点
		if (isInsideOfCell(x) && isInsideOfCell(y)) {
			cell[x][y] += 1;
		}
	}

}

Measured memory_bytes: 16984
def solve():
    ans = 1000000
    for i in range(2):
        if H[i] % 3 == 0:
            return 0
        ans = min(ans, H[1 - i])
        H1 = H[i] // 3
        S_max = (H1 + 1) * H[1 - i]
        S_min = (H[i] - H1 - 1) * (H[1 - i] // 2)
        ans = min(ans, S_max - S_min)
        S_min = H1 * H[1 - i]
        S_max = (H[i] - H1) * ((H[1 - i] + 1) // 2)
        ans = min(ans, S_max - S_min)
    return ans

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

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

int main(){
  int A, B, C;
  int max_value;
  cin >> A >> B >> C;
  max_value = max(A, max(B, C));
  if((max_value*3 - (A+B+C))%2 != 0) cout << (max_value*3 - (A+B+C))/2 + 2 << endl;
  else cout << (max_value*3 - (A+B+C))/2 << endl;
  return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int n;
    cin >> n;
    vector<string> vs(n);
    rep(i, n) cin >> vs[i];
    string t;
    cin >> t;

    int pre = 0;
    int post = 0;
    for (auto s : vs) {
        string sa = s;
        replace(all(sa), '?', 'a');
        string sz = s;
        replace(all(sz), '?', 'z');
        if (sa < t && sz < t) pre++;
        if (sa > t && sz > t) post++;
    }

    bool printed = false;
    rep(i, n + 1) {
        if (pre < i + 1 && i + 1 <= (n + 1) - post) {
            cout << (printed ? " " : "") << i + 1;
            printed = true;
        }
    }
    cout << endl;
}


Measured memory_bytes: 896
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        DecimalFormat df = new DecimalFormat("0.00000000");

        final int N = Integer.parseInt(sc.next());
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        char[] ch = sc.next().toCharArray();
        int pass = 0;
        int rank = 0;
        for (int i=0; i<N; i++) {
            if (ch[i] == 'b')   rank++;
            if (ch[i] == 'a' && pass < A+B) {
                out.println("Yes");
                pass++;
            } else if (ch[i] == 'b' && pass < A+B && rank <= B) {
                out.println("Yes");
                pass++;
            } else {
                out.println("No");
            }
        }
        
        out.flush();
    }
}

Measured memory_bytes: 26804
#include<stdio.h>
int main()
{
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	
	if(A==C && B==C && A==B) printf("No");
	else
	{
		if (A!=C && B!=C && A!=B)
		{
			printf("No");
		}
		else
		{
			printf("Yes");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1692
/*  It's harder to read code than to write it.       
                                    - Joel Spolsky   
                                                    
    --Shubh                                                                     
*/
#include <bits/stdc++.h>

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
 
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define vii vector<pii>
#define mod 998244353 
//(1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define pi 3.14159265359
#define endl '\n'
#define gcd(a,b) __gcd(a,b)

//=================================================================================
ll i,j;

int main()
{   
    IOS;
    ll t;
    t=1;
    //cin>>t;
    
    while(t--)
    {
       ll type[3];
       cin>>type[0]>>type[1]>>type[2];
       sort(type,type+3);
       if(type[0]==type[1] && type[0]==type[2])
       {
        cout<<0<<endl;
       }else if(type[1]==type[2])
       {
            ll temp = type[2]-type[0]; 
            if((temp)%2)
            {
                ll tt=(temp-1)/2;
                tt+=2;
                cout<<tt<<endl;

            }else
            {
                cout<<temp/2<<endl;
            }
       }else if(type[0]==type[1])
       {
            ll temp = type[2]-type[1]; 
            cout<<temp<<endl;
       }else
       {
            ll temp1 = type[2]-type[1];
            ll ans=temp1;
            type[1]+=temp1;
            type[0]+=temp1;
            ll temp = type[2]-type[0]; 
            if((temp)%2)
            {
                ll tt=(temp-1)/2;
                tt+=2;
                cout<<tt+ans<<endl;

            }else
            {
                ans+=(temp/2);
                cout<<ans<<endl;
            }

       }



    }




    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

const int inf = 1 << 30;

class SqrtDiv {
private:
    vector<int> v;
    vector<int> block;
    int blockSize;
public:
    SqrtDiv(int n) {
        v.resize(n, inf);
        blockSize = ceil(sqrt(n) + 1e-9);
        block.resize((n + blockSize - 1) / blockSize, inf);
    }

    void set(int n, int x) {
        v[x] = n;
        x /= blockSize;
        block[x] = inf;
        REP (i, x * blockSize, (x + 1) * blockSize) {
            block[x] = min(block[x], v[i]);
        }
    }

    int get(int l, int r) {
        int ans = inf;
        REP (i, 0, block.size()) {
            int ll = i * blockSize;
            int rr = (i + 1) * blockSize;
            if (rr <= l || r <= ll) continue;
            else if (l <= ll && rr <= r) ans = min(ans, block[i]);
            else {
                REP (j, max(ll, l), min(rr, r)) {
                    ans = min(ans, v[j]);
                }
            }
        }
        return ans;
    }
};

struct Data {
    int l, r, m;
    Data(int l, int r, int m) : l(l), r(r), m(m) {}
};

bool operator<(const Data &d1, const Data &d2) {
    return d1.m > d2.m;
}

int main () {
    int N;
    cin >> N;
    map<int, int> ml;
    SqrtDiv sq[2] = {SqrtDiv(N), SqrtDiv(N)};
    REP (i, 0, N) {
        int ai;
        cin >> ai;
        ml[ai] = i;
        sq[0].set(ai, i);
        sq[1].set(ai, i);
        sq[!(i % 2)].set(inf, i);
    }

    priority_queue<Data, vector<Data>> pq;
    pq.emplace(0, N, sq[0].get(0, N));
    while (pq.size()) {
        auto t = pq.top();
        pq.pop();
        int lt = ml[t.m];
        int g = sq[!(t.r % 2)].get(lt + 1, t.r);
        int gpos = ml[g];
        if (t.l < lt) pq.emplace(t.l, lt, sq[t.l % 2].get(t.l, lt));
        if (lt + 1 < gpos) pq.emplace(lt + 1, gpos, sq[!(lt % 2)].get(lt + 1, gpos));
        if (gpos + 1 < t.r) pq.emplace(gpos + 1, t.r, sq[!(gpos % 2)].get(gpos + 1, t.r));
        cout << t.m << ' ' << g << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13048
#include <iostream>

using namespace std;
int main(void){
    int N;
    cin >> N;
    
    int h;
    int count = 0, max_count = 0, hight = 0;
    for (int i = 0; i < N; i++) {
        cin >> h;
        if (hight < h) {
            if (max_count < count)
                max_count = count;
            count = 0;
        }
        else
            count++;
        hight = h;
    }
    if (max_count < count)
        max_count = count;
    cout << max_count <<endl;
}

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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

vector<int> edge[100005];

long long N,M;
int A,B;

/*==================================================*/
/*==================================================*/

int color[100005];
long long cnt[2];
bool flag;

int check(int node, int nowcol){
    color[node] = nowcol;
    cnt[nowcol]++;

    long long ret = 1;
    REP(i,0,edge[node].size()){
        if(color[edge[node][i]] == -1){
            ret += check(edge[node][i], (nowcol+1)%2);
        }
        if(color[edge[node][i]] == nowcol){
            //ret -= 1000000000000000000;
            flag = true;
        }
    }
    return ret;
}

int main() {
    cin>>N>>M;
    REP(i,0,M){
        cin>>A>>B;
        A--; B--;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }

    REP(i,0,N) color[i] = -1;

    long long ans = 0;
    if(check(0, 0) == N && !flag){
        //cout<<"T"<<endl;
        ans = cnt[0]*cnt[1] - M;
    }else{
        //cout<<"F"<<endl;
        ans = N*(N-1)/2 - M;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 7296
def ok?(d)
  r = 0
  d.each.with_index do |x, i|
    return false if r < 10 * i
    r = [r, 10 * i + x].max
  end
  true
end

d = gets.to_i.times.map{gets.to_i}
puts (ok?(d) and ok?(d.reverse)) ? "yes" : "no"

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

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    
    if(n % k == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
    
    return 0;
}

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

#define OnlineJudge1

#define loop(a,n) for(int i = a;i<n;i++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)


typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.in","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

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

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

//    int powres[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912};

ll power(ll b, ll p){
    if(p == 0)return 1;
    ll res = power(b,p/2);
    res *= res;
    if(p & 1)res *= b;
    return res;
}

set<ll> factors;
set<ll> divisors;

void divide(ll n){
    for(ll i = 2;i * i <= n;i++){
        if(n % i == 0){
            divisors.insert(i);
            divisors.insert(n/i);

        }
    }
}

void factorize(ll n){
        for(ll i = 2;i * i <= n;i++){
        if(n % i == 0){
            factors.insert(i);
            while(n % i == 0)n /= i;
        }
    }
    if(n != 1)factors.insert(n);
}

int Max = 1e7 + 5;
int prime[(int)1e7+7];

void sieve(){
    prime[0] = prime[1] = 1;
    for(ll i = 1;i<=Max;i++){
        if(prime[i])
            continue;
        else{
            for(ll j = i*i;j<=Max;j+=i)
                prime[j] = 1;
        }
    }
}

int main(){
    init();
    int n;
    cin >> n;
    int arr[n],dp[n] = {0};
    for(int i = 0;i < n;i++){
        cin >> arr[i];
    }
    for(int i = 1;i < n;i++){
        dp[i] = dp[i-1] + abs(arr[i] - arr[i-1]);
        if(i - 2 >= 0)
            dp[i] = min(dp[i], dp[i-2] + abs(arr[i] - arr[i-2]));
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int array[128];

int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}

int main(){
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    array['A']=1,array['C']=2,array['G']=3,array['T']=4;

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}



Measured memory_bytes: 4520
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;
use std::cmp::min;

fn main(){
    let n: usize = read();
    let k: usize = read();

    let mut po: Vec<Vec<usize>> = vec![Vec::new();n];
    let mut edge: Vec<(usize, usize)> = Vec::new();
    for _ in 0..n-1 {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        po[a].push(b);
        po[b].push(a);
        edge.push((a, b));
    }

    let inf = 1 << 31;
    let mut ans = n;
    for i in 0..n {
        let mut que: VecDeque<(usize, usize)> = VecDeque::new();
        let mut dis: Vec<usize> = vec![inf;n];
        if k % 2 == 0 {
            dis[i] = 0;
            que.push_back((i, 0));
        } else {
            if i == n - 1 { break; }
            let (a, b) = edge[i];
            dis[a] = 0;
            dis[b] = 0;
            que.push_back((a, 0));
            que.push_back((b, 0));
        }
        while !que.is_empty() {
            let (v, d) = que.pop_front().unwrap();
            for &j in &po[v] {
                if dis[j] == inf {
                    dis[j] = d + 1;
                    que.push_back((j, d + 1));
                }
            }
        }
        ans = min(ans,
            (0..n).filter(|&x| dis[x] > k / 2).count()
        );
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4476
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

Weight minimum_spanning_tree(const Graph &g, size_t s=0) {
    /* Prim */
    size_t V=g.size();
    Edges T;
    Weight total=0;
    vector<Weight> d(V, INF); d[s]=0;
    vector<bool> visited(V);

    lp_queue<pair<Weight, size_t>> q; q.push(make_pair(0, s));
    while (!q.empty()) {
        pair<Weight, size_t> p=q.top(); q.pop();
        size_t v=p.second;
        if (d[v] < p.first) continue;
        if (visited[v]) continue;

        visited[v] = true;
        total += d[v];
        for (const Edge &e: g[v])
            if (d[e.dst] > e.weight) {
                d[e.dst] = e.weight;
                q.push(make_pair(d[e.dst], e.dst));
            }
    }
    return total;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight w;
        scanf("%zu %zu %lld", &s, &t, &w);

        join(g, s, t, w);
    }

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

Measured memory_bytes: 10676
#include <stdio.h>

double calc(double *base,double *des,double *p){
    double a[2]={des[0]-base[0],des[1]-base[1]};
    double b[2]={p[0]-base[0],p[1]-base[1]};
    return a[0]*b[1]-a[1]*b[0];
}
int main(void){
    double A[2],B[2],C[2],P[2],ans1,ans2,ans3;
    for(;~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&A[0],&A[1],&B[0],&B[1],&C[0],&C[1],&P[0],&P[1]);){
        ans1=calc(A,B,P),ans2=calc(B,C,P),ans3=calc(C,A,P);
        if((ans1<0 && ans2<0 && ans3<0) || (ans1>=0 && ans2>=0 && ans3>=0))
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,N,K;
  cin>>N>>K;
  K=K*2+1;
  cout<<(N+K-1)/K;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,t;
	cin>>n>>t;
	int ans=t,ftmp,tmp;
	cin>>ftmp;
	for(int i=1;i<n;++i){
		cin>>tmp;
		ans+=min(tmp-ftmp,t);
		ftmp=tmp;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int main(){
    ll n,d; cin >> n >> d;
    int ans=0;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=d*d) ans++;        
    }
    cout << ans << endl;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1000000007;

ll extgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

void cmb_init(int n, vll &fac, vll &finv) {
  ll x, y;
  for (int i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    extgcd(i, MOD, x, y);
    finv[i] = finv[i - 1] * (MOD + x % MOD) % MOD;
  }
}

// void cmb_init(int n, vll &fac, vll &finv) {
//   vll inv(n + 1, 1);
//   for (int i = 2; i <= n; i++) {
//     fac[i] = fac[i - 1] * i % MOD;
//     inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
//     finv[i] = finv[i - 1] * inv[i] % MOD;
//   }
// }

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

void solve() {
  int N, K;
  cin >> N >> K;
  vi A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vll fac(N + 1, 1), finv(N + 1, 1);
  cmb_init(N, fac, finv);
  sort(all(A));
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum -= (ll)A[i] * cmb(N - i - 1, K - 1, fac, finv) % MOD;
    sum += (ll)A[i] * cmb(i, K - 1, fac, finv) % MOD;
    sum %= MOD;
  }
  cout << sum << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
int main()
{
  char s[3];
  int j;
  scanf("%s",s);
  if(s[0]=='R' && s[1]=='R' && s[2]=='R'){
    j=3;
  }
  else if(s[0]=='R' && s[1]=='R' && s[2]=='S'){
    j=2;
  }
  else if(s[0]=='R' && s[1]=='S' && s[2]=='R'){
    j=1;
  }
  else if(s[0]=='R' && s[1]=='S' && s[2]=='S'){
    j=1;
  }
  else if(s[0]=='S' && s[1]=='R' && s[2]=='R'){
    j=2;
  }
  else if(s[0]=='S' && s[1]=='S' && s[2]=='R'){
    j=1;
  }
  else if(s[0]=='S' && s[1]=='R' && s[2]=='S'){
    j=1;
  }
  else{
    j=0;
  }
  printf("%d",j);
  return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}




int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w;
	cin >>h  >>w;
	vector<string> ba(h);
	rep(i, h) cin >>ba[i];
	const int dr[]={0,1,0,-1,0};
	const int INF= 1<<28;
	auto bfs = [&](int sy, int sx) {
		int ans = 0;
		vector<VI> dd(h, VI(w, INF));
		queue< pair<int, int> > que;
		que.emplace(sy, sx); dd[sy][sx]=0;
		while(!que.empty()){
			int cy,cx; tie(cy,cx) = que.front();
			que.pop();
			rep(i,4){
				int ny=cy+dr[i], nx=cx+dr[i+1];
				if(ny<0 || ny>=h || nx<0 || nx>w) continue;
				if(dd[ny][nx] == INF && ba[ny][nx] =='.'){
					que.emplace(ny, nx);
					dd[ny][nx] = dd[cy][cx] + 1;
				}
			}
		}
		rep(i, h) rep(j , w) if(dd[i][j] < INF && ba[i][j] =='.'){
			if(i==sy && j==sx) continue;
			ans = max(ans, dd[i][j]);
		}
		return ans;
	};
	int ans = 0;
	rep(y1,h) rep(x1,w){
		if(ba[y1][x1]=='#') continue;
		int rc = bfs(y1,x1);
		ans = max(ans, rc);
	}
	cout << ans <<"\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll dp[100][2];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; ll k; cin >> n >> k;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<100;i++){
		dp[i][0]=dp[i][1]=-1;
	}
	dp[45][0]=0;
	for(int d=44;d>=0;d--){
		ll mask=1LL<<d;
		int num=0;
		for(int i=0;i<n;i++){
			if(a[i]&mask)num++;
		}
		if(dp[d+1][1]>=0){
			dp[d][1]=max(dp[d][1],dp[d+1][1]+mask*max(num,n-num));
		}
		if(dp[d+1][0]>=0){
			if(k&(1LL<<d)){
				dp[d][1]=max(dp[d][1],dp[d+1][0]+mask*num);
				dp[d][0]=max(dp[d][0],dp[d+1][0]+mask*(n-num));
			}
			else{
				dp[d][0]=max(dp[d][0],dp[d+1][0]+mask*num);
			}
		}
	}
	cout << max(dp[0][0],dp[0][1]) << endl;
}

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


int main() {
	int N;
	int T;
	int c;
	int t;
	cin >> N;
	cin >> T;
	vector<int>vc;
	rep(i, N) {
		cin >> c;
		cin >> t;
		if (t <= T) {
			vc.push_back(c);
		}
	}
	if (vc.size() == 0) {
		print("TLE");
	}
	else {
		vector<int>::iterator minIt = min_element(vc.begin(), vc.end());
		size_t minIndex = distance(vc.begin(), minIt);
		printf("%d", vc[minIndex]);
	}
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a,b;
	scanf("%d",&a);
	for(int i=1;;i++)
	{
		b=a%10;
		if(b==9||a==9)
			break;
		else
		{
			if(b<10&&a<10)
			{
				printf("No");
				return 0;
			}
			else
				a=a/10;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    return x*y/(T)GCD(x,y);
}
int main(){
    int n; cin >> n;
    set<long long> st;
    vector<int> v;
    for(int i = 0; i < n; i++){
        long long a; cin >> a;
        v.push_back(a);
    }
    v.erase( unique(v.begin(), v.end()), v.end());
    for(long long i = 0; i < v.size()-1; i++){
        cout << v[i] << " ";
    }
    cout << v[v.size()-1] << endl;
}
  




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

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

    int i = 0, counter = 0;
    //N回ボタン押下して不可ならループしている（少しオーバーランするかもしれないがオーダーは同じ）
    while(counter < N && i != 1){
        counter++;
        i = a[i] - 1;
    }
    if(counter == N) counter = -1;

    cout << counter << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> num(N);
  for(int i=0;i<N;i++){
   cin >> num[i];
  }
  
  sort(num.begin(),num.end());
  
  cout << num[N-1]-num[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}


void solve(void){
    int N;
    cin >> N;
    vector <int> u(N), d(N);
    rep(N, i) {
        cin >> u[i];
    }
    rep(N, i) {
        cin >> d[i];
    }
    rep(N-1, i) {
        u[i+1] += u[i];
    }
    d[0] += u[0];
    rep(N-1, i) {
        d[i+1] = d[i+1] + max(d[i], u[i+1]);
    }
    cout << d[N-1] << endl;

}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <fstream>

using namespace std;

#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 1000;
int v[5 + nmax];
int c[5 + nmax];

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i <= n;i++)
    cin >> v[i];
  for(int i = 1;i <= n;i++)
    cin >> c[i];
  int result = 0;
  for(int i = 1;i <= n; i++)
    if(c[i] <= v[i])
      result += v[i] - c[i];
  cout << result;

  return 0;
}


Measured memory_bytes: 256
cards = [[False for i in range(13)] for j in range(4)]
pattern = ["S","H","C","D"]
n = int(input())
for i in range(n):
    line = input().split()
    ch = line[0]
    num = int(line[1])
    cards[pattern.index(ch)][num-1] = True
for j in range(4):
    for i in range(13):
        if cards[j][i] == False:
            print(pattern[j],i+1)


Measured memory_bytes: 5600
a, b = input().rstrip().split()
a = int(a)
b = int(b)

place = b
deff = a - 1

below_pls = place - deff
above_pls = place + deff
if below_pls < -1000000:
    below_pls = -1000000
if above_pls > 1000000:
    above_pls = 1000000

lst = list(range(below_pls, above_pls + 1))
print(' '.join(map(str, lst)))

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin >> n;
	while (n--) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (a < b)
			for (int i = a; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
		else if (a <= 5)
			for (int i = a; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
		else {
			for (int i = a; i <= 9; i++) printf("%d ", i);
			if (b <= 5)
				for (int i = 5; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
			else {
				for (int i = 5; i > 0; i--) printf("%d ", i);
				for (int i = 0; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
			}
		}
	}
	return 0;
}

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

int main() {

    int a, b;
    cin >> a >> b;
    int now = a;
    int count = 1; 
    while(now < b){
        now += a - 1;
        count++;
    }
	if(b == 1) count = 0;
    cout << count << endl;

}

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back
#define int ll

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;
const int N = 1000007, inf = 0x3f3f3f3f;

struct segtree {
	vector<int> seg;
	int n;
	segtree(){}
	segtree(int n) {
		seg.assign(n + n + 7, -2 * inf);
		this->n = n;
	}

	int query(int l, int r) {
		int ans = -2 * inf;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if(l&1) ans = max(ans, seg[l++]);
			if(r&1) ans = max(ans, seg[--r]);
		}
		return ans;
	}

	void update(int p, int val) {
		p += n;
		for(seg[p] = max(seg[p], val); p > 1; p >>= 1) {
			seg[p >> 1] = max(seg[p], seg[p ^ 1]);
		}
	}
};
int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);


	int n; cin >> n;
	vector<ii> pts;
	vector<int> Y;
	for(int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		pts.eb(x, y);
		Y.pb(y);
	}

	sort(Y.begin(), Y.end());
	Y.erase(unique(Y.begin(), Y.end()), Y.end());

	sort(pts.begin(), pts.end());

	segtree up, down;
	up = segtree(n);
	down = segtree(n);

	int ans = -2 * inf;
	// 2 e 4 quadrantes
	for(int i = 0; i < n; ++i) {
		int x, y; tie(x, y) = pts[i];
		int j = lower_bound(Y.begin(), Y.end(), y) - Y.begin();

		// quad 2
		ans = max(ans, up.query(j, n) + x - y);

		// quad 3
		ans = max(ans, down.query(0, j) + x + y);

		// coloca o ponto
		up.update(j, -x + y);
		down.update(j, -x - y);
	}

	up = segtree(n);
	down = segtree(n);
	for(int i = n-1; i >= 0; --i) {
		int x, y; tie(x, y) = pts[i];
		int j = lower_bound(Y.begin(), Y.end(), y) - Y.begin();

		// quad 2
		ans = max(ans, up.query(j, n) - x - y);

		// quad 3
		ans = max(ans, down.query(0, j) - x + y);

		// coloca o ponto
		up.update(j, x + y);
		down.update(j, x - y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 19348
import java.util.*;

public class Main {
    
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int max = 0;
		int count = 0;
		for (char c : arr) {
		    if (c == '1') {
		        count++;
		        max = Math.max(max, count);
		    } else {
		        count = 0;
		    }
		}
		if (max >= m) {
		    System.out.println(-1);
		    return;
		}
		ArrayDeque<Integer> stack = new ArrayDeque<>();
		int idx = n;
		while (idx > 0) {
		    int next = Math.max(idx - m, 0);
		    while (arr[next] == '1') {
		        next++;
		    }
		    stack.push(idx - next);
		    idx = next;
		}
		boolean isFirst = true;
		StringBuilder sb = new StringBuilder();
		while(stack.size() > 0) {
		    if (!isFirst) {
		        sb.append(" ");
		    }
		    sb.append(stack.pop());
		    isFirst = false;
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 46244
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int last = 0;
        int cur = 0;
        int max = 0;
        for (int i = 0; i < h.Length; i++)
        {
            if (last >= h[i])
            {
                cur++;
                max = Max(max, cur);
            }
            else
            {
                cur = 0;
            }
            last = h[i];
        }
        Console.WriteLine(max);
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


Measured memory_bytes: 24156
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

struct team{
	string name;
	int score;
	int num;
	team(string n, int s, int nu):name(n), score(s), num(nu){}
	bool operator<(const team &r)const{
		if(score == r.score) return num > r.num;
		return score < r.score;
	}
};

int main(){
	int n;
	int dataset = 0;
	while(cin >> n, n){
		if(dataset++)cout << endl;
		vector<team> v;
		rep(i, n){
			string name;
			int w, l, d;
			cin >> name >> w >> l >> d;
			v.push_back(team(name, w*3+d, i));
		}
		sort(rev(v));
		rep(i, n){
			cout << v[i].name << ',' << v[i].score << endl; 
		}
	}

	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
vector<int> vv[200005];
bool seen[200005];
queue<int> q;
int from[200005];
void bfs(vector<int> &dist){
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(int node: vv[v]){
      if(dist[node] != -1) continue;
      from[node] = v + 1;
      dist[node] = dist[v] + 1;
      q.push(node);
    }
  }
}
int main(){
  int n, m; cin >> n >> m;
  for(int i = 0, x, y; i < m; ++i){
    cin >> x >> y;
    x--; y--;
    vv[x].push_back(y);
    vv[y].push_back(x);
  }
  vector<int> dist(n, -1);
  dist[0] = 0;
  bfs(dist);
  bool flag = true;
  for(int i = 1; i < n; ++i){
    if(dist[i] - 1 == dist[from[i] - 1]) continue;
    flag = false;
    break;
  }
  if(flag){
    cout << "Yes" << endl;
    for(int i = 1; i < n; ++i) cout << from[i] << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 12996
a = list()
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
k = int(input())

result = True
for i in range(len(a)):
    for j in range(i+1, len(a)):
        # print(i, j)
        if a[j] - a[i] > k:
            result = False

if result:
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 3064
n,a,b,c = map(int,input().split())
L = []
for i in range(n):
    L.append(int(input()))
import itertools
ans = 10**9
tmp = 0
for perm in itertools.permutations(range(n),3):
    ua,ub,uc = perm
    la,lb,lc = L[ua],L[ub],L[uc]
    for use in itertools.product([0,1,2,-1] ,repeat=n-3):
        idx = 0
        tmp = 0
        ls = [la,lb,lc]
        for i,l in enumerate(L):
            if i== ua or  i== ub or i== uc:
                continue
            else:
                if use[idx]>-1:
                    ls[use[idx]] +=l
                    tmp+=10
            idx+=1
        tmp = tmp + abs(ls[0] -a) +abs(ls[1] -b)+abs(ls[2] -c)
        ans=min(ans,tmp)
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {

    int INF = Integer.MAX_VALUE;
    int N;
    int[] A;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int P = sc.nextInt();
        A = new int[N];
        boolean c = true;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (A[i] % 2 == 1) {
                c = false;
            }
        }
        if (P == 0) {
            System.out.println(c ? (long) Math.pow(2, N) : (long) Math.pow(2, N - 1));
        } else {
            System.out.println(c ? "0" : (long)Math.pow(2, N - 1));
        }

    }
}


Measured memory_bytes: 22868