akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


Node treeMinimum(Node x) {
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
}


Node treeSearch(Node u, int k) {
  while (u != NIL) {
    if (u->key == k) break;

    if (u->key > k) {
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return u;
}


Node treeSuccessor(Node x) {
  if (x->right != NIL) {
    return treeMinimum(x->right);
  }

  Node y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  /* 削除する節点yを決定 */
  if (z->left == NIL || z->right == NIL) {
    y = z;
  } else {
    y = treeSuccessor(z);
  }

  /* xをyのNILではない子に設定*/
  if (y->left != NIL) {
    x = y->left;
  /* またはyが子を持たない場合はNILに設定 */
  } else {
    x = y->right;
  }

  /* yの親とxのポインタを変更し、yを削除 */
  /* yが子を１つ持つ場合 */
  if (x != NIL) {
    x->parent = y->parent;
  }
  /* yが根の時 */
  if (y->parent == NIL) {
    root = x;
    /* yが左の子の場合  */
  } else if (y == y->parent->left) {
    y->parent->left = x;
    /* yが右の子の場合 */
  } else {
    y->parent->right = x;
  }

  /* zの次節点が削除された時にyの内容をzに移動 */
  if (y != z) {
    z->key = y->key;
  }
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;

  if (y == NIL) {
    root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void inorder(Node u){
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(void) {
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s", com);
    if (com[0] == 'f') {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if (t != NIL) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    } else if (com[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    } else if (com[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com[0] == 'd') {
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		int n = ni();
		int k = ni();
		String result = n >= 1 + (k - 1)*2 ? "YES" : "NO";
		System.out.println(result);
	}

    //Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
                scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int ax[11],ay[11];
int bx[11],by[11];
struct po{
  int dir,na;
};
po hen[11];
po bhen[11];
int m;
int am;
void ahen() {
  for(int i=0;i<m-1;i++) {
    if(ax[i] == ax[i+1]) {
      if(ay[i+1] - ay[i] > 0) {
	hen[i].dir = 1;
	hen[i].na = ay[i+1] - ay[i];
      }
      else {
	hen[i].dir = 3;
	hen[i].na = -1*(ay[i+1]-ay[i]);
      }
    }
    else if(ay[i] == ay[i+1]) {
      if(ax[i+1]-ax[i] > 0) {
	hen[i].dir = 2;
	hen[i].na = ax[i+1]- ax[i];
      }else {
	hen[i].dir = 0;
	hen[i].na = -1*(ax[i+1]- ax[i]);
      }
    }
    //cout << hen[i].dir << " "<<hen[i].na<<endl;
  }
}

int bbhen() {
  for(int i=0;i<m-1;i++) {
    if(bx[i] == bx[i+1]) {
      if(by[i+1] - by[i] > 0) {
	bhen[i].dir = 1;
	bhen[i].na = by[i+1] - by[i];
      }
      else {
	bhen[i].dir = 3;
	bhen[i].na = -1*(by[i+1]-by[i]);
      }
    }
    else if(by[i] == by[i+1]) {
      if(bx[i+1]-bx[i] > 0) {
	bhen[i].dir = 2;
	bhen[i].na = bx[i+1]- bx[i];
      }else {
	bhen[i].dir = 0;
	bhen[i].na = -1*(bx[i+1]- bx[i]);
      }
    }

    //cout << bhen[i].dir << " "<<bhen[i].na<<endl;
  }

  int t;
  int flg = 0;

 for(int j=0;j<4;j++) {
   t=j;
  if(bhen[0].na == hen[0].na) {
    for(int i=0;i<m-1;i++) 
      if((bhen[i].dir+t)%4 != hen[i].dir%4 || hen[i].na != bhen[i].na){
	flg++;
	break;
      }
  } else flg++;
 
  if(bhen[m-2].na == hen[0].na) {
    
    if(t < 0) t*=-1;
    for(int i=0;i<m-1;i++) 
      if((bhen[m-2-i].dir+t)%4 != hen[i].dir%4 || hen[i].na != bhen[m-2-i].na){
	flg++;
	break;
      }
  } else flg++;

 }

  return flg;
}
  

int main(){

  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    
    for(int i=0;i<=n;i++) {
      cin >> m;

      for(int j=0;j<11;j++) bx[j] = by[j] = 0;

      for(int j=0;j<m;j++) {
	if(i == 0) cin  >> ax[j] >> ay[j];
	else cin >> bx[j] >> by[j];
      }
      //cout <<i<<"??????"<<endl;
      if(i == 0) ahen(),am = m;
      else {
	if(am != m) continue;
	if(bbhen() != 8) cout << i <<endl;
      }
    }
    
    
    cout <<"+++++"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
 
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
 
int t[4][4];
int limit;
 
int getHeuri(){
  int res=0,a;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      if(t[i][j]==0)continue;
      a=t[i][j]-1;
      res+=abs(a/4-i)+abs(a%4-j);
    }
  }
  return res;
}
 
bool check(int depth,int prev,int py,int px){
  int heuri=getHeuri();
  if(heuri+depth>limit)return false;
  if(heuri==0)return true;
  for(int i=0;i<4;i++){
    if(abs(i-prev)==2)continue;
    int ny=py+dy[i],nx=px+dx[i];
    if(ny<0||nx<0)continue;
    if(ny>=4||nx>=4)continue;
    swap(t[ny][nx],t[py][px]);
    if(check(depth+1,i,ny,nx)) return true;
    swap(t[ny][nx],t[py][px]);
  }
  return false;
}
 
void solve(int py,int px){
  for(limit=0;;limit++){
    if(check(0,99,py,px)){
      cout<<limit<<endl;
      return;
    }
  }
}
 
int main(){
  int py,px;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      cin>>t[i][j];
      if(t[i][j]==0){
    py=i;
    px=j;
      }
    }
  }
  solve(py,px);
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>

#define Q_MAX (400000)

typedef struct {
	char block[10][11];
    int num[3];
	int time;
} COLOR;

int head, tail;
COLOR queue[Q_MAX];

void enq(COLOR t)
{
	queue[tail++ % Q_MAX] = t;
}

void deq(COLOR *t)
{
	*t = queue[head++ % Q_MAX];
}

int conv(char c)
{
    return ((c > 'B') + (c > 'G'));
}

int x, y;

void dfs(COLOR *exm, char c, char change, int p, int q)
{
	int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
	int mx, my;
	int i;
	
    exm->num[conv(exm->block[q][p])]--;
    exm->num[conv(c)]++;
	exm->block[q][p] = c;
	
	for (i = 0; i < 4; i++){
		mx = p + dx[i];
		my = q + dy[i];
		if (0 <= mx && mx < x && 0 <= my && my < y && exm->block[my][mx] == change){
			dfs(exm, c, change, mx, my);
		}
	}
}

void check(COLOR p, char col)
{
	COLOR t;
	if (p.block[0][0] != col){
		t = p;
		t.time = p.time + 1;
		dfs(&t, col, t.block[0][0], 0, 0);
		enq(t);
	}
}

int main(void)
{
	COLOR puzzle, temp;
	int i, j;
	char c;
    
	while (1){
		scanf("%d%d", &x, &y);
		
		if (x + y == 0){
			break;
		}
        memset(puzzle.num, 0, sizeof(puzzle.num));
		
		for (i = 0; i < y; i++){
			for (j = 0; j < x; j++){
				do {
					c = puzzle.block[i][j] = getchar();
				} while (c != 'R' && c != 'G' && c != 'B');
                puzzle.num[conv(c)]++;
			}
		}
		memset(queue, 0, sizeof(queue));
		head = tail = 0;
		puzzle.time = 0;
		enq(puzzle);
        
		while (1){
			deq(&temp);
			
			if (temp.num[0] == x * y || temp.num[1] == x * y || temp.num[2] == x * y){
				break;
			}
			
			check(temp, 'R');
			check(temp, 'G');
			check(temp, 'B');
		}
		
		printf("%d\n", temp.time);
	}
	
	return (0);
}

Measured memory_bytes: 49000
#include <stdio.h>

int main(){
    int array[4][2] = {0};
    int hit = 0;
    int blow = 0;
    int i, j;
    while (scanf("%d %d %d %d",&array[0][0],&array[1][0],&array[2][0],&array[3][0])!=EOF){
        scanf("%d %d %d %d",&array[0][1],&array[1][1],&array[2][1],&array[3][1]);
        hit = 0;
        blow = 0;
        for (i = 0; i < 4; i++){
            if (array[i][0] == array[i][1]) {
                hit++;
            }
        }
        for (i = 0; i < 4; i++) {
            for (j = 0; j < 4; j++) {
                if (array[i][0] == array[j][1]) {
                    if (array[i][0] != array[i][1]) {
                        blow++;
                    }
                }
            }
        }
        printf("%d %d\n",hit,blow);
    }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[101];
vector<int> E,O;

template<class V> class MaxFlow_Ford {
public:
	struct edge { int to,reve;V cap;};
	static const int MV = 10000;
	vector<edge> E[MV];
	int vis[MV];
	void add_edge(int x,int y,V cap,bool undir=false) {
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
	}
	V dfs(int from,int to,V cf) {
		V tf;
		if(from==to) return cf;
		vis[from]=1;
		FORR(e,E[from]) if(vis[e.to]==0 && e.cap>0 && (tf = dfs(e.to,to,min(cf,e.cap)))>0) {
			e.cap -= tf;
			E[e.to][e.reve].cap += tf;
			return tf;
		}
		return 0;
	}
	V maxflow(int from, int to) {
		V fl=0,tf;
		while(1) {
			ZERO(vis);
			if((tf = dfs(from,to,numeric_limits<V>::max()))==0) return fl;
			fl+=tf;
		}
	}
};
MaxFlow_Ford<int> mf;

int prime(int x) {
	if(x<=2) return 0;
	for(int a=2;a*a<=x;a++) if(x%a==0) return 0;
	return 1;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	map<int,int> M;
	FOR(i,N) {
		cin>>X[i];
		M[X[i]]^=1;
		M[X[i]+1]^=1;
	}
	
	FORR(r,M) if(r.second) {
		if(r.first%2==0) E.push_back(r.first);
		else O.push_back(r.first);
	}
	
	FOR(x,E.size()) mf.add_edge(0,1000+x,1);
	FOR(x,O.size()) mf.add_edge(2000+x,1,1);
	FOR(x,E.size()) FOR(y,O.size()) if(prime(abs(E[x]-O[y]))) mf.add_edge(1000+x,2000+y,1);
	
	int ma=mf.maxflow(0,1);
	x=E.size()-ma;
	y=O.size()-ma;
	cout<<ma+(x/2)*2+(y/2)*2+x%2*3<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll k, n;
    cin >> k >> n;

    vl a(n+1);
    rep(i, n) {
        cin >> a[i];
    }
    a[n] = a[0] + k;

    vl L(n);
    rep(i, n) {
        L[i] = a[i+1] - a[i];
    }
    sort(rall(L));

    ll ans = k - L[0];

    out(ans);
    re0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;

	bool ok = s.substr(0, 4) == "YAKI";
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  map<char,ll> m;
  string s;
  rep(i,n){
    cin>>s;
    if(s[0]=='M'||s[0]=='A'||s[0]=='R'||s[0]=='C'||s[0]=='H'){
      m[s[0]]++;
    }
  }
  ll ans=0;
  ans+=m['M']*m['A']*m['R'];
  ans+=m['M']*m['A']*m['C'];
  ans+=m['M']*m['A']*m['H'];
  ans+=m['M']*m['R']*m['C'];
  ans+=m['M']*m['R']*m['H'];
  ans+=m['M']*m['C']*m['H'];
  ans+=m['A']*m['R']*m['C'];
  ans+=m['A']*m['R']*m['H'];
  ans+=m['A']*m['C']*m['H'];
  ans+=m['R']*m['C']*m['H'];

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
prime5 = []
for i in range(1,5600):
  a = i * 10 + 1
  flag = True
  for j in range(3,int(a**0.5) + 1):
    if a % j == 0:
      flag = False
  if flag: prime5.append(a)
print(*prime5[:n])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, q;
    cin >> n >> q;
    dsu d(n);
    REP(i, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) d.merge(u, v);
        else cout << (d.same(u, v) ? 1 : 0) << endl;
    }
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s;
  cin >> s;
  string ans = "";
  rep(i,0,(s.size()+1)/2) {
    ans += s.at(2*i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

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

int main(void)
{
unsigned long N, A, B, AB, NmAB, NdAB, ANS;
  scanf("%lu %lu %lu", &N, &A, &B);
  AB = A + B;
  NmAB = N % AB;
  NdAB = N / AB;
  ANS = (A * NdAB) + MIN(A, NmAB);
  printf("%lu\n", ANS);
  
  return 0;
}

Measured memory_bytes: 128
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N = int(input())
    s = "abcdefghijklmnopqrstuvwxyz"
    ans = ""

    a = N
    while a:
        a -= 1
        a, b = divmod(a, 26)
        ans = s[b] + ans

    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 61796
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
 const double pi = 3.141592653589793;
int main(){
  long double a,b,h,m;
  cin >> a >> b >> h >> m;
  long double N = (h * 30) + (m * 0.5);
  long double M = (m * 6);
  if(N >= 360.0)N -= 360;
  if(M >= 360.0)M -= 360;
  long double kaku = min(fabs(N - M),360 - fabs(N - M));
  long double ans = (b * b) + (a * a) - 2 * (b * a * cos(kaku * pi / 180.0));
  cout << fixed << setprecision(1000) <<  sqrt(ans) << endl;
  return 0;
}


Measured memory_bytes: 4172
#include<cstdio>
#include<cstring>
using namespace std;
int n,a[210000];
struct node
{
	int x,p;
}sta[210000];int top;
bool pand(int x)
{
	sta[0].p=0;top=1;
	sta[1].x=0;sta[1].p=a[1];
	for(int i=2;i<=n;i++)
	{
		if(sta[top].p<a[i])
		{
			if(sta[top].x==0)sta[top].p=a[i];
			else sta[++top]=(node){0,a[i]};
		}
		else
		{
			if(x==1)return false;
			while(sta[top].p>a[i])top--;
			if(sta[top].p!=a[i])sta[++top]=(node){0,a[i]};
			sta[top].x++;
			while(sta[top].x==x)
			{
				if(sta[top-1].p!=sta[top].p-1)
				{
					sta[top].x=1;
					sta[top].p=sta[top].p-1;
				}
				else
				{
					top--;
					if(top==0)return false;
					sta[top].x++;
				}
			}
			if(sta[top].p!=a[i])sta[++top]=(node){0,a[i]};
		}
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(pand(mid))r=mid;
		else l=mid+1;
	}
	printf("%d\n",r);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    double maxDen = -1;
    int maxSW = -1, maxS = -1;

    for(int i = 0; 100*a*i <= f; i++) {
        for(int j = 0; 100*b*j <= f-100*a*i; j++) {
            if(i == 0 && j == 0) continue;
            int water = 100*a*i + 100*b*j;
            for(int k = 0; c*k <= f-water; k++) {
                for(int l = 0; d*l <= f-water-c*k; l++) {
                    int sugarLim = water/100*e;
                    int sugar = c*k + d*l;
                    if(sugarLim < sugar || water+sugar > f) continue;
                    if(maxDen < (double)sugar/(water+sugar)) {
                        maxDen = (double)sugar/(water+sugar);
                        maxSW = water+sugar;
                        maxS = sugar;
                    }
                }
            }
        }
    }
    cout << maxSW << " " << maxS << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, a, b)       for(int i=a; i<=b; ++i)
const int N = 1e5 + 10;
int n, k;
int cnt;
int height[N], a[N];
vector<int> e[N];
void dfs(int u, int p = 0) {
    height[u] = 0;
    for(auto v: e[u]) {
        dfs(v, u);
        height[u] = max(height[u], height[v] + 1);
    }
    if (u != 1 && height[u] == k-1 && p != 1) {
        cnt ++;
        height[u] = -1;
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    cnt = 0;
    forn(i, 1, n) cin >> a[i];
    if (a[1] != 1) { cnt ++; a[1] = 1; }
    forn(i, 2, n) e[a[i]].push_back(i);
    dfs(1);
    cout << cnt;
    return 0;
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int coin;
		Scanner scan = new Scanner(System.in);

		coin = scan.nextInt();

		int amari = 0;
		int fh = 0;
		int f = 0;

		if(coin >= 500) {
			fh = coin / 500;
			amari = coin % 500;
			if(amari >= 5) {
				f = amari / 5;
			}
			System.out.println(fh*1000 + f*5);
		} else {
			f = coin / 5;
			System.out.println(f*5);
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2e6+5,M=1e9+7;
int f[N],s[N];
int g(int l,int r){
    return (s[l]-s[r+1]+M)%M;
}
int32_t main(){
    int n;
    cin>>n;
    for(int i=N-2;i>n;--i){
        f[i]=1;
        s[i]=f[i]+s[i+1];
    }
    f[n]=n;
    s[n]=f[n]+s[n+1];
    for(int i=n-1;i>=1;--i){
        f[i]=(f[i+1]+(n-1)*(n-1)+g(i+3,i+n+1))%M;
        s[i]=(f[i]+s[i+1])%M;
    }
    cout<<f[1]<<'\n';
    return 0;
}

Measured memory_bytes: 34880
using System;
using System.Collections.Generic;
using System.Linq;
class ilds1_3_a{
  public static void Main(){
    String[] str = Console.ReadLine().Split(' ');
    Stack<int> stck = new Stack<int>();
    foreach(String s in str){
      switch(s[0]){
        case '+':
          stck.Push(stck.Pop()+stck.Pop());
          break;
        case '*':
          stck.Push(stck.Pop()*stck.Pop());
          break;
        case '-':
          stck.Push(-(stck.Pop()-stck.Pop()));
          break;
        default:
          stck.Push(int.Parse(s));
          break;
      }
    }
    Console.WriteLine(stck.Pop());
  }
}



Measured memory_bytes: 16384
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
  public static void Main()
  {
    var n = int.Parse(Console.ReadLine());
    var input = Console.ReadLine().Split().Select(Double.Parse).ToList();

    while (2 <= input.Count)
    {
      input.Sort();
      var target = input.GetRange(0, 2);
      input.RemoveRange(0, 2);
      input.Add(target.Average());
    }

    Console.WriteLine(input.Single());
  }
}


Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S, T;
  cin >> S >> T;
  int ans = 0;
  rep(i,3) {
    if (S[i] == T[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    int n;cin >> n;
    vector<vector<bool>> b(3,vector<bool>(3));
    for(int i=0;i<n;i++){
        int c;cin >> c;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a[j][k]==c){
                    b[j][k]=true;
                }
            }
        }
    }
    for(int i=0;i<3;i++){
        if(b[i][0]&&b[i][1]&&b[i][2]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    for(int j=0;j<3;j++){
        if(b[0][j]&&b[1][j]&&b[2][j]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(b[0][0]&&b[1][1]&&b[2][2]){
        cout << "Yes" << endl;
        return 0;
    }
    if(b[0][2]&&b[1][1]&&b[2][0]){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.sort()
counter = 0
Amax = A[-1]
A.append(0)
dp = [True for i in range(Amax)]

for i in range(len(A)-1):
    p = A[i]
    if dp[p-1]:
        for j in range(Amax//p):
            if dp[p*(j+1)-1]:
                dp[p*(j+1)-1] = False
        if p != A[i+1]:
            counter += 1
    else:
        continue

print(counter)

Measured memory_bytes: 32208
#include <bits/stdc++.h>
using namespace std;
double u_distance(int, int, int, int);
bool eq(double, double);

int main() {
  int n;
  cin >> n;
  pair<double, double> maxpa(-1, -1); // distance, time
  pair<double, double> maxpb(-1, -1); // distance, time
  int f, lf, a, la, t, lt, x, lx, y, ly;
  for(int i = 0; i < n; ++i) {
    cin >> f >> a >> t >> x >> y;
    if(i > 0 && la != a && lt == t) {
      if(t && ((maxpb.first < u_distance(lx, x, ly, y)) || (eq(maxpb.first, u_distance(lx, x, ly, y)) && maxpb.second >= f - lf))) {
        maxpb.first = u_distance(lx, x, ly, y);
        maxpb.second = f - lf;
      } else if(!t && ((maxpa.first < u_distance(lx, x, ly, y)) || (eq(maxpa.first, u_distance(lx, x, ly, y)) && maxpa.second >= f - lf))) {
        maxpa.first = u_distance(lx, x, ly, y);
        maxpa.second = f - lf;
      }
    }
    lf = f; la = a; lt = t; lx = x; ly = y;
  }
  double maxpasecond = (maxpa.second == -1) ? -1.0 : (maxpa.second / 60.0);
  double maxpbsecond = (maxpb.second == -1) ? -1.0 : (maxpb.second / 60.0);
  // cout << maxpa.first << ' ' << maxpasecond << endl;
  // cout << maxpb.first << ' ' << maxpbsecond << endl;
  (eq(maxpa.first, -1)) ? printf("-1") : printf("%f", maxpa.first);
  printf(" ");
  (eq(maxpasecond, -1)) ? printf("-1") : printf("%f", maxpasecond);
  printf("\n");
  (eq(maxpb.first, -1)) ? printf("-1") : printf("%f", maxpb.first);
  printf(" ");
  (eq(maxpbsecond, -1)) ? printf("-1") : printf("%f", maxpbsecond);
  printf("\n");
  return 0;
}

double u_distance(int lx, int x, int ly, int y) {
  return sqrt(pow(x - lx, 2) + pow(y - ly, 2));
}

bool eq(double a, double b) {
  return abs(a - b) < 0.001;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

int main() {
  int K;
  string S;
  cin >> K >> S;
  
  if ( S.size() <= K ) {
    cout << S << endl;
  } else {
    string s = S.substr(0,K);
    string ans = s + "...";
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int n, x, t;
  cin >> n >> x >> t;
  int made = 0;
  int ans = 0;
  for (int i = 0; made < n; i++) {
    ans += t;
    made += x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

using Pair = pair<int, int>;
using Pairs = vector<Pair>;
using ll = long long;

int main() {
  int N;
  cin >> N;
  Pairs ps(N);
  for(int i = 0; i < N; ++i) {
    cin >> ps[i].second >> ps[i].first;
  }
  sort(ps.begin(), ps.end());

  ll total = 0;
  for(auto p : ps) {
    total += p.second;
    if(total > p.first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>

#define INF 100000

using namespace std;

int main()
{

    while (true) {
        int m, n_min, n_max;
        cin >> m >> n_min >> n_max;
        if (m==0 && n_min ==0 && n_max == 0) {
            return 0;
        }
        vector<int> pv(m);
        for (int i = 0; i < m; i++) {
            cin >> pv[i];
        }
        sort(pv.rbegin(), pv.rend());
        int d_max = -INF;
        int result = n_min;
        for (int n = n_min; n <= n_max; n++) {
            int d = pv[n - 1] - pv[n];
            if (d >= d_max) {
                d_max = d;
                result = n;
            }
        }
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 3056
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
  d=bisect.bisect_left(a,b[i])
  e=bisect.bisect_right(c,b[i])
  ans+=d*(n-e)
print(ans)


Measured memory_bytes: 23200
#include <stdio.h>

int main(){
  int num;
  int a[100];
  int i, j, swap, read;
  int count = 0;
  int min_i, min;

  scanf("%d", &num);
  for(i = 0; i < num; i++) {
    scanf("%d", &read);
    a[i] = read;
  }
  if(num == 1) printf("%d", a[0]);
  else{
  for(i = 0; i < num-1; i++){
    min_i = i; min = a[i];
    for(j = i+1; j < num; j++) if(min > a[j]){min_i = j; min = a[j];}
    if(i != min_i){
      swap = a[i];
      a[i] = a[min_i];
      a[min_i] = swap;
      count++;
    }
    printf("%d ", a[i]);
    if(i == num-2) printf("%d", a[num-1]);
  }
  }
  printf("\n%d\n", count);

  return 0;
}


      
      
    

Measured memory_bytes: 1820
def main():
    N, K, Q = map(int, input().split(" "))
    
    A = [int(input()) for _ in range(Q)]
    
    if Q < K:
        for _ in range(N):
            print("Yes")
        return
    
    M = {}
    for a in A:
        if not a in M.keys():
            M[a] = 1
        else:
            M[a] += 1
    
    for i in range(1, N+1):
        if i in M.keys():
            if K - Q + M[i] >0:
                print("Yes")
            else:
                print("No")
        else:
            print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 11284
#76c
Sdash = list(str(input()))
T = list(str(input()))

#文字列 S′ を見つけ、これは文字列 S の 0 個以上 |S| 個以内の文字が ? に置き換わった文字列であることも分かりました。

#条件1：文字列 S の中に連続する部分文字列として英小文字から成る文字列 Tが含まれている。
#条件2：S は、条件1を満たす文字列の中で辞書順最小の文字列である。

#そのとき、鍵となる文字列 Sを出力しなさい。
#ただし、そのような文字列 S が存在しない場合は代わりに UNRESTORABLE と出力しなさい。

#後ろから探る
presence_flag = 0

for i in range(len(Sdash)-len(T),-1,-1):
    pickuped = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if T[j] != pickuped[j] and pickuped[j] != "?":
            break
    else:
        presence_flag = 1
        if Sdash[i:i+len(T)] != T: #文字列に?を含んでいる 
            Sdash[i:i+len(T)]=T
            break
        
if presence_flag == 1:
    for i in range(len(Sdash)):
        if Sdash[i]=="?":
            Sdash[i]="a"
    print(''.join(map(str, Sdash)))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3192
MOD = 10 ** 9 + 7
n = int(input())
d = {}
for i in range(1, n + 1):
    j = 2
    while j * j <= i:
        while i % j == 0:
            if j in d:
                d[j] += 1
            else:
                d.setdefault(j, 1)
            i //= j
        j += 1
    if i != 1:
        if i in d:
            d[i] += 1
        else:
            d.setdefault(i, 1)
m = 1
for v in d.values():
    m *= v + 1
print(m % MOD)


Measured memory_bytes: 9108
import re

given = input("")

result = re.search(r"([0-9]+)\s([0-9]+)\s([0-9]+)", given)

a = int(result.group(1))
b = int(result.group(2))
c = int(result.group(3))

if a < b and b < c:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 7800
#include<bits/stdc++.h>
using namespace std;
const int maxn=500005,maxm=500005;
struct edge{int fr,to,next;}e[2*maxm];
int tot,last[maxn];
inline void add(int x,int y){e[++tot]=(edge){x,y,last[x]};last[x]=tot;}
inline int read()
{
    int re=0,x=1;char c='^';
    for(;!isdigit(c);c=getchar())if(c=='-')x=-1;
    for(;isdigit(c);c=getchar())re=(re<<3)+(re<<1)+c-'0';
    return re*x;
}
int n,k,ans=(1<<30),sum=0,cnt;
int deep[maxn],fa[maxn],first[maxn];
int st[2*maxn][21];
inline void dfs(int x)
{
    st[++cnt][0]=x;first[x]=cnt;
    for(int i=last[x],y=e[i].to;i;i=e[i].next,y=e[i].to)
        if(fa[x]!=y)
        {
            fa[y]=x;deep[y]=deep[x]+1;
            dfs(y);
            st[++cnt][0]=x;
        }
}
inline int st_max(int x,int y)
{
    if(deep[x]<=deep[y])return x;
    else return y;
}
inline void st_maker()
{
    for(int j=1;j<=21;j++)
        for(int i=1;i+(1<<(j-1))-1<=2*n;i++)
            st[i][j]=st_max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
inline int query(int x,int y)
{
    x=first[x];y=first[y];
    if(x>y)swap(x,y);int z=log2(y-x+1);
    return st_max(st[x][z],st[y-(1<<z)+1][z]);
}
inline int leth(int x,int y)
{
    int lca=query(x,y);
    return deep[x]+deep[y]-(deep[lca]<<1);
}
int main()
{
    int x,y,z;
    n=read();k=read();
    for(int i=1;i<n;i++)
    {
        x=read();y=read();
        add(x,y);
        add(y,x);
    }
    deep[0]=(1<<30);deep[1]=1;dfs(1);
    st_maker();
    if((k&1)==0)
        for(int i=1;i<=n;i++)
        {
            sum=0;
            for(int j=1;j<=n;j++)
                if(leth(i,j)>(k>>1))
                    sum++;
            ans=min(ans,sum);
        }
    else
        for(int i=1;i<=tot;i++)
        {
            sum=0;
            for(int j=1;j<=n;j++)
                if(min(leth(e[i].fr,j),leth(e[i].to,j))>(k>>1))
                    sum++;
            ans=min(ans,sum);
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 8832
n = int(input())
a = list(map(int, input().split()))
b = [i+1 for i in range(n)]
a_dict = dict(zip(a, b))
ans = [''] * n
for i, (a_, b_) in enumerate(sorted(a_dict.items())):
    ans[i] = str(b_)
print(' '.join(ans))

Measured memory_bytes: 30452
import collections

n = int(input())
li = list(map(int,input().split()))
 
ans = 1
ans_li = collections.Counter(li)

if not li[0] == 0:
    print(0)
    exit()

if not ans_li[0] == 1:
    print(0)
    exit()

for i in range(max(ans_li)+1):
    ans *= ans_li[i] ** ans_li[i+1]
    if ans_li[i] == 0:
        print(0)
        exit()
 
print(ans % 998244353)

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  st s;
  cin >> s;
  ll wha, whz;
  rep(i, 0, s.size()) if(s.at(i) == 'A'){
    wha = i;
    break;
  }
  for(ll i = s.size() - 1; i >= 0; i--) if(s.at(i) == 'Z'){
    whz = i;
    break;
  }
  cout << whz - wha + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

#include <vector>
#include <stack> // s.top()
#include <queue> // s.front()
using namespace std;

typedef long long llong;
typedef vector<int> vecint;
typedef vector<llong> vecllong;
typedef pair<llong, llong> P;

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10

bool pairComp(const P& firstElof, const P& secondElof) {
	return firstElof.second > secondElof.second;
}

// ========================================================


int main() {
	int k, a, b;
	cin >> k >> a >> b;
	llong allK = k + 1;
	if (a >= b) {
		cout << allK << endl;
		return 0;
	}
	//step1
	k -= (a - 1);
	if (k <= 0) {
		cout << allK << endl;
		return 0;
	}
	llong score = a;
	//step2
	while (k >= 2) {
		k -= 2;
		score += (b-a);
	}
	if (k == 1)score++;

	cout << max(allK, score) << endl;




	



	return 0;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>p(n),q(n);
  rep(i,0,n)cin>>p[i];
  rep(i,0,n)cin>>q[i];
  vector<vector<ll>>s;
  vector<ll>v;
  rep(i,0,n)v.PB(i+1);
  do{
    s.PB(v);
  }while(next_permutation(ALL(v)));
  ll a,b;
  rep(i,0,s.size())if(s[i]==p)a=i;
  rep(i,0,s.size())if(s[i]==q)b=i;
  cout<<abs(a-b)<<endl;
  return 0;
}

Measured memory_bytes: 4408
n = int(input())
h = list(map(int,input().split()))
m = 0
s = []

for i in range(n - 1):
    if h[i] >= h[i + 1]:
        m += 1
    else:
        s.append(m)
        m = 0
s.append(m)

s.sort()
s.reverse()
print(s[0])
        

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=86400;
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        int ans=1;
        for(int i=0;i<n;i++)
        {
            int t1=ans*2;
            int t2=ans+k;
            ans=min(t1,t2);
        }
        printf("%d\n",ans);
    }
    return 0;
}
/**
2 2
86400 86398
2 86400
0 86400
**/


Measured memory_bytes: 256
/* Author - xorier4104 */

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>


using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define MOD 			(int) 1e9+7
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define mem(a,b)        memset(a,(b),sizeof(a))
#define max(a,b)        ((a)>(b) ? (a):(b))
#define min(a,b)        ((a)<(b) ? (a):(b))
#define abs(a)          ((a)>0 ? (a):(-(a)))
#define sq(a) 			((a)*(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

int main(){ FastIO;

	int a,b,c,k;
	cin>>a>>b>>c>>k;
	
	if(k<=a) cout<<k<<endl;
	else if(k>a && k<=a+b) cout<<a<<endl;
	else if(k>a+b) cout<<a+(k-(a+b))*-1<<endl;
	

return 0;	
}

Measured memory_bytes: 3656
(defun is-ignore(x)
  (or (char= x #\newline) (char= x #\space)))

(defun read-str(flag)
  (let ((s (read-char)))
	(if (is-ignore s)
	  (if flag
		nil
		(read-str nil))
	  (cons s (read-str t)))))

(defun func (x y)
  (if x
	(progn
	  (princ (car x))
	  (func y (cdr x)))))

(let ((n (read)) (a (read-str nil)) (b (read-str nil)))
  (func a b))


Measured memory_bytes: 9700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

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

ll t[110];

int main(void) {
	int n; cin >> n;
	rep(i, n) cin >> t[i];
	// printf("k\n");
	ll d = 1;
	rep(i, n) d = lcm(d, t[i]);
	printf("%lld\n", d);
	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

int A[MAX];
LL S[MAX];
LL Sb[MAX];
int n;

LL getS(int l, int r, LL* s)
{
	LL res = s[r];
	if (l) res -= s[l-1];
	return res;
}

LL get(int l, int r, int val)
{
	LL tot = Sb[n-1];
	tot -= getS(l, r, Sb);
	tot += getS(l, r, S) * val;
	return tot;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_Stdio(false); cin.tie(0);

	int k;
	scanf("%d%d", &n, &k);
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);

		S[i] = A[i];
		if (A[i] > 0) Sb[i] = A[i];

		if (i)
		{
			S[i] += S[i-1];
			Sb[i] += Sb[i-1];
		}
	}

	LL res = -LINF;

	FOR (i, 0, n)
	{
		int L = i;
		int R = i + k - 1;
		if (R >= n) break;

		res = max(res, get(L, R, 0));
		res = max(res, get(L, R, 1));
	}

	cout<<res<<endl;

}


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

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

  int c=0, flag=1;
  while(flag){
    for(int i=0; i<N; i++){
      if(A[i]%2 == 1){
        flag = 0;
        break;
      }
      A[i] /= 2;
    }
    c++;
  }
  c--;

  cout << c << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
main = [0 for i in range(n)]

for i in range(n):
	main[i] = int(input())

minv = main[0]
maxv = main[1] - minv

for i in range(1,n):
	if maxv < main[i] - minv:
		maxv = main[i] - minv
	if minv > main[i]:
		minv = main[i]

print(maxv)


Measured memory_bytes: 13600
def main22():
    data = input().split()
    num = []
    for i in range(2):
        num.append(int(data[i]))
    gate = []
    for i in range(num[1]):
        karin = []
        karid = input().split()
        for j in range(2):
            karin.append(int(karid[j]))
        gate.append(karin)
    und = 1
    upp = num[0]
    for i in range(num[1]):
        if und < gate[i][0]:
            und = gate[i][0]
        if upp > gate[i][1]:
            upp = gate[i][1]
    result = upp - und + 1
    if result < 0:
        print(0)
    else:
        print(result)
        
if __name__ == "__main__":
    main22()

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

X = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

for i in range(b):
    X[i] = str(a)
for j in range(a):
    Y[j] = str(b)

for k in range(9):
    if int(X[k]) < int(Y[k]):
        ｎX = [e for e in X if e != 0]
        print(''.join(nX))
        break
    elif int(X[k]) > int(Y[k]):
        ｎY = [e for e in Y if e != 0]
        print(''.join(nY))
        break
    else:
        if k == 8:
            ｎX = [e for e in X if e != 0]
            print(''.join(nX))

Measured memory_bytes: 3064