akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <ctype.h>
#include <memory.h>
int main(void){
    int n,i,o,min,max,t;
    char line[1025],line1[60];
    scanf("%d",&n);
    for(i=0;memset(line,0,sizeof(line)),memset(line1,0,sizeof(line1)),min=t=30,max=31,i<n;i++){
        scanf("%s",line);
        line1[min]=line[0];
        for(o=3;line[o];o++)
            if(isalpha(line[o])){
                if(line[o-1] == '>'){
                    line1[++t]=line[o];
                    if(max==t)
                        max++;
                }
                else{
                    if(min==t)
                        min--;
                    line1[--t]=line[o];
                }
            }
        line1[max]=0;
        printf("%s\n",line1+min);
    }
    return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>

using namespace std;



int w, h, xs, ys, xg, yg, n, c, d, x, y, newc;
int board[100][100];	//添字は行、列の順
int dirx[] = {-1, 0, 0, 1};
int diry[] = {0, -1, 1, 0};
//xs,ysから接する同じ色のところを100に置き換えていく
void dfs(int x, int y)
{
	board[y][x] = 6;
	
	for (int i=0; i<4; i++)
	{
		int nx, ny;
		
		nx = x + dirx[i];
		ny = y + diry[i];
		
		if (0<=nx && nx<w && 0<=ny && ny<h && board[ny][nx]==newc)
		{
			dfs(nx, ny);
		}
	}
}


int main()
{
	while (cin >> w >> h)
	{
		if (w == 0 && h == 0) break;
		
		cin >> xs >> ys >> xg >> yg >> n;
		
		//board初期化
		for (int i=0; i<h; i++)
		{
			for (int j=0; j<w; j++)
			{
				board[i][j] = 0;
			}
		}
		
		for (int i=0; i<n; i++)
		{
			cin >> c >> d >> x >> y;
			if (d == 0)
			{
				//横向き
				board[y-1][x-1] = board[y-1][x] = board[y-1][x+1] = board[y-1][x+2] = c;
				board[y][x-1] = board[y][x] = board[y][x+1] = board[y][x+2] = c;
			} else {
				//縦向き
				board[y-1][x-1] = board[y][x-1] = board[y+1][x-1] = board[y+2][x-1] = c;
				board[y-1][x] = board[y][x] = board[y+1][x] = board[y+2][x] = c;
			}
		}
		
		newc = board[ys-1][xs-1];
		dfs(xs-1, ys-1);
		if (board[yg-1][xg-1] == 6)
		{
			cout << "OK" << endl;
		} else {
			cout << "NG" << endl;
		}
		
		
		//テスト出力
		/*
		for (int i=0; i<h; i++)
		{
			for (int j=0; j<w; j++)
			{
				cout << board[i][j];
			}
			cout << endl;
		}
		*/
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m,d,x; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

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

int main() {
	cin >> s;
	int cnt1 = 0;
	int cnt = 0;
	rep(i, s.size()) {
		if (s[i] == 'o')cnt1++;
		else cnt++;
	}
	int kk = 15 - s.size();
	if (cnt1 + kk >= 8)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int x,y;
	int ans[n]={0};
	for(int i=0;i<m;i++){
		cin>>x>>y;
		if(h[x-1]>h[y-1]){
		//	ans[x-1]=1;
			ans[y-1]=-1;
		}
		if(h[y-1]>h[x-1]){
			//ans[y-1]=1;
			ans[x-1]=-1;
		}
		if(h[x-1]==h[y-1]){
			ans[y-1]=-1;
			ans[x-1]=-1;
		}
	}
/*	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}*/
	int count =0;
	for(int i=0;i<n;i++){
		if(ans[i]==1||ans[i]==0){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
	
}


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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack<double> stack = new Stack<double>();
            string line = "";
            while ((line = Console.ReadLine()) != null)
            {
                String[] arg = line.Split(' ');
                stack.Clear();
                for (int i = 0; i < arg.Length; i++)
                {
                    int n = 0;
                    if (int.TryParse(arg[i], out n))
                    {
                        stack.Push(n);
                    }
                    else if(arg[i] == "+") stack.Push(stack.Pop() + stack.Pop());
                    else if (arg[i] == "-")
                    {
                        double mae = stack.Pop();
                        stack.Push(stack.Pop() - mae);
                    }
                    else if (arg[i] == "*") stack.Push(stack.Pop() * stack.Pop());
                    else if (arg[i] == "/")
                    {
                        double mae = stack.Pop();
                        stack.Push(stack.Pop() / mae);
                    }
                }
                Console.WriteLine(stack.Pop());
            }
        }
    }
}

Measured memory_bytes: 5960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    string a;cin>>a;
    int i=a.size()-1;
    string s="erase";
    string t="eraser";
    string u="dream";
    string v="dreamer";
    bool f=true;
    while(i>=-1){
        if(i==-1)break;
        if(0<=i && i<4){
            f=false;break;
        }else if(i>=4 && a.substr(i-4,5)==s || a.substr(i-4,5)==u){
            i-=5;continue;
        }else if(i>=5 && a.substr(i-5,6)==t){
            i-=6;continue;
        }else if(i>=6 && a.substr(i-6,7)==v){
            i-=7;continue;
        }else{
            f=false;break;
        }
    }
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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


int main() {
  
  int N, X;
  cin >> N >> X;
  vector<int> a(N);
  
  int ans = 0;
  int count = 1;
  
  for ( int i = 0; i < N; i++ ) {
    cin >> a.at(i);
    ans += a.at(i);
    if ( ans <= X ) count++;
    else break;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int a,b;
cin>>a>>b;
ol(max(a+b,max(a-b,a*b)));

return 0;
}



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

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


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

int main(){
	//??£?????¢?????°??¨????????????????\???°??????????????????????????¨??£??????????????¨???
	int sq[200]={0};
	int oddsq[200]={0};
	//???????????????index?????????
	int index=0;
	int indexODD=0;
	 //dp???????????¨??????
	int INF=2000000;
	
	for(int i=0; (i+1)*(i+2)*(i+3)/6<=1000000; ++i){
		sq[i]=(i+1)*(i+2)*(i+3)/6;
		if(sq[i]%2==1) oddsq[indexODD++]=sq[i];	
		//printf("%3d :%7d\n",i, sq[i]);
		index=i+1;
	}
	//printf("index= %d, inODD = %d\n", index, indexODD);
	
	//solve

	//dpA[i]:=??°i?????£?????¢?????°????????¨????????¨?????¨?????????????????£?????¢?????°?????°???????°????		
	int dpA[1000001];
	fill(dpA,dpA+1000001,INF);
	dpA[0]=0;
		
	for(int i=0; i<1000001; ++i){
		for(int j=0; j<index; ++j){
			if(i+sq[j]<1000001) dpA[i+sq[j]]=min(dpA[i+sq[j]],dpA[i]+1);
				else break;	
		}	
	}
		
	//dpB[i]:=??°i?????£?????¢?????°????????¨????????¨?????¨???????????????????\???°????????£?????¢?????°?????°???????°????		
	int dpB[1000001];
	fill(dpB,dpB+1000001,INF);
	dpB[0]=0;
		
	for(int i=0; i<1000001; ++i){
		for(int j=0; j<indexODD; ++j){
			if(i+oddsq[j]<1000001) dpB[i+oddsq[j]]=min(dpB[i+oddsq[j]],dpB[i]+1);
				else break;	
		}	
	}
		
	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		printf("%d %d\n", dpA[n], dpB[n]);
	}	
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;
    
#define EPS (1e-7)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    int ans = 0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        int tmp = 0;
        for(auto c:s){
            tmp += c-'0';
        }
        if(a<=tmp&&tmp<=b){
            ans += i;
        }
    }
    cout<<ans<<endl;
}

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

char HA[1<<21], T[256];

int main() {
    unsigned int n, s, t;
    char c;
    T['A'] = 4;
    T['C'] = 3;
    T['G'] = 2;
    T['T'] = 1;
    scanf("%d", &n);
    getchar();
    while (n--) {
        s = 0;
        t = 1;
        int flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[s] = 1;
        } else {
            puts( HA[s] ? "yes" : "no" );
        }
    }
    return 0;
}

Measured memory_bytes: 1748
#include <stdio.h>
#include "stdlib.h"

#define MAXN 100000

static struct{
    uint answer[MAXN];//S[0..i] 其中 0=<i<=2019 中可以存在最大的个数
    char S[MAXN+1];//字符串
    uint N;
}data;

int main() {
    scanf("%u",&data.N);
    scanf("%s",data.S);

    data.answer[0]=0;
    data.answer[1]=0;

    for(uint i=2;i<=data.N;i++){
        uint end=i-1;
        if (data.S[end]==data.S[end-1])
            data.answer[i]=data.answer[i-1];
        else{
            data.answer[i]=data.answer[i-1]>data.answer[i-2]+1?data.answer[i-1]:data.answer[i-2]+1;
        }
    }

    printf("%u\n",data.answer[data.N]);

    return 0;
}


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

const int N = 200005;
const long long inf = 1e18;

int n, MAX, A, B;
int x[N];
long long sum[N];

struct SegmentTree {
	long long T[N << 2], lz[N << 2];
	void init() {
		for (int i = 1; i < (N << 2); ++i) {
			T[i] = inf;
			lz[i] = 0;
		}
	}

	#define mid ((l + r) >> 1)
	void push(int v, int l, int r) {
		if (lz[v] == 0) return;
		if (l < r) lz[v << 1] += lz[v], lz[v << 1 | 1] += lz[v];
		T[v] += lz[v];
		lz[v] = 0;
		if (T[v] > inf) T[v] = inf;
	}

	void upd_pos(int v, int l, int r, int pos, long long val) {
		push(v, l, r);
		if (l > r || r < pos || l > pos) return;
		if (l == r) { T[v] = val; return; }
		upd_pos(v << 1, l, mid, pos, val); upd_pos(v << 1 | 1, mid + 1, r, pos, val);
		T[v] = min(T[v << 1], T[v << 1 | 1]);
	}
	void upd_seg(int v, int l, int r, int L, int R, int val) {
		push(v, l, r);
		if (l > r || R < l || L > r) return;
		if (L <= l && r <= R) { lz[v] = val; push(v, l, r); return; }
		upd_seg(v << 1, l, mid, L, R, val); upd_seg(v << 1 | 1, mid + 1, r, L, R, val);
		T[v] = min(T[v << 1], T[v << 1 | 1]);
	}

	long long get(int v, int l, int r, int L, int R) {
		push(v, l, r);
		if (l > r || R < l || L > r) return inf;
		if (L <= l && r <= R) return T[v];
		return min(get(v << 1, l, mid, L, R), get(v << 1 | 1, mid + 1, r, L, R));
	}
	#undef mid

	void upd_pos(int pos, long long val) { upd_pos(1, 0, MAX, pos, val); }
	void upd_seg(int l, int r, int val) { upd_seg(1, 0, MAX, l, r, val); }
	long long get(int l, int r) { return get(1, 0, MAX, l, r); }
} seg1, seg2;

long long ans = inf;

void solve() {
	//x[0] = B;
	// first move: A
	seg1.init(); // seg1 for xi >= xj (i > j)
	seg2.init(); // seg2 for xi < xj (i > j)
	seg1.upd_pos(B, abs(x[1] - A) - B);
	seg2.upd_pos(B, abs(x[1] - A) + B);

	for (int i = 2; i <= n; ++i) {
		long long cur = min(seg1.get(0, x[i]) + x[i], seg2.get(x[i], MAX) - x[i]);
		seg1.upd_seg(0, MAX, abs(x[i] - x[i-1]));
		seg2.upd_seg(0, MAX, abs(x[i] - x[i-1]));
		seg1.upd_pos(x[i-1], cur - x[i-1]);
		seg2.upd_pos(x[i-1], cur + x[i-1]);
	}
	
	for (int i = 1; i <= MAX; ++i) {
		ans = min(ans, seg1.get(i, i) + i);
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> MAX >> n >> A >> B; // initial positions
	for (int i = 1; i <= n; ++i) cin >> x[i];
	solve();
	swap(A,B);
	solve();
	printf("%lld\n", ans);
}

Measured memory_bytes: 27648
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
using namespace std;


int main(){
	int n, y;
	cin >> n >> y;
	for(int i = 0; i<=n;++i){
		for(int j = 0; j <= n-i; ++j){
			int k = n - i - j;
			if (i*10000+j*5000+k*1000 == y){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double 
#define For(i, a, n) for(long long i = a; (a < n) ? (i < n) : (i > n); (a < n) ? (i++) : (i--))
#define mod 1000000007
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
using namespace std;


void solve() {
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    For(i, 0, n) {
        cin >> a[i];
        sum = (sum % mod + a[i] % mod) % mod;
    }
    ll v = 0;
    ll ans = 0;
    For(i ,0 , n - 1) {
        v = (v % mod + a[i] % mod) % mod;
        ll z = sum - v;
        if(z < 0)
            z = (z + mod) % mod;
        ans = (ans % mod + (z * (a[i] % mod) % mod) % mod) % mod;
    }
    cout << ans << "\n";
}

int main() {
    fio;
    solve();
}

Measured memory_bytes: 5204
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 0; i < n; ++i)
			{
				int a = stdIn.nextInt();
				list.add(a);
			}
			int ohajiki = 32;
			int pos = 0;
			boolean endFlag = false;
			while(!endFlag)
			{
				ohajiki -= (ohajiki - 1) % 5;
				System.out.println(ohajiki);
				ohajiki -= list.get(pos);
				if(ohajiki <= 0)
				{
					endFlag = true;
					System.out.println("0");
					continue;
				}
				else
				{
					System.out.println(ohajiki);
				}
				++pos;
				if(pos >= n)
				{
					pos = 0;
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

const int coin[6] = { 500,100,50,10,5,1 };

using namespace std;

struct Expm { int a, b, c, r; };

int main(){
	
	/*int answer[5][2] = { 0 };
	int n = 0;

	int buf[100];
	int ndataset;
	for (ndataset = 0; ; ndataset++) {

		cin >> n;
		if (n == 0) break;

		for (int i = 0; i < n; i++) {
			cin >> buf[i];
		}

		sort(&buf[0], &buf[n]);

		int scoreT = 0;
		int scoreH = 0;
		for (int i = 0; i < n; i++) {
			int sbase = 2 * i + 1 - buf[i];
			if (sbase > 0) {
				scoreH = max(abs(sbase), scoreH);
			}
			else {
				scoreT = max(abs(sbase), scoreT);
			}
		}
		if (scoreH > scoreT) scoreT = 0;
		if (scoreH <= scoreT) scoreH = 0;
		answer[ndataset][0] = scoreT;
		answer[ndataset][1] = scoreH;

	} // dataset

	for (int i = 0; i < ndataset; i++) {
		cout << answer[i][0] << endl;
		cout << answer[i][1] << endl;
	}*/

	int resA[5][100]; int resB[5][100]; int resC[5][100];
	int numa[5], numb[5], numc[5], nume[5];
	int set = 0;

	for (;; set++) {

		Expm expm[1000];

		cin >> numa[set] >> numb[set] >> numc[set];
		if (numa[set] == 0 && numb[set] == 0 && numc[set] == 0) break;

		for (int i = 0; i < numa[set]; i++) resA[set][i] = 2;
		for (int i = 0; i < numb[set]; i++) resB[set][i] = 2;
		for (int i = 0; i < numc[set]; i++) resC[set][i] = 2;

		cin >> nume[set];
		for (int i = 0; i < nume[set]; i++) {
			cin >> expm[i].a
				>> expm[i].b
				>> expm[i].c
				>> expm[i].r;
			if (expm[i].r) {
				resA[set][expm[i].a-1] = resB[set][expm[i].b-numa[set]-1] =
					resC[set][expm[i].c - numa[set] - numb[set] -1] = 1;
			}
		}
		for (int i = 0; i < nume[set]; i++) {
			if (expm[i].r) continue;
			if (resA[set][expm[i].a-1] == 1 &&
				resB[set][expm[i].b - numa[set] -1] == 1)
				resC[set][expm[i].c - numa[set] - numb[set] -1] = 0;
			if (resC[set][expm[i].c - numa[set] - numb[set] -1] == 1 &&
				resB[set][expm[i].b - numa[set] -1] == 1)
				resA[set][expm[i].a-1] = 0;
			if (resA[set][expm[i].a-1] == 1 &&
				resC[set][expm[i].c - numa[set] - numb[set] -1] == 1)
				resB[set][expm[i].b - numa[set] -1] = 0;
		}
	}

	for (int j = 0; j < set; j++) {
		for (int i = 0; i < numa[j]; i++)
			cout << resA[j][i] << endl;
		for (int i = 0; i < numb[j]; i++)
			cout << resB[j][i] << endl;
		for (int i = 0; i < numc[j]; i++)
			cout << resC[j][i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

long diff(long l, long m, long r, vector<long> &b) {
    long a = b[m] - b[l];
    long c = b[r] - b[m];
    return abs(a - c);
}

int main() {
    long N;
    cin >> N;
    vector<long> A(N + 1, 0);

    for (long i = 1; i <= N; ++i) {
        cin >> A[i];
    }
    for (long j = 1; j <= N - 1; ++j) {
        A[j + 1] += A[j];
    }

    long mindiff = INT_MAX;
    long l = 1;
    long r = 3;
    for (long m = 2; m <= N - 2; m++) {
        while (l <= m - 2 && diff(0, l, m, A) > diff(0, l + 1, m, A)) {
            l++;
        }
        while (r <= N - 2 && diff(m, r, N, A) > diff(m, r + 1, N, A)) {
            r++;
        }

        vector<long> p(4);
        p[0] = A[l] - A[0];
        p[1] = A[m] - A[l];
        p[2] = A[r] - A[m];
        p[3] = A[N] - A[r];
        long diff = *max_element(p.begin(), p.end()) - *min_element(p.begin(), p.end());
        mindiff = min(mindiff, diff);
    }
    cout << mindiff << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

int KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
		else return true;
	}
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


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

	Yes(KIBN(s));

	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MOD=1000000007;

int main() {
  int n;
  cin >> n;
  int m=0;
  rep(i,n) {
    int x;
    cin >> x;
    if(x!=i+1) m++;
  }
  cout << (m<3? "YES" :"NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
typedef long long ll;
#define rep(i, n) for (int (i) = 0; i < (n);++i)
using namespace std;

int main(){
    ll power = 1;
    ll N;
    cin >> N;
    for(ll i = 1; i <= N; i++){
        power *= i;
        power = power % 1000000007;
    }
    cout << power << endl;
    return 0;
}

Measured memory_bytes: 256
main = do
  [n,m,c] <- map read . words <$> getLine :: IO [Int]
  bs <- map read . words <$> getLine :: IO [Int]
  as <- map (map read . words) . lines <$> getContents :: IO [[Int]]
  print $ length $ filter (\a -> c + (sum $ zipWith (*) bs a) > 0) as

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

int main(){
	int N, K, Point[3];
	cin >> N >> K >> Point[0] >> Point[2] >> Point[1];
	string T;
	cin >> T;
	vector<int> g(N);
	for(int i=0;i<N;i++) {
		if(T[i] == 'r') g[i] = 0;
		if(T[i] == 'p') g[i] = 1;
		if(T[i] == 's') g[i] = 2;
	}

	int ans = 0;
	for(int i=0;i<K;i++) {
		int point = 0;
		point += Point[(g[i] + 1) % 3];
		int forbidden = (g[i] + 1) % 3;
		vector<vector<int>> dp(N/K + 5, vector<int>(3,0));
		int cnt = 0;
		for(int j=i;j<N;j+=K) {
			// 今回出したい手がk
			for(int k=0;k<3;k++) {
				int plus = 0;
				// 勝つとき
				if(k == (g[j] + 1) % 3) plus += Point[k];
				dp[cnt+1][k] = max(dp[cnt][(k+1)%3],dp[cnt][(k+2)%3]) + plus;
			}
			cnt++;
		}
		ans += max(dp[cnt][0], max(dp[cnt][1], dp[cnt][2]));
	}
	cout << ans << endl;
}

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

struct Convert_ID_HW {
    ll N, M;
    Convert_ID_HW(ll N, ll M) : N(N), M(M) {}
    ll getid(ll h, ll w) { return h*M + w;}
    ll geth(ll id) { return id/M;}
    ll getw(ll id) { return id%M;}
};

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<string> S(N);
    for ( int i = 0; i < N; i++ ) cin >> S[i];
    int vs = N*M, vt = N*M+1;
    Convert_ID_HW ids(N,M);
    vector<int> dh = {0, 1, 0, -1}, dw = {1, 0, -1, 0};
    atcoder::mf_graph<ll> g(N*M+2);
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            if ( S[i][j] == '#' ) continue;
            if ( (i ^ j) & 1 ) continue;
            for ( int ii = 0; ii < 4; ii++ ) {
                int h = i + dh[ii];
                int w = j + dw[ii];
                if ( h < 0 || h >= N || w < 0 || w >= M ) continue;
                if ( S[h][w] == '#' ) continue;
                g.add_edge(ids.getid(i,j), ids.getid(h,w), 1LL);
            }
        }
    }
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            if ( S[i][j] == '#' ) continue;
            if ( (i^j)&1 ) {
                g.add_edge(ids.getid(i,j), vt, 1LL);
            } else {
                g.add_edge(vs, ids.getid(i,j), 1LL);
            }
        }
    }

    ll f = g.flow(vs, vt);
    vector<string> ans(S);
    for ( auto e : g.edges() ) {
        if ( e.from == vs || e.to == vt ) continue;
        if ( e.flow != 1 ) continue;
        int h1 = ids.geth(e.from), w1 = ids.getw(e.from);
        int h2 = ids.geth(e.to), w2 = ids.getw(e.to);
        if ( h1 == h2 ) {
            if ( w1 > w2 ) swap(w1,w2);
            ans[h1][w1] = '>';
            ans[h2][w2] = '<';
        } else if ( w1 == w2 ) {
            if ( h1 > h2 ) swap(h1,h2);
            ans[h1][w1] = 'v';
            ans[h2][w2] = '^';
        }
    }
    cout << f << "\n";
    for ( auto a : ans ) {
        cout << a << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
    
int main(void){
    int n; cin >> n;
    vector<int> cnt(4);
    
    rep(i, n){
        string s; cin >> s;
        if(s == "AC"){
            cnt.at(0) += 1;
        }else if(s == "WA"){
            cnt.at(1) += 1;
        }else if(s == "TLE"){
            cnt.at(2) += 1;
        }else if(s == "RE"){
            cnt.at(3) += 1;
        }
    }
    
    cout << "AC x " << cnt.at(0) << endl;
    cout << "WA x " << cnt.at(1) << endl;
    cout << "TLE x " << cnt.at(2) << endl;
    cout << "RE x " << cnt.at(3) << endl;
        
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;

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

#define SPRE(x) setprecision(x) // 精度を指定

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll X;
	cin >> X;
	ll n = 1;
	ll sum = 1;
	while(sum < X){
		sum += ++n;
	}
	cout << n << '\n';

}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashMap<Integer, Long> HM = new HashMap<>();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            A[i] = tmp;
            if (HM.containsKey(tmp)) {
                HM.put(tmp, HM.get(tmp) + 1L);
            } else {
                HM.put(tmp, 1L);
            }
        }
        Long sum = 0L;
        for (int s : HM.keySet()) {
            Long tmp = HM.get(s);
            sum = sum + tmp * (tmp - 1) / 2;
        }
        for (int i = 0; i < N; i++) {
            System.out.println(sum - HM.get(A[i]) + 1);

        }

    }
}

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

                                    typedef long long ll;
                                    typedef  double ld;
                                    #define rep(i,a,n) for(ll i=(a); i<(n); i++)
                                    #define per(i,a,n) for(ll i=(n-1); i>=(a); i--)
                                    #define F first
                                    #define S second
                                    #define maxx(a,b) a=max(a,b)
                                    #define minn(a,b) a=min(a,b)
                                    #define db(x) cerr<<#x<<" = "<<x<<endl
                                    #define N 1111111
                                    #define mod 1000000007
                                    #define rt return
                                    #define inf 12345678908761

                                    using namespace std;

                                    ll a[111111],w[111],v[111];

                                    int main(){

                                        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

                                        //freopen("Ulug'bek","r",stdin);
                                        //freopen("Abdimanabov","w",stdout);

                                        int n,W; cin>>n>>W;
                                        rep(i,1,n+1)cin>>w[i]>>v[i];

                                        memset(a,-1,sizeof a);
                                        a[0]=0;

                                        rep(i,1,n+1)
                                            per(j,w[i],W+1)
                                                if(a[j-w[i]]!=-1)maxx(a[j],a[j-w[i]]+v[i]);

                                        cout<<*max_element(a,a+W+1);

                                    rt 0;
                                    }



















Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

vector<ll> ans;
vector<ll> tree[200010];

void dfs(int v, int pair) {
    for(int i = 0; i < tree[v].size(); i++) {
        if(tree[v][i]==pair) continue;
        ans[tree[v][i]] += ans[v];
        dfs(tree[v][i],v);
    }
}
int main() {
    int n, q; cin >> n >> q;
    rep(i,n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x; cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0,-1);
    
    rep(i,n) {
        cout << ans[i] << endl;
    }



    return 0;
}

Measured memory_bytes: 27392
N, M = map(int, input().split())
S = input()
T = input()

def _gcd(a,b):
  while b>0:
    a,b=b,a%b
  return a

gcd = _gcd(N,M)
lcm = N*M//gcd

def check():
  a,b = 0,0
  da,db = N//gcd, M//gcd
  while a < N:
    if S[a]!=T[b]:
      print(-1)
      return
    a+=da
    b+=db
  print(lcm)

check()  






Measured memory_bytes: 3316
N,K=map(int,input().split())
def syurui(p):
    if p==1:
        return p
    elif p==2:
        return 3*p*(p-1)+p
    else:
        return p*(p-1)*(p-2)+3*p*(p-1)+p    
if K%2==0:
    print(syurui(N//K)+syurui(N//(K//2)-N//K))
else:
    print(syurui(N//K))

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		if(b % a == 0) {
			System.out.println(a+b);
		}else {
			System.out.println(b-a);
		}
	}
}

Measured memory_bytes: 23252
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let N = util.Scan1 int
util.ScanVecV N (fun x ->
  x.Split()
  |> fun a -> (float a.[0]) * (if a.[1] = "JPY" then 1.0 else 380000.0 ))
|> Array.sum
|> printfn "%f"


Measured memory_bytes: 14172
#include <stdio.h>

int main()
{   int n,i;
    scanf("%d",&n);
    int b[101],j;
    b[n]=0;
    for(i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    
    int l=n;
    int op[100],k=0,flag=1;
    while(flag>0&&n>=0){
        flag=0;
        for(i=n-1;i>=0;i--){
            if(b[i]==i+1){
                op[k]=b[i];
                k++;
                flag=1;
                for(j=i;j<n-1;j++){
                    b[j]=b[j+1];
                }
                n--;
                break;
            }
        }
    }
    if(k<l){
        printf("-1");
        return 0;
    }
    for(i=k-1;i>=0;i--){
    printf("%d\n",op[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> P(N);
    rep(i, N) cin >> P[i];
    set<ll> se;
    for(int bit = 1; bit < (1 << N); bit++) {
        ll lcm = 1;
        for(int i = 0; i < N; i++) {
            if(bit & (1 << i)) {
                lcm = lcm * P[i] / __gcd(lcm, P[i]);
            }
        }
        se.insert(lcm);
    }
    cout << se.size() << endl;
    return 0;
}


Measured memory_bytes: 4072
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int X;
    int Y;
    cin >> X >> Y;

    // A+B = X
    // 2*A + 4*B = Y
    // 2*A + 2*B = 2*X
    // Y - 2*X = 2*B

    int D = Y - 2*X;

    if (D >= 0 && D%2 == 0) {
        int B = D/2;
        int A = X-B;

        if (A >= 0 && B >= 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int64_t N,A;
    cin >> N;
    map<int64_t,int64_t> data;
    int64_t sum=0;
    for (int i=0;i<N;i++) {
        cin >> A;
        sum+=A;
        data[A]++;
    }
    
    int64_t Q,B,C;
    cin >> Q;
    
    for (int i=0;i<Q;i++) {
        cin >> B>> C;
        sum+=(C-B)*data[B];
        data[C]+=data[B];
        data[B]=0;
        cout << sum << endl;
    }
    
    
}


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

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

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define rep_cs(i, l, n) for (int i = (l); i <= (n); i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long combination(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_C = 1000;
long long Com[MAX_C][MAX_C];

void combination_for_small()
{
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i)
    {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j)
        {
            Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]) % MOD;
        }
    }
}

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    while (n > 0)
    {
        n = n / k;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;



int main(){
    int n, k;
    cin >> n >> k;
    if(k != 1)cout << n - k;
    else cout << 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, z = 0;
    cin >> n >> m;
    for (int i = 1; i * i <= m; i++) if (m % i == 0) {
        if (m / i >= n) z = max(z, i);
        if (m / (m / i) >= n) z = max(z, m / i);
    }
    cout << z;
}


Measured memory_bytes: 256
def b_search (min, max)
  mid = (min + max) / 2
  if mid == min
    if possible?(min)
      return min
    else
      return max
    end
  end
  unless possible?(mid)
    min = mid
  else
    max = mid
  end
  b_search(min, max)
end

def possible?(limit)
  neccesary_training = 0
  N.times do |i|
    tmp_cost = $eat_costs[i] - limit / $food_costs[i]
    neccesary_training += tmp_cost if tmp_cost > 0
  end
  neccesary_training <= K
end

INF = 10 ** 18
N, K = gets.split.map(&:to_i)
$eat_costs = gets.split.map(&:to_i).sort
$food_costs = gets.split.map(&:to_i).sort { |a, b| b <=> a }

puts b_search(0, INF)


Measured memory_bytes: 34896
/* 
 * Created on: May 11, 2020 time: 1:15:09 PM 
 *      Author: null_ptr
 */
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	string str1,str2;
	cin>>str1>>str2;
	int n=str2.size();
	if(str1==str2.substr(0,n-1))
		cout<<"Yes\n";
	else
		cout<<"No\n";
}


Measured memory_bytes: 3592
#![allow(unused)]

use std::cmp::{min, max};

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Scanner<'a, R> {
        Scanner { reader: reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n: usize = sc.get();
    let k: usize = sc.get();
    let hs: Vec<i64> = (0..n).map(|_| sc.get()).collect();

    let mut dp = vec![std::i64::MAX; n];

    dp[0] = 0;

    for i in 1..n {
        dp[i] = ((max(0, i as i64 - k as i64) as usize)..i)
            .map(|j| dp[j] + (hs[j] - hs[i]).abs())
            .min()
            .unwrap();
    }

    println!("{}", dp[n - 1]);
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (abs(a-c)<=d||(abs(a - b) <= d && abs(b - c) <= d))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}
const int N = 500 + 10;
const int dx[] = {0 , 0 , 1 , -1};
const int dy[] = {1 , -1 , 0 , 0};
 
ll res[N][N] ;
int n;
int pri[N * 4] , pcnt;
 
void getp(){
	for (int i = 2;pcnt <= 1100;i++){
		for (int j = 1;j <= pcnt;j++){
			if (i % pri[j] == 0) goto wxh;
		}
		pri[++pcnt] = i;
		wxh:;
	}
}
int main(){
	scanf("%d",&n);
	
    if(n==2) return printf("4 7\n23 10\n"),0;
	getp();
	for (int i = 1;i <= n;i++)
	for (int j = 1;j <= n;j++)
	if ( !((i + j) & 1)){
		res[i][j] = 1ll * pri[(i + j) >> 1] * pri[((i - j) >> 1) + ((n + 1) / 2) + n];
	}
	for (int i = 1;i <= n;i++)
	for (int j = 1;j <= n;j++)
	if ( ((i + j) & 1)){
		ll d = 1;
		for (int o = 0;o < 4;o++){
	
			int ni = i + dx[o] , nj = j + dy[o];
			if (ni > n || ni < 1 || nj > n || nj < 1) continue;
			d = d / __gcd(d , res[ni][nj]) * res[ni][nj] ;
		}
		res[i][j] = d + 1;
	}
	
	
	for (int i = 1;i <= n;i++){
		for (int j = 1;j <= n;j++){
			printf("%lld ",res[i][j]);
		}enter;
	}
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define pi 3.1415  
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 1000009
#define MOD 1000000007
#define INF (int)3000009
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-2*b)<<endl;

    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int f(string s){
  int n=s.length();
  vector<int> a(n);
  a[0] = n;
  int i = 1, j = 0;
  while(i<n){
    while (i+j<n && s[j]==s[i+j]) j++;
    a[i] = j;
    if (j==0) {
      i++;
      continue;
    }
    int k = 1;
    while(i+k<n && k+a[k]<j){
      a[i+k] = a[k];
      ++k;
    }
    i += k;
    j -= k;
  }

  int res = 0;
  rep(i,n){
    res = max(res,min(a[i],i));
  }
  return res;
}

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

  int ans = 0;
  rep(i,n) ans = max(ans,f(s.substr(i,n-i)));
  cout << ans << endl;
}


Measured memory_bytes: 256