akhauriyash/Code-Regression huggingface dataset:
// Ivan Carvalho
// Problem Z - Educational Dynamic Programming Contest - AtCoder
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 2*1e5 + 10;

struct line{

	ll a,b;

	line(ll _a,ll _b){
		a = _a;
		b = _b;
	}

	ll get(ll x){return a*x + b;}

	ld get(ld x){return a*x + b;}

};

ld inter(line l1,line l2){

	return -(l1.b - l2.b)/ld(l1.a - l2.a);

}

bool useless(line l1,line l2,line l3){
	return inter(l1,l3) < inter(l2,l1);
}

vector<line> CHT;
ll dp[MAXN],h[MAXN],C;
int chtPtr,N;

void add(line l){

	//CHT.push_back(l);
	//return;

	while(CHT.size() >= 2 && useless(CHT[CHT.size()-2],CHT.back(),l) ){
		CHT.pop_back();
	}

	CHT.push_back(l);

}

ll query(ll x){

	//ll best = CHT[0].get(x);
	//for(line l : CHT) best = min(best, l.get(x) );
	//return best;

	if(chtPtr >= CHT.size()) chtPtr = CHT.size() - 1;

	while(chtPtr + 1 < CHT.size() && CHT[chtPtr].get(x) > CHT[chtPtr+1].get(x) ){
		chtPtr++;
	}

	return CHT[chtPtr].get(x);

}

int main(){

	scanf("%d %lld",&N,&C);

	for(int i = 1;i<=N;i++){
		scanf("%lld",&h[i]);
	}

	add(line(-2*h[1], h[1]*h[1] + C ));

	for(int i = 2;i<=N;i++){

		dp[i] = query(h[i]) + h[i]*h[i];
		add(line(-2*h[i], h[i]*h[i] + dp[i] + C ));

	}

	printf("%lld\n",dp[N]);

	return 0;

}

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

int main()
{
    string s;
    cin >> s;
    int ex = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'o')
        {
            ex++;
        }
    }
    cout << 700 + 100 * ex << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1LL << 30;

// dp[j] := j円を作るときのコインの枚数
int dp[50505];
    
int main() {
    int n, m;
    cin >> n >> m;
    vector< int > c(m);
    for (int i=0; i<m; ++i) cin >> c[i];
    
    for (int i=0; i<22; ++i) fill_n(dp, 50505, INF);
    
    dp[0] = 0;
    
    for (int i=0; i<m; ++i) {
        for (int j=0; j<=n; ++j) {
            if (j >= c[i]) {
                dp[j] = min(dp[j], dp[j-c[i]] + 1);
            }
        }
    }

    int ans = dp[n];
    cout << ans << endl;
    
    return 0;
}


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

int main(){
	int n, p, sum = 0, maks = 0;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> p;
		maks = max(p, maks);
		sum += p;
	}

	sum -= maks;
	sum += (maks/2);
	cout << sum << endl;

	return 0;
}

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

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

    int i=1, ans;
    while(1){
        ans=1000*i - n;
        i++;

        if(ans>=0){
            break;
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
from math import ceil
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

a, b, c, d = map(int, input().split())
e = lcm(c, d)
nc = b//c-a//c
if a%c==0:
    nc += 1

nd = b//d-a//d
if a%d==0:
    nd += 1

ne = b//e-a//e
if a%e==0:
    ne += 1

print(b-a+1-nc-nd+ne)

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

typedef long long int64;

int main()
{
  string S;
  cin >> S;
  int N = S.size();
  
  int64 ans = 0ll, tmp;
  int last = 0;
  for (int bit = 0; bit < (1 << (N - 1)); ++bit) {
    last = 0;
    for (int i = 0; i < N - 1; ++i) {
      if ((bit >> i) & 1) {
        ans += (int64)stoll(S.substr(last, i - last + 1).c_str());
	last = i + 1;
      }
    }
    ans += (int64)stoll(S.substr(last, N - last).c_str());
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
    int64_t h;
    cin >> h;
    int i=0;
    while(1){
        if(pow(2,i)<=h && pow(2,i+1)>h){
            break;
        }
        i++;
    }
    cout << static_cast<long long int>( pow(2,i+1) - 1) <<endl;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

//Princess in Danger
public class Main{

	int[][] dist, wf;
	int INF = 1<<29, P = 107;
	int N, M, L, K, A, H;
	
	class E{
		int t, d;
		public E(int t, int d) {
			this.t = t;
			this.d = d;
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			N = sc.nextInt(); M = sc.nextInt(); L = sc.nextInt(); K = sc.nextInt(); A = sc.nextInt(); H = sc.nextInt();
			if((N|M|L|K|A|H)==0)break;
			boolean[] ice = new boolean[N];
			ice[A] = ice[H] = true;
			while(L--!=0)ice[sc.nextInt()] = true;
			List<E>[] es = new ArrayList[N];
			for(int i=0;i<N;i++)es[i]=new ArrayList<E>();
			wf = new int[N][N];
			for(int[]a:wf)Arrays.fill(a, INF);
			while(K--!=0){
				int s = sc.nextInt(), t = sc.nextInt(), d = sc.nextInt();
				wf[s][t] = wf[t][s] = d;
				es[s].add(new E(t, d)); es[t].add(new E(s, d));
			}
			for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)wf[i][j]=Math.min(wf[i][j], wf[i][k]+wf[k][j]);
			dist = new int[N][M+1];
			for(int[]a:dist)Arrays.fill(a, INF);
			for(int i=0;i<=M;i++)dist[A][i] = 0;
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(N, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					int a = o1/P, b = o1%P, c = o2/P, d = o2%P;
					int v1 = dist[a][b]+wf[a][H], v2 = dist[c][d]+wf[c][H];
					return v1!=v2?v1-v2:wf[a][H]-wf[c][H];
//					return (dist[a][b]+wf[a][H])-(dist[c][d]+wf[c][H]);
				}
			});
			q.add(A*P+M);
			int res = INF;
			while(!q.isEmpty()){
				int v = q.poll();
				int pos = v/P, m = v%P;
				if(pos==H){
					res = dist[pos][m]; break;
				}
				for(E e:es[pos]){
					for(int t=0;t+m<=M;t++){
						if(t>0&&!ice[pos])break;
						int nm = t+m-e.d;
						if(nm<0)continue;
						int w = dist[pos][m]+t+e.d;
						if(w<dist[e.t][nm]){
							q.remove(e.t*P+nm); dist[e.t][nm] = w;
							int r = nm-1;
							while(r>=0&&w<=dist[e.t][r]){
								q.remove(e.t*P+r); dist[e.t][r] = w; r--;
							}
							q.add(e.t*P+nm);
						}
					}
				}
				
			}
			System.out.println(res==INF?"Help!":res);
		}
	}

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

Measured memory_bytes: 16000
// B.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
	string a, b;
	cin >> a >> b;
	if (a == b) {
		cout << "EQUAL" << endl;
	} else if (a.length() > b.length()) {
		cout << "GREATER" << endl;
	} else if (a.length() < b.length()) {
		cout << "LESS" << endl;
	} else {
		cout << (a > b ? "GREATER" : "LESS") << endl;
	}
	return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int x;
    cin >> x;
    ll ans = 0;
    ans += (ll)x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int arr[200000];
set<int> s;

int main()
{
	int n, k;
	int ans = 1;
	int cnt = 0;

	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);

	int now = 1;
	for (int i = 1; i < n; i++)
	{
		if (arr[i] > arr[i - 1])
			now++;
		else
		{
			if (now >= k)
				cnt++;
			now = 1;
		}
	}

	if (now >= k)
		cnt++;

	if (n == k)
	{
		printf("1");
		return 0;
	}

	for (int i = 0; i < k; i++)
		s.insert(arr[i]);

	for (int i = k; i < n; i++)
	{
		if (arr[i - k] != *s.begin() || arr[i] < *s.rbegin())
			ans++;

		s.erase(arr[i - k]);
		s.insert(arr[i]);
	}

	if (cnt == 0)
		printf("%d", ans);
	else
		printf("%d", ans - cnt + 1);

	return 0;
}

Measured memory_bytes: 10368
a, b = map(int, input().split())


def gcd(x, y):
    if(y == 0):
        return x
    else:
        return gcd(y, x%y)

A = list(input().split())
B = []
ans = abs(int(A[0])-b)
for i in A:
    aa = abs(int(i) - b)
    ans = gcd(ans, aa)

print(ans)

Measured memory_bytes: 11096
N = int(input())
graph = [[] for _ in range(N+1)]
AB = []

for _ in range(N-1):
  a, b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)
  AB.append((a, b))

root = 1
parent = [0] * (N+1)
order = []
stack = [root]

while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

color = [-1] * (N+1)
K = -1
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue
        if c == ng:
            c += 1
        K = max(c, K)
        color[y] = c
        c += 1

ans = []

for a, b in AB:
    if parent[a] == b:
        ans.append(color[a])
    else:
        ans.append(color[b])

print(K)
for i in ans:
  print(i)


Measured memory_bytes: 103724
import itertools

N = int(input())
L = map(int, input().split())

C = list(itertools.combinations(L,3))

ans = 0
for a, b, c in C:
    if a < b + c and b < a + c and c < b + a and a != b and b != c and a != c:
        ans += 1
print(ans)

Measured memory_bytes: 20616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    ll maxx = max(A, max(B, C));
    vector<ll> dif(3);
    dif[0] = maxx - A;
    dif[1] = maxx - B;
    dif[2] = maxx - C;
    sort(dif.begin(), dif.end(), greater<ll>());
    ll cnt = 0;
    cnt += dif[1];
    cnt += (dif[0] - dif[1]) / 2;
    vector<ll> ch(3);
    ch[0] = A;
    ch[1] = B; 
    ch[2] = C;
    sort(ch.begin(), ch.end());
    if(ch[0]%2!=ch[1]%2){
      cout << cnt + 2 << endl;
    }
    else cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void iterate(string str)
{
    unsigned long lNum = 0;
    for (size_t i = 0; i < str.length(); i++)
    {
        if (str[i] != 'R')
        {
            lNum = i;
            break;
        }
    }

    unsigned long rNum = str.length() - lNum;

    for (size_t i = 0; i < lNum - 1; i++)
    {
        cout << "0 ";
    }

    long lr = lNum / 2;
    long rl = rNum / 2;
    long ll = lNum - lr;
    long rr = rNum - rl;

    //cout << "lr: " << lr << ", rl: " << rl << endl;

    cout << ll + rl << ' ' << rr + lr;

    for (size_t i = 0; i < rNum - 1; i++)
    {
        cout << " 0";
    }

    //cout << lNum;
}

int main()
{
    string s;
    cin >> s;
    long strLength = s.length();

    vector<string> parts;

    int b = 0;
    for (size_t i = 1; i < strLength; i++)
    {
        if (s[i - 1] == 'L' && s[i] == 'R')
        {
            parts.push_back(s.substr(b, i - b));
            b = i;
        }
    }

    if (b != strLength)
    {
        parts.push_back(s.substr(b));
    }

    for (vector<string>::iterator i = parts.begin(); i < parts.end(); i++)
    {
        if (i != parts.begin())
        {
            cout << ' ';
        }
        // cout << *i << endl;
        iterate(*i);
    }
    cout << endl;
}

Measured memory_bytes: 3320
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rg register
#define usn unsigned
#define llint long long
using namespace std;
const int N=1008611;

struct ios{
	template <typename _tp>
	inline ios operator >> (_tp &x){
		x = 0;int f = 1;char c = getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c<='9'&&c>='0';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x){
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x) ++dgt,s[dgt] = x%10+'0',x/=10;
		while(dgt) putchar(s[dgt]),--dgt;
		return *this;
	}
	inline ios operator << (char x){
		putchar(x);
		return *this;
	}
}io;

char s[N];
int len,ans=1,dbd[N];

int main()
{
	scanf("%s",s+1),len = strlen(s+1);
	for(rg int i=2;i<=len;++i){
		if(s[i]==s[i-1]&&i<=len-2){
			ans += 2,i += 2;
		}
		else if(s[i]==s[i-1]&&i<=len-1){
			++ans,++i;
		}
		else if(s[i]!=s[i-1]){
			++ans;
		}
	}
	io << ans << '\n';
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}

class Seg_Tree{//gcd
public:
	vector<int> dat;
	int n;
	void initsize(int n0){
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=1;
				break;
			}
			k*=2;
		}
	}

	//to sg[i]  x
	void update(int i,int x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = gcd(dat[i*2+1],dat[i*2+2]);
		}
	}

	//gcd[a,b)
	int query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return dat[a+n-1];
		if(a<=l && r<=b)return dat[k];
		else{
			int vl = query0(a,b,k*2+1,l,(l+r)/2);
			int vr = query0(a,b,k*2+2,(l+r)/2,r);
			return gcd(vl,vr);
		}
	}

	//return gcd [a,b)
	int query(int a,int b){
		return query0(a,b,0,0,n);
	}
};

int main(){
	int N;
	cin >> N;
	Seg_Tree sg;
	sg.initsize(N);
	for(int i=0;i<N;i++){
		int k;
		cin >> k;
		sg.update(i,k);
	}

	int ans = max(sg.query(1,N),sg.query(0,N-1));
	for(int i=1;i<N-1;i++){
		int p = gcd(sg.query(0,i),sg.query(i+1,N));
		ans = max(ans,p);
	}

	cout << ans << endl;
}


Measured memory_bytes: 1280
from bisect import bisect_left as bl 
from copy import deepcopy as dc
from time import time
from random import randint
start=time()
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for _ in range(D)]

T=[randint(1,26) for _ in range(D)]

for i in range(D):
    best=1
    bestscore=0
    for j in range(26):
        if S[i][j]>bestscore:
            best=j+1
            bestscore=S[i][j]
    T[i]=best


last=[[0] for _ in range(26)]
score=[0]*D
for i in range(D):
    contest=T[i]-1
    if i == 0:
        score[i]=S[i][contest]
    else:
        score[i]=score[i-1]+S[i][contest]
    last[contest].append(i+1)
    for j in range(26):
        blank=i+1-last[j][-1]
        score[i]-=blank*C[j]

def research(day,query,border):
    global last,T,score
    T2=T[:]
    last2=[[0] for _ in range(26)]
    for i in range(D):
        contest=T[i]-1
        last2[contest].append(i+1)
    score2=score[:]
    T2[day-1]=query+1
    for i in range(26):
        ind=bl(last2[i],day)
        last2[i]=last2[i][:ind]

    for i in range(day-1,D):
        contest=T2[i]-1
        if i == 0:
            score2[i]=S[i][contest]
        else:
            score2[i]=score2[i-1]+S[i][contest]
        last2[contest].append(i+1)
        for j in range(26):
            blank=i+1-last2[j][-1]
            score2[i]-=blank*C[j]
    if score2[-1]>=border:
        T=T2[:]
        last=dc(last2)
        score=score2[:]
    return

while time()-start<=1.5:
    research(randint(1,D),randint(0,25),score[-1])

for i in range(D):
    print(T[i])


Measured memory_bytes: 9904
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	string a,b;
    cin >> a >> b;
    if(a.size()!=b.size()) cout << (a.size()>b.size()?"GREATER\n":"LESS\n");
    else if(a==b) cout << "EQUAL\n";
    else cout << (a>b?"GREATER\n":"LESS\n");
	return 0;
}


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

using namespace std;
const int N = 5e3 + 10;
typedef long long ll;

ll a , b , f[N];
int n , p[N];
int main(){
	scanf("%d%lld%lld",&n,&a,&b);
	for (int i = 1;i <= n;i++){
		scanf("%d",p + i);
	}
	p[n + 1] = n + 1;
	memset(f , 0x3f , sizeof f);
	f[0] = 0;
	
	for (int i = 1;i <= n + 1;i++){
		int g = 0;
		for (int j = i - 1;j >= 0;j--){
			if (p[j] > p[i]){
				g++;
			}else{
				f[i] = min(f[i] , f[j] + 1ll * g * a + 1ll * (i - j - 1 - g) * b);
			}
		}
	}
	cout<<f[n + 1];
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      String num = sc.next();
      if(num.length() == 1 && Character.getNumericValue(num.charAt(0)) == 0){
        break;
      }
      else{
        int sum = 0;
        for(int i = 0; i < num.length(); i++){
          sum += Character.getNumericValue(num.charAt(i));
        }
        System.out.printf("%d\n", sum);
      }
    }
  }
}


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

int main(){
    vector<int> data(3);
    int sum=0;
    bool ok=false;
    for (int i=0; i<3 ;i++) {
        cin>>data[i];
        sum+=data[i];
    }
    for (int i=0; i<3; i++){
        long long ans;
        ans = sum-data[i];
        if (data[i]==ans) ok = true;
    }
    if (ok) cout<<"Yes"<<endl;
    else if (!ok) cout<<"No"<<endl;
}


Measured memory_bytes: 3572
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    std::getline(std::cin, s);
    for(size_t i = 0; i < s.size(); ++i){
        char c = s[i];
        if(std::isupper(c)){
            c = std::tolower(c);
        }else if(std::islower(c)){
            c = std::toupper(c);
        }
        std::cout << c;
    }
    std::cout << std::endl; 
    return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>

int main(){
  int N, X;
  scanf("%d %d", &N, &X);
  int i;
  int L, D=0;
  for(i=0; i<=N; i++){
    if(i>0){
      D+=L;
      if(D>X) break;
    }
    scanf("%d", &L);
  }
  printf("%d", i);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(s: str):
    G = 0
    P = 0
    res = 0
    for i, ss in enumerate(s):
        if ss == 'p':
            if P < G:
                P += 1
            else:
                res -= 1
                G += 1
        else:
            if P < G:
                res += 1
                P += 1
            else:
                G += 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5432
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
 
void main() {
    auto N = readln.chomp.to!long;
    auto x = readln.split.to!(long[]);
    long cnt = 0;
    foreach (i; 0..N) {
        if (x[i] == i+1) {
            cnt++;
            swap(x[i], x[i+1]);
        }
    }
    writeln(cnt);
}


Measured memory_bytes: 4284
#include <stdio.h>
#include <stdlib.h>
#define N 3
#define N1 4
#define N2 9
#define N3 100
int puz[N][N];
int tmp[N][N];
int dx[N1]={0,1,0,-1};
int dy[N1]={1,0,-1,0};
void empty(int x[],int y[]) {
  int i,j;
  for(i=0;i<N;i++) {
    for(j=0;j<N;j++) {
      if(!puz[i][j]) {
        *x = j;
        *y = i;
        return;
      }
    }
  }
}
void swap(int a[],int b[]){
  int tmp;
  tmp=*a;
  *a=*b;
  *b=tmp;
}
int cal(){
  int i,a,sum=0;
  for(i=0; i<N2; i++){
    a = puz[i/N][i%N];
    if(a){
      a--;
      sum+=abs((i/N)-(a/N))+abs((i%N)-(a%N));
    }
  }
  return sum;
  }
int dfs(int x,int y,int p,int dep,const int lim){
  int i,h,nx,ny,res;
  h=cal();
  if(h==0) return dep;
  if(dep+h>lim) return -1;
  for(i=0;i<N1;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    if(~p && i==(p+2)%N2) continue;
    if(!(0<=nx && nx<N && 0<=ny && ny<N)) continue;
    swap(&puz[y][x],&puz[ny][nx]);
    res = dfs(nx,ny,i,dep+1,lim);
    if(~res) return res;
    swap(&puz[y][x],&puz[ny][nx]);
  }
  return -1;
}
int main() {
  int i,j,ans,x,y,l;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++) scanf("%d",&puz[i][j]);
  }
  empty(&x,&y);
  for(l=0;l<N3;l++){
    for(i=0;i<N;i++){
      for(j=0;j<N;j++) tmp[i][j] = puz[i][j];
    }
    ans=dfs(x,y,-1,0,l);
    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }
    for(i=0;i<N;i++){
      for(j=0;j<N;j++) puz[i][j] = tmp[i][j];
    }
     ans = -1;
    if(l==N3-1) printf("%d\n",ans);
  }
  return 0;
}



Measured memory_bytes: 2112
n, m  = gets.strip.split.map(&:to_i)
as = gets.strip.split.map(&:to_i)

matched_numbers = [2,5,5,4,5,6,3,7,6].map.with_index {|e, i| [e, i+1] }.select {|_, i| 
as.include?(i) }.sort_by(&:last).to_h

#p matched_numbers

dp = Array.new(n+1)

(n+1).times do |i|
  tmp = matched_numbers[i].to_i.to_s
  matched_numbers.each do |cost, number|
    next if dp[i-cost].to_i.zero?

    exists = dp[i-cost]
    current_number = number.to_s
    current = exists > current_number ? (exists+current_number) : (current_number+exists)

    tmp = current if tmp.length < current.length || (tmp.length == current.length && tmp < current)
  end
  dp[i]=tmp
end

#p dp
p dp[n].to_i



Measured memory_bytes: 51068
#include <stdio.h>

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int c1,c2,c3;
  c1=a+b;
  c2=a-b;
  c3=a*b;
  if(c1<c2){
    if(c2<c3){
      printf("%d",c3);
    }else{
      printf("%d",c2);
    }
  }else{
    if(c1<c3){
       printf("%d",c3);
    }else{
      printf("%d",c1);
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int >

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); 
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int ans = 0;
    for (int i = 0; i <= min(n , k); i++) {
        for (int j = 0; j + i <= min(n , k); j++) {
            vector<int> jewels;
            int sum = 0;
            for (int ind = 0; ind < i; ind++) {
                if (v[ind] < 0)
                    jewels.push_back(v[ind]);
                sum += v[ind];
            }
            for (int ind = n - 1; ind > n - 1 - j; ind--) {
                if (v[ind] < 0)
                    jewels.push_back(v[ind]);
                sum += v[ind];
            }
            if (!jewels.empty()) {
                sort(jewels.begin(), jewels.end());
                for (int op = 0; op < min(k - (i + j), sz(jewels)); op++) {
                    sum -= jewels[op];
                }
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << "\n";
}

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

int main(){
    long long x; cin>>x;
    if(x%11==0){
        cout<<x/11*2<<endl;
    }else if(x%11<=6){
        cout<<x/11*2+1<<endl;
    }else{
        cout<<x/11*2+2<<endl;
    }
}


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

int n;
int ans;
void dfs(int x, int depth) {
    if(depth == 0) {
        if(x <= n) {
            map<int, bool> mp;
            while (x) {
                for (int i = 3; i < 8; i++) {
                    if(x%10 == i) {
                        mp[i] = 1;
                        break;
                    }
                }
                x /= 10;
            }
            int cnt = 0;
            for (auto p : mp) {
                cnt += p.second;
            }
            if(cnt == 3) {
                ans++;
            }
        }
        return;
    }

    x *= 10;
    for (int i = 3; i < 8; i += 2) {
        dfs(x + i, depth - 1);
    }
}
void solve () {
    cin >> n;
    string s = to_string(n);
    int sz = (int) s.size();
    for (int j = 2; j < sz; j++) {
        for (int i = 3; i < 8; i+= 2) {
           dfs(i, j);
        }
    }
    cout << ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const long long mod = 1e9 + 7;
const ll INF = 1000000000000000;

int main(){
  int N;
  ll  W;
  cin >> N >> W;
  vector<ll> w(N);
  vector<int> v(N);
  rep(i, N){
    cin >> v[i] >> w[i];
  }
  vector<vector<ll>> dp(N + 1, vector<ll>(100001, INF));
  dp[0][0] = 0;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < 100001; j++){
      if(j - v[i-1] >= 0){
        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i-1]] + w[i-1]);
      }else {
        dp[i][j] = min(dp[i][j], dp[i - 1][j]);
      }
    }
  }
  int ans = 100000;
  while(dp[N][ans] > W)ans--;
  cout << ans << endl;
}


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

int k;
string s;

int main()
{
	ios::sync_with_stdio(0);
	cin >> k >> s;
	int len = s.size();
	if(k >= len) cout << s;
	else cout << s.substr(0, k) << "...";
//	system("pause");
	return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>

int main(){
  char s[100000];
  int i,j,f,l,r;
  
  scanf("%s",s);
  
  for(i=0;s[i]!='\0';i++){
    f = i;
    while(s[i+1]!='L'){
      i++;
	  printf("0 ");
    }
	l = i+1;
    while(s[i+1]=='L'){
      i++;
    }
	r = (l-f)/2 + (i-l)/2 + 1;
	printf("%d ", (i-f+1) - r);
	printf("%d ", r);
	for(j=0;j<i-l;j++){
		printf("0 ");
	}
  }
  return 0;
}

Measured memory_bytes: 512
#[derive(Clone, Copy, PartialEq)]
enum Bamboo {
    A, B, C, None,
}

fn abs_sub(x: usize, y: usize) -> usize {
    std::cmp::max(x, y) - std::cmp::min(x, y)
}

fn calc(a: usize, b: usize, c: usize, ls: &Vec<usize>, bamboos: &Vec<Bamboo>) -> usize {
    let mut alen: usize = 0;
    let mut blen: usize = 0;
    let mut clen: usize = 0;
    let mut concat_mp: usize = 0;

    for (i, b) in bamboos.iter().enumerate() {
        match *b {
            Bamboo::A => {concat_mp += if alen == 0 {0} else {10}; alen += ls[i]},
            Bamboo::B => {concat_mp += if blen == 0 {0} else {10}; blen += ls[i]},
            Bamboo::C => {concat_mp += if clen == 0 {0} else {10}; clen += ls[i]},
            _ => {},
        }
    }
    abs_sub(a, alen) + abs_sub(b, blen) + abs_sub(c, clen) + concat_mp
}

fn dfs(n: usize, a: usize, b: usize, c: usize, ls: &Vec<usize>, depth: usize, mut bamboos: &mut Vec<Bamboo>) -> Option<usize> {
    if depth < n {
        let mut min: Option<usize> = None;
        for i in [Bamboo::A, Bamboo::B, Bamboo::C, Bamboo::None].iter() {
            bamboos[depth] = *i;
            if let Some(v) = dfs(n, a, b, c, &ls, depth+1, &mut bamboos) {
                if min.is_none() {
                    min = Some(v);
                }
                else {
                    min = Some(std::cmp::min(min.unwrap(), v));
                }
            }
        }
        min
    }
    else {
        if bamboos.contains(&Bamboo::A) &&
           bamboos.contains(&Bamboo::B) &&
           bamboos.contains(&Bamboo::C) {
            Some(calc(a, b, c, &ls, &bamboos))
        }
        else {
            None
        }
    }
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let c: usize = iter.next().unwrap().parse().unwrap();

    let mut ls = Vec::with_capacity(8);

    for _ in 0..n {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let l: usize = buf.trim().parse().unwrap();
        ls.push(l);
    }

    let mut bamboos = vec![Bamboo::None; n];
    println!("{}", dfs(n, a, b, c, &ls, 0, &mut bamboos).unwrap());
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll a[55];


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

	ll ans = 0;
	int N;
	cin >> N;
	ll sum = 0;
	ll M = -inf;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
		M = max(a[i], M);
	}


	if (M > 1000) {
		ll X = sum - N * (N - 1);
		ans = X;
		for (int i = 0; i < N; i++)a[i] += X;

		ll D = N + 1;
		ll ok = inf,ng = 0;
		while (ok - ng > 1) {
			ll mid = (ok + ng) / 2LL;
			ll temp = 0;
			for (int i = 0; i < N; i++)temp += max(0LL,(a[i]-mid)/D);
			if (temp <= X)ok = mid;
			else ng = mid;
		}
		ll tempsum = 0;
		for (int i = 0; i < N; i++) {
			tempsum += max(0LL, (a[i] - ok) / D);
			a[i] = max(0LL,a[i] - ((a[i]-ok)/D)*D);
		}
		for (int i = 0; i < X-tempsum; i++) {
			int id = -1;
			int ma = -1;
			for (int i = 0; i < N; i++)if (a[i] > ma) { id = i, ma = a[i]; };
			for (int i = 0; i < N; i++)if (i == id)a[i] -= D;
		}
	}


	//simulation
	while(1){
		int id = -1;
		ll ma = -inf;
		for (int i = 0; i < N; i++) {
			if (a[i] > ma) { id = i, ma = a[i]; };
		}
		if (ma <= N - 1)break;
		for (int i = 0; i < N; i++) {
			if (i != id)a[i]++;
			else a[i] -= N;
		}
		ans++;
	}
	puts(ans);

	
	return 0;
}


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

int main(){

  int N, K, num, ans=0, aaa, Aaa=0;
  cin >> N >> K;
  string S;
  cin >> S;

  int T[N]={};

  if(S[0]=='0'){
    num = 1;
  }else{
    num = 0;
  }

  for(int i=1; i<S.size(); i++){
    if(S[i]=='0' && S[i-1]!='0') num++;
  }

  // 全部逆立ち
  if(K >= num){
    cout << N << endl;
    return 0;
  }

  num = 1;
  aaa = 0;

  for(int i=1; i<N; i++){
    if(S[i]==S[i-1]){
      num++;
    }else{
      T[aaa] = num;
      aaa++;
      num=1;
    }
    if(i==N-1){
      T[aaa] = num;
    }
  }


  int k;
  if(S[0]=='0'){
    k=1;
    while(k+2*K<N){
      Aaa = 0;
      for(int i=k; i<k+2*K+1; i++){
        Aaa += T[i];
      }
      ans = max(ans, Aaa);
      k += 2;
    }
    Aaa = 0;
    for(int i=0; i<2*K; i++){
      Aaa += T[i];
    }
    ans = max(ans, Aaa);
    cout << ans << endl;
    return 0;
    }

  if(S[0]=='1'){
    k=0;
    while(k+2*K<N){
      Aaa = 0;
      for(int i=k; i<k+2*K+1; i++){
        Aaa += T[i];
      }
      ans = max(ans, Aaa);
      k += 2;
    }
    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin>>A[i];
  
  vector<int> rev(N);
  for (int i=0; i<N; i++) rev[A[i]-1] = i+1;
  for (int i=0; i<N; i++) cout<<rev[i]<<endl;
  return 0;
  
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N * 3];
        for (int i = 0; i < N * 3; ++i) {
            A[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(A);
        long ans = 0;
        for (int i = N * 3 - 2; i >= N; i -= 2) {
                ans += A[i];
            }

        System.out.println(ans);
    }
}

Measured memory_bytes: 97128
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  string s;
  cin>>s;
  rep0(i,s.size()-1){
    if(s[i] == 'C'){
      REP(j,i,s.size()){
        if(s[j] == 'F'){
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
	r=list(map(int,input().split()))
	s.append(r)
def score(t):
	last=[0]*26
	happy=0
	for i in range(d):
		last[t[i]-1]=i+1
		happy+=s[i][t[i]-1]
		for j in range(26):
			happy-=(i+1-last[j])*c[j]
		print(happy)
score([int(input())for _ in range(d)])

Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int arr[N];

int minCost(int n, int k) {
    int dp[n];
    dp[0] = 0;
    for (int i = 1; i <= min(k, n); i++)
        dp[i] = abs(arr[i] - arr[0]);

    if (k < n) {
        for (int i = k + 1; i < n; i++) {
            int ans = INT_MAX;
            for (int j = i - 1; j >= i - k; j--) {
                ans = min(ans, dp[j] + abs(arr[i] - arr[j]));
            }
            dp[i] = ans;
        }
    }

    return dp[n - 1];
}

int main()
{
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << minCost(n, k);
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
        int flag=1;
    for(int i=0;i<n-1;i++)
    {
        if(h[i+1]>h[i])
            h[i+1]--;
        else if(h[i+1]==h[i])
        {

        }
        else
        {
            flag=0;
        }
        
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 768
#include <stdio.h>

int main()
{
  char s[5];
  scanf("%s",s);
  int a=0;
  int b=0;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<4;j++){
      if(s[i]==s[j])a=a+1;
    }
  }
  if(a==2)puts("Yes");
  else puts("No");
  return 0;
}

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

void solve(std::string S) {
  ll ans = 0;
  ll cur = 0;
  REP(i, S.size()) {
    if (S[i] == 'R') {
      cur++;
    } else {
      cur = 0;
    }
    ans = max(ans, cur);
  }
  cout << ans << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define INF 0x7fffffff
typedef long long ll;
using namespace std;
int n,C,d[31][31],col[3][31],ans=INF;
bool used[31];
void search(int x,int res)
{
	if(x>2)
	{
		ans=min(ans,res);
		return;
	}	
	int sum;
	for(int i=1;i<=C;i++)
	{
		if(used[i])
			continue;
		sum=0;
		for(int j=1;j<=C;j++)
			sum+=col[x][j]*d[j][i];
		used[i]=true;
		search(x+1,res+sum);
		used[i]=false;
	}
}
int main()
{
	int c;
	cin>>n>>C;
	for(int i=1;i<=C;i++)
		for(int j=1;j<=C;j++)
			scanf("%d",&d[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&c);
			col[(i+j)%3][c]++;
		}	
	search(0,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;i++)
set <int> st;
int n;
vector<int> a(100005);
int main(int argc,char const* argv[])
{
  cin >> n;
  rep(i,n)
    {
      cin >> a[i];
    }
  ll tmp1=0,tmp2=0;
  ll now=0;
  for(int i=0;i<n;i++)
    {
      now+=a[i];
      if(i%2==0)
	{
	  if(now<=0)
	    {
	      tmp1+=(1-now);
	      now=1;
	    }
	}
      else
	{
	  if(now>=0)
	    {
	      tmp1+=(now-(-1));
	      now=-1;
	    }
	}
    }
  now=0;
  for(int i=0;i<n;i++)
    {
      now+=a[i];
      if(i%2!=0)
	{
	  if(now<=0)
	    {
	      tmp2+=(1-now);
	      now=1;
	    }
	}
      else
	{
	  if(now>=0)
	    {
	      tmp2+=(now-(-1));
	      now=-1;
	    }
	}
    }
   
  cout << min(tmp1,tmp2) << endl;
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<tuple>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using tp=tuple<int,int,int,int>;
using vtp=vector<tp>;


int main(void)
{
	int h, w;

	while(scanf("%d%d", &h, &w)==2)
	{
		vvi a(h+1);
		vtp ans;

		for(auto&ma:a) ma.resize(w+1);

		for(int y=1;y<=h;y++)
		{
			for(int x=1;x<=w;x++)
			{
				scanf("%d", &a[y][x]);
			}
		}
		for(int y=1;y<=h;y++)
		{
			for(int x=1;x<w;x++)
			{
				if(a[y][x]%2)
				{
					a[y][x]--;
					a[y][x+1]++;
					ans.emplace_back(y, x, y, x+1);
				}
			}
		}
		for(int y=1;y<h;y++)
		{
			if(a[y][w]%2)
			{
				a[y][w]--;
				a[y+1][w]++;
				ans.emplace_back(y, w, y+1, w);
			}
		}
		printf("%d\n", ans.size());
		for(auto&mtp:ans)
		{
			int y, x, y_, x_;
			tie(y, x, y_, x_)=mtp;
			printf("%d %d %d %d\n", y, x, y_, x_);
		}
	}

	return 0;
}


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

int n,k;
int a[1000000];
int b[1000000];
int deq[1000000];

int main()
{
	cin >> n >> k;
	int s = 0,t=0;
	for(int i = 0;i<n;i++)cin >> a[i];
	for(int i = 0;i<n;i++)
	{
		while(s<t&&a[deq[t-1]]>=a[i])t--;
		deq[t++] = i;
		if(i-k +1>=0)
		{
			b[i-k+1]=a[deq[s]];
			if(deq[s]==i-k+1)
			{
				s++;
			}
		}
	}
	for(int i = 0;i<=n-k;i++)
	{
		if(i)cout<<' ';
		cout<<b[i];
	}
	cout<<endl;
}


Measured memory_bytes: 14816
#include <iostream>

using namespace std;

void hoge(char **map, int x, int y) {
  for (int x2 = x - 3; x2 <= x + 3; ++x2) {
    if (0 <= x2 && x2 <= 7 && map[x2][y] == '1') {
      map[x2][y] = '0';
      hoge(map, x2, y);
    }
  }
  for (int y2 = y - 3; y2 <= y + 3; ++y2) {
    if (0 <= y2 && y2 <= 7 && map[x][y2] == '1') {
      map[x][y2] = '0';
      hoge(map, x, y2);
    }
  }
}

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

  for (int d = 0; d < n; ++d) {
    char map[8][8];
    for (int x = 0; x < 8; ++x)
      for (int y = 0; y < 8; ++y)
        cin >> map[x][y];

    int ix, iy;
    cin >> ix >> iy;

    char *map2[8];
    for (int i = 0; i < 8; ++i)
      map2[i] = map[i];
    hoge(map2, iy-1, ix-1);

    cout << "Data " << d + 1 << ":" << endl;
    for (auto &s : map) {
      for (auto &v : s)
        cout << v;
      cout << endl;
    }
  }
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 1000000000

ll n, a[1000001];

bool pairwise()
{
	ll factors[1000001] = {};
	for (ll i = 0; i < n; i++) {

		ll x = a[i];
		for (ll j = 1; j * j <= x; j++) {

			if (x % j == 0) {

				factors[j]++;

				if (j > 1 && factors[j] == 2)
					return false;

				if (j != x / j) {
					factors[x / j]++;
					if (factors[x / j] == 2)
						return false;
				}
				// x /= j;
			}
		}

	}
	return true;
}

bool setwise()
{
	ll res = a[0];
	for (ll i = 1; i < n; i++)
		res = __gcd(res, a[i]);
	return res == 1LL;
}

void test_case()
{
	cin >> n;

	for (ll i = 0; i < n; i++)
		cin >> a[i];

	if (pairwise()) {
		cout << "pairwise coprime";
	}
	else if (setwise()) {
		cout << "setwise coprime";
	} else {
		cout << "not coprime";
	}
}


int main()
{
	fastio
	// int t;
	// cin >> t;
	// while (t--)
	test_case();
}


Measured memory_bytes: 19204
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#pragma GCC optimize("Ofast,no-stack-protector")
#define res register int
#define N 100005
using namespace std;
int n,L,a[N],maxn,site;
inline int read()
{
  int X=0,w=0;
  char ch=0;
  while(!isdigit(ch))
  {
    w|=ch=='-';
    ch=getchar();
  }
  while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  return w?-X:X;
}
int main()
{
  n=read(),L=read();
  for(res i=1; i<=n; i++)
    a[i]=read();
  for(res i=1; i<n; i++)
    if(maxn<a[i]+a[i+1])
      maxn=a[i]+a[i+1],site=i;
  if(maxn<L)
  {
    puts("Impossible");
    return 0;
  }
  puts("Possible");
  for(res i=1; i<site; i++)
    printf("%d ",i);
  for(res i=n-1; i>site; i--)
    printf("%d ",i);
  printf("%d\n",site);
  return 0;
}


Measured memory_bytes: 1152
x, y, a, b, c, = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

if x < a:
    del p[: a - x]
if y < b:
    del q[: b - y]

delicious = p[:] + q[:] + r[:]
delicious.sort(reverse=True)

cnt = 0
for i in range(x + y):
    cnt += delicious[i]
    
print(cnt)

Measured memory_bytes: 22560
N, A, B = map(int, input().split())
L = str(input())

total = 0
kaigai = 0

for i in range (0, len(L)):
	if L[i] == 'a':
		if total < A+B:
			print('Yes')
			total+=1
		else:
			print('No')
	elif L[i] == 'b':
		if total < A+B and kaigai <B:
			print('Yes')
			total+=1
			kaigai+=1
		else:
			print('No')
	else:
		print('No')

Measured memory_bytes: 4016
#include <stdio.h>

int main(void)
{
  char b;

  scanf("%c",&b);

  switch(b){
    case 'A':
      printf("T");
      break;
    case 'T':
      printf("A");
      break;
    case 'G':
      printf("C");
      break;
    case 'C':
      printf("G");
      break;
  }

  return 0;
}


Measured memory_bytes: 128
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll N, K; cin >> N >> K;
	vector<ll> h(N); rep(i, N)cin >> h[i];

	sort(ALL(h));

	ll mi = 1e18;
	for (int i = 0; i <= N - K; i++) {
		mi = min(mi, h[i + K - 1] - h[i]);
	}

	cout << mi << endl;
}

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

int main() {
	int m1, d1, m2, d2;
	cin >> m1 >> d1;
	cin >> m2 >> d2;

	if (m1 == m2) {
		cout << 0;
	} else {
		cout << 1;
	}



	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
    print(ans)
    return

#D
def D():
    n, m = LI()
    ab = LIR(n)
    ab.sort(key=lambda x: (x[1], x[0]), reverse=True)
    ans = 0
    for i in range(n):
        if m >= ab[i][0]:
            ans += ab[i][1]
            m -= 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    A()


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

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

const int N = 2e3 + 10;
const ll mod = 1e9 + 7;
int n, m, s[N], t[N];
ll dp[N][N];
ll C[N][N];

void init() {
	C[0][0] = 1;
	C[1][0] = C[1][1] = 1;
	for (int i = 2; i < N; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
		}
	}
}

int main() {
	n = read(), m = read();
	init();
	for (int i = 0; i < n; i++) s[i] = read();
	for (int i = 0; i < m; i++) t[i] = read();
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i > 0) dp[i][j] += dp[i - 1][j];
			if (j > 0) dp[i][j] += dp[i][j - 1];
			if (i > 0 && j > 0 && s[i - 1] != t[j - 1]) dp[i][j] += mod - dp[i - 1][j - 1];
			dp[i][j] %= mod;
		}
	}
	printf("%lld\n", dp[n][m]);
	return 0;
}

Measured memory_bytes: 61824