akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<iterator>
#include<vector>
#include<algorithm>


#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 100001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main() 
{  
    fast;
    int n,k;
    cin>>n>>k;
    v<ll> a(n,0);
    for(int i = 0 ; i < n ; i++)
    cin>>a[i];
    int start = 0;
    ll ans = LLONG_MAX;
    for(start = 0 ; start+k-1 < n ; start++)
    {
        ll l,r;
        l = a[start];
        r = a[start+k-1];
        if(l*r >= 0)
        {
            ans = min(ans,max(abs(l),abs(r)));
        }
        else
        {
            ll temp = min(abs(l)+2*abs(r),2*abs(l)+abs(r));
            ans = min(ans,temp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {

int h1,h2,m1,m2,k;
cin >> h1 >> m1 >> h2 >> m2 >>k;

int time_h = h2 - h1;
int time_m = m2 - m1;

if(time_m < 0){
	time_h--;
    time_m += 60;
}

int total_time_minute = time_h*60 + time_m;
int study_start_time = total_time_minute - k;

cout << study_start_time;

}
  

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int A, B, C;
    cin >> A >> B >> C;
    bool poor = false;
    if(A == B && B != C) poor = true;
    if(A == C && B != C) poor = true;
    if(C == B && A != C) poor = true;
    cout << (poor ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 100000000
typedef struct{
    int prev;
    int cur;
    int v;
}node_t;
node_t queue[N];
int head,num;
void enqueue(int prev,int cur,int v){
    if(num<N){
        queue[(head+num)%N].prev=prev;
        queue[(head+num)%N].cur=cur;
        queue[(head+num)%N].v=v;
        num++;
    }
    else{
        printf("エラー\n");
        exit(1);
    }
}
node_t dequeue(const double cost[31][31][31]){
    int index=head;
    double min=cost[queue[head].prev][queue[head].cur][queue[head].v];
    for(int i=head+1;i<head+num;i++){
        if(min>cost[queue[i%N].prev][queue[i%N].cur][queue[i%N].v]){
            min=cost[queue[i%N].prev][queue[i%N].cur][queue[i%N].v];
            index=i%N;
        }
    }
    node_t tmp=queue[head]; queue[head]=queue[index]; queue[index]=tmp;
    node_t d={-1,-1,-1};
    if(num>0){
        d=queue[head];
        head=(head+1)%N;
        num--;
    }
    return d;
}
int main(void){
    while(1){
        head=num=0;
        int n,m,s,g;
        int x,y,d,c;
        node_t tmp;
        int dist[31][31]={0},lim[31][31]={0},used[31][31][31]={0};
        //int node[31][31]={0};
        double cost[31][31][31]={0};
        scanf("%d%d%d%d",&n,&m,&s,&g);
        if(n+m==0) break;
        for(int i=1;i<=m;i++){
            scanf("%d%d%d%d",&x,&y,&d,&c);
            dist[x][y]=dist[y][x]=d; lim[x][y]=lim[y][x]=c;
        }
        enqueue(0,s,0);
        while(1){
            tmp=dequeue(cost);
            int prev=tmp.prev,cur=tmp.cur,v=tmp.v;
            if(prev==-1) break;
            for(int i=1;i<=n;i++){//i:新しい場所
                if(prev==i||cur==i||dist[cur][i]==0) continue;
                for(int j=v-1;j<v+2;j++){//速度 v-1,v,v+1
                    if(j<1||lim[cur][i]<j||used[cur][i][j]) continue;
                    if(cost[cur][i][j]==0||
                       cost[cur][i][j]>cost[prev][cur][v]+1.0*dist[cur][i]/j){
                        enqueue(cur,i,j);
                        used[cur][i][j]=1;
                        cost[cur][i][j]=cost[prev][cur][v]+1.0*dist[cur][i]/j;
                    }
                }
            }
        }
        double min=N;
        for(int i=1;i<=n;i++){
            if(cost[i][g][1]>0&&min>cost[i][g][1])
                min=cost[i][g][1];
        }
        if(min==N) printf("unreachable\n");
        else printf("%f\n",min);
    }
}



Measured memory_bytes: 2412
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

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

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long K = sc.nextLong();

        int result = 0;
        for (int i = 0; i < N; i++) {
            long height = sc.nextLong();
            result += height >= K ? 1 : 0;
        }

        System.out.println(result);
    }
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  int p = 0;
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll mod = 0;
  int k;
  cin >> k;
  vector<bool> modulo(k,false);
  if(k%2==0){
    cout << -1 << endl;
    return 0;
  }else{
    REP(i,k){
      mod = (mod*10+7)%k;
      modulo[mod] = true;
      if(modulo[0]){
        cout << (i+1) << endl;
        return 0;
      }
      
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N, M;
	cin >> N >> M;

	int kotae = (N - M) * 100 + M * 1900;
	kotae *= pow(2, M);
	co(kotae);
	Would you please return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
A = [list(input()) for _ in range(n)]
B = [list(input()) for _ in range(m)]
ans = False
for i in range(n-m+1):
    for j in range(n-m+1):
        flg = True
        for e, k in enumerate(range(m)):
            if A[i+e][j:j+m] != B[k]:
                flg = False
        if flg:
            ans = True
            break
print('Yes' if ans else 'No')


Measured memory_bytes: 3060
#include<iostream>
#include<climits>
using namespace std;
int main(){
  	int n,k;
  	cin>>n>>k;
  	int h[n];
  	for(int i=0;i<n;i++){
      	cin>>h[i];
    }
  	int dp[n+1];
  	dp[0]=0;
  	dp[1]=0;
  	for(int i=2;i<=n;i++){
      	int val=INT_MAX;
      	for(int j=max(1,i-k);j<i;j++){
          	val=min(abs(h[i-1]-h[j-1])+dp[j],val);
        }
      	dp[i]=val;
    }
  	cout<<dp[n]<<endl;
  	
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> Pair;
const int Nmax = 2e5 + 5, Mod = 1e9 + 7;

int n, m, i, x, y, d, a[Nmax], A[Nmax], B[Nmax], D[Nmax];
bool used[Nmax];
vector< Pair > v[Nmax];

void dfs(int node)
{
    used[node] = 1;
    for(auto it : v[node])
        if(!used[it.first])
        {
            a[it.first] = a[node] + it.second;
            dfs(it.first);
        }
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> n >> m;
    for(i=1; i<=m; ++i)
    {
        cin >> x >> y >> d;
        A[i] = x; B[i] = y; D[i] = d;
        v[x].push_back({y, d});
        v[y].push_back({x, -d});
    }

    for(i=1; i<=n; ++i)
        if(!used[i])
        {
            a[i] = 0;
            dfs(i);
        }

    for(i=1; i<=m; ++i)
        if(a[B[i]] - a[A[i]] != D[i])
        {
            cout << "No\n";
            return 0;
        }

    cout << "Yes\n";
    return 0;
}


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

#define MAX_N 1000

typedef long long ll;

// string s = "HASFJGHOGAKZZFEGA";
string s;

int main() {
    cin >> s;
    int start = s.find("A");
    int end = s.rfind("Z");
    // printf("%d %d\n", start, end);
    printf("%d\n", end - start + 1);
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<string.h>

using namespace std;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		string code[50];
		for(int i = 0;i < 50;i++){
			code[i] = "";
		}
		
		for(int i = 0;i < n;i++){
			string ts;
			cin >> ts;
			for(int j = 0;j < ts.size();j++){
				if(j == 0){
					code[i] += ts[j];
				}
				if(ts[j] == 'a' || ts[j] == 'i' || ts[j] == 'u' || ts[j] == 'e' || ts[j] == 'o' && j != ts.size()-1){
					code[i] += ts[j+1];
				}
			}
		}
		
		int code_max = 0;
		for(int i = 0;i < n;i++){
			if(code_max < code[i].size()){
				code_max = code[i].size();
			}
		}
		
		int ans = -1;
		for(int i = 1;i <= code_max;i++){
			int snum = 0;
			for(int j = 0;j < n;j++){
				for(int k = 0;k < n;k++){
					if(j != k && code[j].substr(0,i) == code[k].substr(0,i)){
						snum++;
						break;
					}
				}
			}
			if(snum == 0){
				ans = i;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for ( i = 0; i < n1; i++) L[i] = A[left + i];
    for ( i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++){
    	if ( L[i].value <= R[j].value )
    		A[k] = L[i++];
    	else
    		A[k] = R[j++];
    	
   }	
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if (left + 1 < right){
    	mid = (left + right)/2;
    	mergeSort(A, n, left, mid);
    	mergeSort(A, n, mid, right);
    	merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i,j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++){
    	if (A[j].value <= x.value){
    		i++;
    		t = A[i]; A[i] = A[j]; A[j] = t;
    	}
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if(p < r){
    	q = partition(A,n,p,r);
    	quickSort(A,n,p,q-1);
    	quickSort(A,n,q+1,r);
    }
}

int main(){
    int  n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
    	scanf("%s %d", S, &v);
    	A[i].suit = B[i].suit = S[0];
    	A[i].value = B[i].value = v;
    }
    
    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);
    
    for(i = 0; i < n; i++)
    	if(A[i].suit != B[i].suit)stable = 0;
    
    
    if(stable == 1)printf("Stable\n");
    else printf("Not stable\n");
    for (i = 0; i < n; i++)
    	printf("%c %d\n",B[i].suit, B[i].value);
    
    
    return 0;
}



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

#define int long long

signed main(){
  int a,v,b,w,t;cin>>a>>v>>b>>w>>t;
  if(a>b)swap(a,b);
  for(int i=0;i<t;i++){
    a+=v;
    b+=w;
  }
  if(a>=b)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
int a[3005];
int main()
{
    int n,hi=0,i;
    scanf("%d",&n);
     int ans = 0;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        ans += a[i] - 1;
    }
   
    printf("%d\n",ans);
}

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

int main() {
    int N, C, K; cin >> N >> C >> K;
    vector<int> T(N);
    for (int i = 0; i < N; ++i) cin >> T[i];
    sort(T.begin(), T.end());
    int res = 0;
    for (int i = 0; i < N;) {
        ++res;
        int start = i;
        while (i < N && T[i] - T[start] <= K && i - start < C) ++i;
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[100],i,c,b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=n-1;i>=0;i--)
	{
		if((n-i)%2==1)
			c+=a[i];
		else
			b+=a[i];
	}
	printf("%d",c-b);
	return 0;
} 

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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main (){
  int n,m;
  cin >> n >> m;
  int a[m],b[m];

  rep(i,0,m){
    cin >> a[i] >> b[i];
  }

  rep(i,0,n){
    int count = 0;
    rep(j,0,m){
      if(a[j] == i+1 || b[j] == i+1){
        count++;
      }
    }
    pout(count);
  }

  return 0;
}

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

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

        int s = sc.NextInt();
        int w = sc.NextInt();

        string answer = w >= s ? "unsafe" : "safe";

        Console.WriteLine(answer);
    }

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

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

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

            return _line[_index++];
        }

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

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

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

Measured memory_bytes: 27536
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

    class Box
    {
        public bool prob;
        public int num;
        public Box()
        {
            this.prob = false;
            this.num = 0;
        }
    }
    class Program
    {

        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            var ints = In.Ints().ToArray();
            var N = ints[0];
            var M = ints[1];

            List<Box> boxList = new List<Box>();
            boxList.Add(new Box() { num = 1 , prob = true});
            foreach (var i in Enumerable.Range(1, N-1))
            {
                boxList.Add(new Box() { num = 1 , prob = false });
            }

            foreach (var i in Enumerable.Range(1, M))
            {
                var m = In.Ints().ToArray();
                var ma = m[0]-1;
                var mb = m[1]-1;

                boxList[ma].num -= 1;
                boxList[mb].num += 1;

                if( boxList[ma].prob == true)
                {
                    boxList[mb].prob = true;
                }

                if( boxList[ma].num == 0)
                {
                    boxList[ma].prob = false;
                }
            }

            var ans = boxList.Count(b => b.prob == true);
            Out(ans);
            return;
        }

        static void Out(Object o){
            Console.WriteLine(o);
        }
    }




    class In
    {
        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static IEnumerable<int> Ints()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i));
        }

        public static String Line()
        {
            return Console.ReadLine();
        }
    }
}


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

int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) cout << "GREATER" << endl;
    else if (a.size() < b.size()) cout << "LESS" << endl;
    else {
        bool flg = true;
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                flg = false;
                break;
            }
            if (a[i] < b[i]) {
                cout << "LESS" << endl;
                flg = false;
                break;
            }
        }
        if (flg) cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, c = 0, d, e;
	char b;
	string s;
	cin >> a;
	string test[101];
	for (int h = 1; h <= a; h++) {
		cin >> s;
		if (h >= 2 && s[0] != b) {
			c++;
		}
		for (int j = 1; j < h; j++) {
			if (test[j] == s) {
				c++;
			}
		}
		b = s[s.size() - 1];
		test[h] = s;
	}
	if (c == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> e;
}

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

const int N = 6e5 + 5, mod = 998244353;

typedef long long ll;
typedef long double ld;

ll fact[N], rev[N];

ll pw(ll a, ll b) {
	if(!b)	return 1LL;
	ll ans = pw(a, b / 2);
	ans *= ans;
	ans %= mod;
	if(b & 1)	ans *= a;
	return ans % mod;
}

void prep() {
	fact[0] = 1;
	for (int i = 1; i < N; i++)
		fact[i] = (fact[i - 1] * i) % mod;
	rev[N - 1] = pw(fact[N - 1], mod - 2);
	for (int i = N - 2; i; i--)
		rev[i] = (rev[i + 1] * (i + 1)) % mod;
	rev[0] = 1;
}

ll c(ll n, ll k) {
	ll ans = fact[n] * rev[k];
	ans %= mod;
	ans *= rev[n - k];
	return ans % mod;
}

int main() {
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	prep();
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ll tmp = k - (i * a);
		if(tmp >= 0LL && tmp % b == 0 && tmp / b <= n) {
			tmp /= b;
			ans += c(n, i) * c(n, tmp);
			ans %= mod;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <stack>
#define int long long
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int H,A;
    cin >> H >> A;
    if(H%A==0)
        cout << H/A;
    else
        cout << H/A+1;
    return 0;
}

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

const int MAXN = 1 << 18;
struct S {
	int fir, sec;
	explicit S(int _f = 0, int _s = 0) { fir = _f, sec = _s; }
	void insert(int x) {
		if (x > fir) sec = fir, fir = x;
		else if (x > sec) sec = x;
	}
	void merge(const S & b) {
		insert(b.fir);
		insert(b.sec);
	}
} f[MAXN];
int n;
int main() {
	scanf("%d", &n);
	const int lim = 1 << n;
	for (int i = 0; i != lim; ++i) scanf("%d", &f[i].fir);
	for (int i = 0; i != n; ++i)
		for (int j = 0; j != lim; ++j)
			if (!(j >> i & 1))
				f[j | 1 << i].merge(f[j]);
	int ans = 0;
	for (int i = 1; i != lim; ++i) {
		ans = std::max(ans, f[i].fir + f[i].sec);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 5120
loop {
  h, w = gets.chomp.split(' ').map { |i| i.to_i }
  if h == 0 and w == 0 then break
  else
    (1..h).each { |he|
      (1..w).each { |wi|
        if he == 1 or he == h or wi == 1 or wi == w
          print '#'
        else
          print '.'
        end
      }
      print "\n"
    }
    print "\n"
  end
}

Measured memory_bytes: 6108
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	int ha, sa, hb, sb;
	cin>>ha>>sa>>hb>>sb;
	bool f=true;
	while (ha>0 and hb>0){
		if(f) hb-=sa;
		else ha-=sb;
		f=!f;
	}
	if(ha>0) cout<<"Yes";
	else cout<<"No";

}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e16
#define mod 998244353
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll x,y,z;cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<en;
	return 0 ; 
}

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

int main()
{
	int S;
	int h, m, s;
	cin >>S;
	
	h = S / 3600;
	S = S % 3600;
	m = S / 60;
	s = S % 60;
	
	
	cout << h << ":"<< m <<":"<< s << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
using namespace std;
int n;
long long f[400];
int main()
{
    cin >> n;
    f[0] = 2;
    for (int i = 0; i <= n; i++)
    {
        f[i] = f[i - 1] * 2 + 2;
    }
    cout << f[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const int mat_N=3;
const int mat_M=3;
// long long, including mod calculation
struct mat{
	long long a[mat_N][mat_M];
	mat(){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=0;}
	mat(int s){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=(i==j)*s;}
	mat operator+(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-()const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=-a[i][j];
		return ret;
	}
	mat operator*(const long long &k)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]*k%mod;
		return ret;
	}
	// assuming mat_N = mat_M
	// by changing here, you can use for graph problems (ex. a[i][j]=min(a[i][k]+a[k][j]))
	mat operator*(const mat &m)const{
		mat ret;
		for(int k=0;k<mat_N;k++)for(int i=0;i<mat_N;i++)for(int j=0;j<mat_N;j++){
			ret.a[i][j]=(ret.a[i][j]+a[i][k]*m.a[k][j])%mod;
		}
		return ret;
	}
};
mat I=mat(1);
mat pw(mat a,long long t){
	mat ret=I;
	while(t){
		if(t&1){
			ret=ret*a;
		}
		t/=2;
		a=a*a;
	}
	return ret;
}
int c[110000];
 
int n;
mat M;
long long v[3];
long long tv[3];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	M.a[0][1]=M.a[1][0]=M.a[1][1]=M.a[2][0]=M.a[2][2]=1;
	M.a[0][0]=M.a[0][2]=M.a[1][2]=2;
	mat M1=M;
	M1.a[0][0]--;
	M1.a[1][0]--;
	M1.a[2][0]--;
	
	n=b+1;
	int last=0;
	for(int i=0;i<b;i++){
		int d;scanf("%d",&d);
		c[i+1]=d;
	}
	c[n]=a;
	mat cur(1);
	for(int i=0;i<b;i++){
		cur=M1*pw(M,c[i+1]-c[i]-1)*cur;
	}
	cur=pw(M,c[n]-c[n-1]-1)*cur;
 
	long long ret=0;
	ret=(cur.a[0][0]+cur.a[0][1]+cur.a[0][2])%mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

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

bool visited[100100];
vector<int> g[100100];
int l[100100],r[100100],m=1;
ll bitree[225816];

void dfs(int u){
	int i,v;
	visited[u] = true;
	for(i=(g[u].l_ength()-1); i>=0; --i){
		v = g[u][i];
		if(visited[v]){
			continue;
		}
		l[v] = m; ++m;
		dfs(v);
		r[v] = m; ++m;
	}
}

ll query(int x){
	ll v = 0ll;
	while(x){
		v += bitree[x];
		x -= (x&(-x));
	}
	return v;
}

void update(int x, ll v){
	while(x<=m){
		bitree[x] += v;
		x += (x&(-x));
	}
}

int main(void){
	int n,i,k,j,u,q;
	ll w;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> k;
		for(j=0; j<k; ++j){
			cin >> u;
			g[i].push_back(u);
		}
	}
	dfs(0);
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> k;
		if(k){
			cin >> u;
			cout << query(l[u]) << endl;
		}else{
			cin >> u >> w;
			update(l[u],w);
			update(r[u],-w);
		}
	}
	return 0;
}



Measured memory_bytes: 15676
#154_E
n = input()
s = len(n)
x = int(input())

#dp[i][flg][cnt] ... i桁目まで、未満フラグ、0以外の数
dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(s+1)]
dp[0][0][0] = 1

for i in range(1, s+1):
    for k in [0, 1, 2, 3]:
        if n[i-1] == '0':
            dp[i][0][k] += dp[i-1][0][k]
        else:
            dp[i][1][k] += dp[i-1][0][k]
            if k > 0:
                dp[i][0][k] += dp[i-1][0][k-1]
                dp[i][1][k] += dp[i-1][0][k-1] * (int(n[i-1]) - 1)
        
        dp[i][1][k] += dp[i-1][1][k]
        if k > 0:
            dp[i][1][k] += dp[i-1][1][k-1] * 9
   
print(dp[s][0][x] + dp[s][1][x])

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    dump(A);
    map<int, int> mp;
    rep(i, N) mp[A[i]]++;

    int two  = 0;
    int live = 0;
    for (auto p : mp) {
        int x, a;
        tie(x, a) = p;
        if (a % 2 == 0) {
            mp[x] = 2;
            two++;
        } else {
            mp[x] = 1;
        }
        live += mp[x];
    }
    d(live);

    if (two % 2 == 0) {
        live -= two;
    } else {
        live -= two - 1;
        live -= 2;
    }
    cout << live << endl;

    return 0;
}

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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> s(n+1);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    int sw_one_hot = 1 << i;
    for (int j = 0; j < k; j++) {
      int s1;
      cin >> s1;
      //cout << s1 << ' ' << sw_one_hot << endl;
      s[s1-1] |= sw_one_hot;
    }
  }

  for (int i = 0; i < m; i++) {
    int p;
    cin >> p;
    s[n] |= p << i;
  }

  //for (auto it = s.begin(); it != s.end(); it++) {
  //  cout << *it << endl;
  //}

  int loop_size = 1 << n;
  int cnt = 0;
  for (int i = 0; i < loop_size; i++) {
    int sw_xor = s[n];
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        sw_xor ^= s[j];
      }
    }
    //cout << i << ' ' << sw_xor << endl;
    if (!sw_xor) {
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main(){
int n,m;
string key;
map<string,int> m1;
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> key;
    m1[key]++;
  }

map<string,int> m2;
  cin >> m;
  for(int i=0;i<m;++i){
    cin >> key;
    m2[key]++;
  }

  int maxn = 0;
  for(auto i=m1.begin();i!=m1.end();++i){
    string key = i->first;
    if(m2.count(key)){
      maxn = max(maxn,m1[key]-m2[key]);
    } else{
      maxn = max(maxn,m1[key]);
    }
  }

  cout << maxn << endl;
  
  
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N;
		int K;

		N = scan.nextInt();
		K = scan.nextInt();

		// 割れる回数=桁数
		int ans  = 0;

		while(N  > 0) {
			// NをKで割った商で置き換える
			N = N / K;
			// Nが0になるまでカウント
			ans++;
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 21716
#include<stdio.h>
int main()
{
	int a[31] = {0};
	int n,i;
	for (i = 1; i <= 28; i++){
		scanf("%d", &n);
		a[n] = 1;
	}
	for (i = 1; i <= 30; i++){
		if (a[i] != 1){
			printf("%d\n", i);
		}

	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long
#define problem ""

template<typename A, typename B, typename C>
struct triple{
    A X;
    B Y;
    C Z;
    triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0){
    return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b){
    if (a.X != b.X)
        return a.X < b.X;
    if (a.Y != b.Y)
        return a.Y < b.Y;
    return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p){
    ofs << "( " << p.F << " , " << p.S << " )";
    return ofs;
}
template<typename T>
void print(T a){
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}
template<typename T>
T max(T a, T b, T c){
    return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c){
    return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a){
    return *min_element(all(a));
}
template<typename T, typename D>
D max(T a){
    return *max_element(all(a));
}
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void solve(){
    int a, b; cin >> a >> b;
    cout<<max(0LL, a - 2 * b) << '\n';
}

signed main()
{
    if(0){
        freopen(problem".in", "r", stdin);
        freopen(problem".out", "w", stdout);
    }
    srand(time(NULL));
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1; //cin >> t;
    rng(t) solve();
}


Measured memory_bytes: 3636
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    a,b,k = map(int,input().split())
    from math import gcd
    y = make_divisors(gcd(a,b))
    print(y[-k])

if __name__ == '__main__':
    main()


Measured memory_bytes: 61640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
/////////////////////////////////////////

int main(){
  initialize();
  ll A,B,C;
  cin >> A >> B >> C;
  if((A%2)*(B%2)*(C%2)==0) cout << "0" << endl;
  else cout << min(A*B,min(B*C,C*A)) << endl;
  return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
import fractions
#from scipy.misc import comb

N,X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x.sort()

ans = abs(x[1]-x[0])
for i in range(1,N+1):
    ans = fractions.gcd(ans,abs(x[i]-x[i-1]))

print(ans)


Measured memory_bytes: 24976
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod= 1e9+7;

int main(){
  int H,W;
  string S[50];
  char A[50][50];
  cin>>H>>W;
  for (int i(0);i<H;i++) cin>>S[i];
  for (int h(0);h<H;h++) {
    for (int w(0);w<W;w++){
      if (S[h][w]=='#') {
        A[h][w]='#';
        cout << '#';
      }
      else {
        int cnt=0;
        for (int hi(-1);hi<=1;hi++) {
          for (int wi(-1);wi<=1;wi++){
            if (h+hi<0||w+wi<0||h+hi>=50||w+wi>=50) continue; 
            if (S[h+hi][w+wi]=='#') cnt +=1;
          }
        }
        cout << cnt;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[200000];
int s[200000];
int v[200000];
int sz;
int add(int k, int z){
  if(k==0){
    return 0;
  }
  if(sz==0 || s[sz-1] < k){
    s[sz] = k;
    v[sz++] = 1;
    return 1;
  }
  v[sz-1]++;
  if(v[sz-1]==z){
    sz--;
    return add(k-1,z);
  }
  return 1;
}
int main(){
  int i;
  int res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  int KL2GvlyY;
  int Q5VJL1cS;
  int e98WHCEY;
  KL2GvlyY = 1;
  Q5VJL1cS = N;
  while(KL2GvlyY < Q5VJL1cS){
    if((KL2GvlyY + Q5VJL1cS)%2==0){
      e98WHCEY = (KL2GvlyY + Q5VJL1cS) / 2;
    }
    else{
      e98WHCEY = (KL2GvlyY + Q5VJL1cS - 1) / 2;
    }
    sz = 0;
    for(i=(1);i<(N);i++){
      if(A[i-1] < A[i]){
        continue;
      }
      while(sz && s[sz-1] > A[i]){
        sz--;
      }
      if(e98WHCEY==1){
        break;
      }
      if(!add(A[i],e98WHCEY)){
        break;
      }
    }
    if(i==N){
      Q5VJL1cS = e98WHCEY;
    }
    else{
      KL2GvlyY = e98WHCEY + 1;
    }
  }
  res =Q5VJL1cS;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190925-1

// --- original code ---
// int N, A[2d5];
// int s[2d5], v[2d5], sz;
// 
// int add(int k, int z){
//   if(k==0) return 0;
//   
//   if(sz==0 || s[sz-1] < k){
//     s[sz] = k;
//     v[sz++] = 1;
//     return 1;
//   }
//   v[sz-1]++;
//   if(v[sz-1]==z){
//     sz--;
//     return add(k-1,z);
//   }
//   return 1;
// }
// 
// {
//   int i, res;
//   rd(N,A(N));
//   res = bsearch_min[int,z,1,N][
//     sz = 0;
//     rep(i,1,N){
//       if(A[i-1] < A[i]) continue;
//       while(sz && s[sz-1] > A[i]) sz--;
//       if(z==1) break;
//       if(!add(A[i],z)) break;
//     }
//   ](i==N);
//   wt(res);
// }


Measured memory_bytes: 1024
unittest
{
	assert( [ "3", "2 3", "1 3", "1 2" ].parse.expand.solve == 3 );
	assert( [ "4", "2 3 4", "1 3 4", "4 1 2", "3 1 2" ].parse.expand.solve == 4 );
	assert( [ "3", "2 3", "3 1", "1 2" ].parse.expand.solve == -1 );
}



import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ass = new long[][]( n, n - 1 );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
		as[] -= 1;
	}
	return tuple( ass );
}

auto solve( long[][] ass )
{
	auto d = 0L;
	auto ds = new long[ ass.length ];
	auto ct = 0L;
	auto cg = ass.length * ass[ 0 ].length / 2;
	
	auto queue = DList!( Tuple!( long, long ) ).init;
	for( auto i = 0L; i < ass.length; i++ )
	{
		queue.insertBack( tuple( i, ass[ i ].front ) );
	}
	queue.insertBack( tuple( -1L, -1L ) );
	
	while( true )
	{
		auto i = queue.front[ 0 ];
		auto v = queue.front[ 1 ];
		queue.removeFront;
		
		// 1日の終わり
		if( i < 0 && v < 0 )
		{
			if( queue.empty ) break;
			d++;
			queue.insertBack( tuple( -1L, -1L ) );
			continue;
		}
		
		// 終わった試合orまだできない試合なのでスキップ
		if( ass[ i ].empty || ass[ v ].empty || ass[ i ].front != v || ass[ v ].front != i ) continue;
		
		// この日は既に試合しているので次の日に回す
		if( ds[ i ] == d || ds[ v ] == d )
		{
			queue.insertBack( tuple( i, v ) );
			continue;
		}
		
		// 試合実施
		ass[ i ].popFront;
		ass[ v ].popFront;
		if( !ass[ i ].empty ) queue.insertBack( tuple( i, ass[ i ].front ) );
		if( !ass[ v ].empty ) queue.insertBack( tuple( v, ass[ v ].front ) );
		ds[ i ] = d;
		ds[ v ] = d;
		ct++;
	}
	
	return ( ct == cg ) ? d : -1;
}


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

int n;
const int MAX = 100010;
const long long INF = 1e18;
struct edge{
    long long cost;
    long long to;
};
vector<edge> G[MAX];
long long D[MAX];
typedef pair<long long, long long> P;

void dijkstra(long long s){
    for(int i = 0; i < n; i++){
        D[i] = INF;
    }
    D[s] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push({0, s});
    while(!q.empty()){
        P p = q.top();
        q.pop();
        long long now = p.second;
        if(D[now] < p.first) continue;
        for(int i = 0; i < G[now].size(); i++){
            edge e = G[now][i];
            if(D[e.to] > D[now] + e.cost){
                D[e.to] = D[now] + e.cost;
                q.push({D[e.to], e.to});
            }
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({c, b});
        G[b].push_back({c, a});
    }

    int q, k;
    cin >> q >> k;
    dijkstra(k - 1);

    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        cout << D[x - 1] + D[y - 1] << endl;
    }

    return 0;
}

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

ll dp[100][100001] = {};

ll max(ll a, ll b){
	return a>=b?a:b;
}

ll knapsack(int weight[],int value[], int idx ,int W){
	if(W<0) return INT_MIN;
	if( idx<0 ) return 0;
	ll& res = dp[idx][W];
	if(res!=-1)return res;
	res = max(value[idx] + knapsack(weight,value,idx-1,W-weight[idx]) , knapsack(weight,value,idx-1,W));
	return res;
}


int main(){
	memset(dp,-1,sizeof(dp));
	int n,W;
	cin >> n >> W;
	int weight[n];
	int value[n];
	for(int i=0;i < n; ++i){
		cin >> weight[i] >> value[i];
	}

	knapsack(weight,value,n-1, W);
	cout << dp[n-1][W] << endl;

}

Measured memory_bytes: 78336
//→と←が交差しない。…→のかたまり, ←のかたまり, →のかたまり…という風に分けてみる。
//区切りの候補(左からのPCの個数=左からのコンセントの個数となる場所の直後)を|とする。pc|cpなら分割する. pc|pcなら分割しない.
//各かたまりは独立なので, それぞれのつなぎ方を求めてかけると, 答え. それぞれのつなぎかたは…前から数える。
//O(N)

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define int long long


int n;
int a[100000];
int b[100000];
vector<int> types;

void input() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
}

void set_types() {
	typedef pair<int, int> P;
	vector<P> pa;
	int i;
	
	for (i = 0; i < n; i++) pa.push_back(P(a[i], -1));
	for (i = 0; i < n; i++) pa.push_back(P(b[i], 1));
	sort(pa.begin(), pa.end());

	types.clear();
	for (i = 0; i < pa.size(); i++) types.push_back(pa[i].second);
}

vector<int> divide() {
	vector<int> divs;
	int diff = 0;
	int i;
	
	divs.push_back(0);
	for (i = 0; i < types.size(); i++) {
		diff += types[i];
		if (diff == 0) {
			divs.push_back(i + 1);
		}
	}
	
	vector<int> ret;
	ret.push_back(divs[0]);
	for (i = 1; i < (int)divs.size() - 1; i++) {
		if (types[divs[i] - 1] == types[divs[i]]) {
			ret.push_back(divs[i]);
		}
	}
	ret.push_back(divs[(int)divs.size() - 1]);
	
	return ret;
}

//[l, r)
int get_cnt(int l, int r) {
	int cnt = 1;
	int diff = 0;
	
	for (int i = l; i < r; i++) {
		if (types[i] != types[l]) {
			cnt *= abs(diff);
			cnt %= 1000000007;
		}
		diff += types[i];
	}
	return cnt;
}

signed main() {
	int i;
	
	input();
	set_types();
	vector<int> divs = divide();
	
	int ans = 1;
	for (i = 0; i < (int)divs.size() - 1; i++) {
		int cnt = get_cnt(divs[i], divs[i + 1]);
		ans *= cnt;
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8556
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;



int main() {
	int N;
	int K;
	string S;
	cin >> N >> K;
	cin >> S;

	int ans = 0;
	int tmp_ops = 0;
	int left = 0;
	int right = 0;
	bool zero_mode = false;
	while (left < N) {
		//cout << tmp_ops << endl;
		while (right <= N && tmp_ops <= K) {
			if (zero_mode) {
				if (S[right] == '1') {
					zero_mode = false;
				}
			}
			else {
				if (S[right] == '0'){
					zero_mode = true;
					tmp_ops++;
				}
			}
			right++;
		}
		ans = max(right - left - 1, ans);
		//cout << left << " " << right << endl;
		//cout << ans << endl;
		//cout << tmp_ops << endl;

		if (left < N - 1 && S[left] == '0' && S[left + 1] == '1') {
			tmp_ops--;
		}
		left++;
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 512