akhauriyash/Code-Regression huggingface dataset:
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

class AOJ0107{
private:
  int w,d,h;
  double t_r,f_r,l_r;
public:
  AOJ0107(int w,int h,int d):w(w),h(h),d(d){
    t_r = sqrt(pow((double)w/2.0,2)+pow((double)h/2.0,2));
    f_r = sqrt(pow((double)h/2.0,2)+pow((double)d/2.0,2));  
    l_r = sqrt(pow((double)w/2.0,2)+pow((double)d/2.0,2));  
  }
  ~AOJ0107(){}

  bool judge(double sp){
    if(sp-t_r > EPS)return true;
    if(sp-f_r > EPS)return true;
    if(sp-l_r > EPS)return true;
    return false;
  }

  void run(){
    int cnt;
    cin >> cnt;
    rep(i,cnt){
      int rect;
      cin >> rect;
      if(judge(rect))cout << "OK" << endl;
      else cout << "NA" << endl;
    }

  }



};


int main(){

  while(true){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c == 0)break;
    AOJ0107 ans = AOJ0107(a,b,c);
    ans.run();
  }
return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = br.readLine();
			System.out.println(calcTime(line));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String calcTime(String line) {
		int seconds = Integer.parseInt(line);
		int h = 0;
		int m = 0;
		int s = 0;

		s = seconds % 60;
		m = seconds / 60;
		h = m / 60;
		m = m % 60;

		return String.valueOf(h) + ':' + m + ':' + s;
	}
}


Measured memory_bytes: 24336
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<map>
#include<set>
#include<bitset>
#include<iostream>
#include<sstream>
#include<numeric>
#include<tuple>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n-1; i >= 0; i--)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y);
#define mins(x,y) x = min(x,y);
#define pb push_back
#define snuke srand((unsigned)clock()+(unsigned)time(NULL))
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

const int MX = 100005, INF = 1000000000, mod = 1000000009;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-9;
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 }; //<^>v
vector<tuple<int, int, int>> v;
int x[1009], y[1009], h[1009];
int main() {
	int n;
	tuple<int, int, int> tp = make_tuple(-1, -1, -1);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];


	}
	int H;
	for (int px = 0; px < 101; px++) {
		for (int py = 0; py < 101; py++) {
			H = 1;
			for (int k = 0; k < n; k++) {
				if (h[k] >= 1) {
					H = h[k] + abs(px - x[k]) + abs(py - y[k]);
				}
			}
			bool flg = true;
			for (int k = 0; k < n; k++) {
				if (max(H - abs(x[k] - px) - abs(y[k] - py), 0) != h[k]) {
					flg = false;
				}
			}
			if (flg == true) {
				cout << px << " " << py << " " << H << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define sort(x) sort(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int n, m;

int main(){
	int i, j;
	ll ans;
	cin >> n;
	if(n == 1)ans = 0;
	else if(n==2)ans = 1;
	else {
		ans = (ll)(n-1)*n/2;
	}
	cout << ans;
	return 0;
}


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

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

	int cnt = 0;
	if (s[0] == '1') cnt++;
	if (s[1] == '1') cnt++;
	if (s[2] == '1') cnt++;

	cout << cnt << endl;
}

Measured memory_bytes: 256
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n, x;
	cin >> n >> x;
	vector<int>a(1e+5);
	a[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		a[i] = a[i - 1] + x;
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)
	{
		if (a[i] <= x)ans++;
		else break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPracticalSkillTest solver = new DPracticalSkillTest();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPracticalSkillTest {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int h = in.nextInt(), w = in.nextInt(), hw = h * w;
            int d = in.nextInt();
            int s = (hw + d - 1) / d;
            int[][] xs = new int[d][s];
            int[][] ys = new int[d][s];
            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    int a = in.nextInt() - 1;
                    xs[a % d][a / d] = x;
                    ys[a % d][a / d] = y;
                }
            }
            int[][] sum = new int[d][s];
            for (int i = 0; i < d; i++) {
                for (int j = 1; j < s; j++) {
                    sum[i][j] = sum[i][j - 1]
                            + Math.abs(xs[i][j - 1] - xs[i][j])
                            + Math.abs(ys[i][j - 1] - ys[i][j]);
                }
            }
            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                int m = l % d;
                l /= d;
                r /= d;
                out.println(sum[m][r] - sum[m][l]);
            }
        }

    }
}



Measured memory_bytes: 98864
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n,a,b;
	int k;
	int sum = 0,psum;
	scanf("%d%d%d",&n,&a,&b);
	for (int i = 1; i <= n; ++i){
		psum = 0;
		k = i;
		for (int j = 0; j < 5; ++j)
		{
			psum += (k % 10);
			k /= 10;
		}
		if(a <= psum && psum <= b)	sum += i;
	}
	printf("%d\n", sum);
	return 0;
}


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

using namespace std;

int W,H,x,y,r;

int main(){
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if (x>=r && x<=W-r && y>=r && y<=H-r){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}



Measured memory_bytes: 3148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
    class Program
    {
        static int H = 0;
        static int W = 0;

        static void Main(string[] args)
        {
            string in1 = Console.ReadLine();
            string result = string.Empty;
            if(in1 =="A")
            {
                result = "T";
            }
            else if (in1 == "C")
            {
                result = "G";

            }
            else if (in1 == "G")
            {
                result = "C";

            }
            else if (in1 == "T")
            {
                result = "A";

            }
            Console.WriteLine(result);
        }
    }
}

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


int main(){
  ull x,a,b;
  cin >> x >> a >> b;
  if( b > a+x ){
    cout << "dangerous" << endl;
  }else if( b > a && b <= a+x ){
    cout << "safe" << endl;
  }else{
    cout << "delicious" << endl;
  }
    
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
 
namespace std{
  bool operator < ( const P &a, const P &b ){
    return (a.real()==b.real()?a.imag()<b.imag():a.real()<b.real());
  }
};
 
typedef pair<int,int> Pair;
double eps=1e-9;
 
int n;
int vw,vc;
P t[2000];
 
void func(){
  map<P , set<P> > G;
  set<P> st;
  for(int i=0;i<n;i++){
    st.insert(t[i]);
  }
   
  set<Pair> K;
  for(int i=0;i+1<n;i++){
    P v=t[i+1]-t[i];
    if(v.imag()<-eps){
      while(1){
        set<Pair> :: iterator it;
        it=K.lower_bound( Pair(t[i+1].imag(),-1) );
        if(it==K.end())break;
        if(t[i].imag() < it->first)break;
        P base=v/abs(v.imag());
        double length=t[i].imag()-it->first;
         
        st.insert(t[i]+base*length);
        //        G[ t[i]+base*length ].insert( t[it->second] );
        G[ t[it->second]  ].insert( t[i]+base*length );
         
        K.erase(it);
      }
    }
    if(v.imag()>eps){
      K.insert( Pair(t[i].imag(), i ) );
    }
  }
 
  K.clear();
  for(int i=n-1;i-1>=0;i--){
    P v=t[i-1]-t[i];
    if(v.imag()<-eps){
      while(1){
        set<Pair> :: iterator it;
        it=K.lower_bound( Pair(t[i-1].imag(),-1) );
        if(it==K.end())break;
        if(t[i].imag() < it->first)break;
        P base=v/abs(v.imag());
        double length=t[i].imag()-it->first;
 
        st.insert(t[i]+base*length);
        G[ t[i]+base*length ].insert( t[it->second] );
 
        K.erase(it);
      }
    }
    if(v.imag()>eps){
      K.insert( Pair(t[i].imag(), i ) );
    }
  }
 
  set<P> :: iterator it;
  vector<P> u;
  for(it=st.begin();it!=st.end();it++){
    u.push_back(*it);
    //    printf("%.3f %.3f\n",it->real(),it->imag());
  }
 
  vector<double> dp( st.size() , 1e30 );
  dp[0]=0;
  for(int i=0;i+1<(int)st.size();i++){
    dp[i+1]=min(dp[i+1],dp[i]+abs(u[i]-u[i+1])/(double)vw);
 
    for(it=G[u[i]].begin();it!=G[u[i]].end();it++){
      P to=*it;
      int target=lower_bound(u.begin(),u.end(),to)-u.begin();
      dp[target]=min(dp[target],dp[i]+
                     abs(u[i].real()-u[target].real())/(double)vc);
    }
  }
  printf("%.6f\n",dp.back());
}
 
int main(){
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    scanf("%d %d",&vw,&vc);
    for(int i=0;i<n;i++){
      int x,y;
      scanf("%d %d",&x,&y);
      t[i]=P(x,y);
    }
    func();
  }
  return 0;
}

Measured memory_bytes: 3676
n, a, b, c = map(int, input().split())
l = sorted([int(input()) for i in range(n)])
ans = 10**10
for order in [[a, b, c],[b, c, a],[c, a, b],[a, c, b],[b, a, c],[c, b, a]]:
    mp = 0
    l_copy = l.copy()
    for goal in order:
        tem_mp = 10**10
        used = []
        for bit in range(1, 2 ** len(l_copy)):
            length = 0
            cost = 0
            count = 0
            tem_used = []
            for j in range(len(l_copy)):
                if (bit >> j) & 1:
                    length += l_copy[j]
                    count += 1
                    if count > 1:
                        cost += 10
                    tem_used.append(j)
            if tem_mp  > abs(goal - length) + cost:
                used = tem_used
                tem_mp = abs(goal - length) + cost
        mp += tem_mp
        for u in used[::-1]:
            l_copy.pop(u)
    ans = min(ans, mp)
print(ans)

Measured memory_bytes: 3064
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    int n, m;
    std::cin >> n >> m;
    int r = n,l = 1;
    int tmp_r,tmp_l;
    int ans = 0;

    for(int i=0; i<m; i++){
        std::cin >> tmp_l >> tmp_r;
        if(tmp_l > r || tmp_r < l)
        {
            ans =  0;
            break;
        }
        else
        {
            l = std::max(l,tmp_l);
            r = std::min(r,tmp_r);
//            std::cout << l << "," << r << std::endl;
            ans = r - l + 1;
        }
    }

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

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

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

  vector<int> a(n+5);
  vector<int> b(n+5);
  vector<int> c(n+5);
  int ans = 0;

  for(int i=1;i<=n;i++){
    cin >>a.at(i);
  }

  for(int i=1;i<=n;i++){
    cin >>b.at(i);
  }

  for(int i=1;i<n;i++){
    cin >>c.at(i);
  }

  for(int i=1;i<=n;i++){
    ans += b.at(a.at(i));

    if(i != 1 & a.at(i-1) == a.at(i) - 1){
      ans += c.at(a.at(i-1));
    }
  }

  

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

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

int n;
vector<int> a;

vector<vector<vector<long long>>> dp;

long long solve(int start, int end, int turn) {
    if (start > end)
        return 0;
    if (dp[start][end][turn] == 3000000000001)
        dp[start][end][turn] = turn ? max(solve(start + 1, end, 0) + a[start], solve(start, end - 1, 0) + a[end])
                                    : min(solve(start + 1, end, 1) - a[start], solve(start, end - 1, 1) - a[end]);

    return dp[start][end][turn];
}

int main() {
    cin >> n;

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

    dp.resize(n, vector<vector<long long>>(n, vector<long long>(2, 3000000000001)));
    cout << solve(0, n - 1, 1);
}

Measured memory_bytes: 492928
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0): n(n), d(n + 1, 0) {}
  void add(int i, T x = 1) {
    if (i == 0) return;
    for (; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i > 0; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
};

int n;
char c[4040];
int a[4040];
int idb[2020], idw[2020];
int dp[2020][2020];

void init() {
  rep(i, 2020) rep(j, 2020) dp[i][j] = inf;
  dp[0][0] = 0;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  init();

  cin >> n;
  rep(i, n * 2) {
    cin >> c[i] >> a[i];
    a[i]--;
  }

  //rep(i, n * 2) cout << c[i] << ' ' << a[i] << '\n';
  rep(i, n * 2) {
    if (c[i] == 'B') idb[a[i]] = i + 1;
    else idw[a[i]] = i + 1;
  }
  //rep(i, n) cout << idb[i] << ' ' << idw[i] << '\n';
  BIT<int> b(n * 2);
  rep(i, n + 1) {
    BIT<int> w(n * 2);
    rep(j, n) {
      w.add(idw[j]);
      chmin(dp[i][j + 1], dp[i][j] + idw[j] - b.sum(idw[j]) - w.sum(idw[j]));
    }
    if (i < n) {
      b.add(idb[i]);
      BIT<int> w(n * 2);
      rep(j, n + 1) {
        chmin(dp[i + 1][j], dp[i][j] + idb[i] - b.sum(idb[i]) - w.sum(idb[i]));
        if (j == n) break;
        w.add(idw[j]);
      }
    }
  }
  cout << dp[n][n] << '\n';



  




  
  return 0;
}

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



int main() {
string A, B;
cin >> A >> B;
int a = A.size();
int b = B.size();
if(a > b) cout << "GREATER" << endl;
else if(a <b) cout << "LESS" << endl;
else{
    for(int i = 0; i < a; i++){
int ai = A[i];
int bi = B[i];
if (ai > bi){
    cout << "GREATER" << endl; 
    break;
}
else if(ai < bi){
    cout << "LESS" << endl;
    break;
}
else if(i == a-1 && ai == bi) cout << "EQUAL" << endl;
else continue;



    }





}


}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long k = sc.nextInt();
        List<Integer> ll = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            ll.add(sc.nextInt());
        }
        Collections.sort(ll);
        Collections.reverse(ll);
        long ans1 = 0;
        for (int i = 0; i < Math.min(k, n); i++) {
            ans1 += ll.get(i);
        }
        long ans2 = 0;
        for (int i = 0; i < n; i++) {
            ans2 += ll.get(i);
        }
        System.out.println(ans2 - ans1);
    }


    public static int log2(long x) {
        return (int) (Math.log(x) / Math.log(2));
    }
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);


typedef long long flow_t;
const flow_t flow_inf = 1e18;

struct edge {
	int v, u;
	flow_t c, f;
	edge(int v, int u, flow_t c): v(v), u(u), c(c), f(0) {}
};

struct Network {
	int n;
	int s, t;
	vector <edge> es;
	vector <vector <int> > g;
	Network(int n, int s, int t): n(n), s(s), t(t), g(n) {}

	void add_edge(int v, int u, flow_t c) {
		g[v].push_back(es.size());
		es.push_back(edge(v, u, c));
		g[u].push_back(es.size());
		es.push_back(edge(u, v, 0));
	}

	void add_flow(int e, flow_t f) {
		es[e].f += f;
		es[e ^ 1].f -= f;
	}
};

class DinicMaxFlow {
public:
	Network& G;

	int *pos, *d, *q;

	DinicMaxFlow(Network& G): G(G) {
		pos = new int[G.n];
		q = new int[G.n];
		d = new int[G.n];
	}
	~DinicMaxFlow() {
		delete[] pos;
		delete[] q;
		delete[] d;
	}

	int bfs() {
		const int MXD = G.n + 1;
		fill(d, d + G.n, MXD);
		d[G.s] = 0;
		q[0] = G.s;
		int l = 0, r = 1;
		while (l < r) {
			int v = q[l++];
			for (int e: G.g[v]) {
				if (G.es[e].c == G.es[e].f)
					continue;
				int u = G.es[e].u;
				if (d[u] == MXD) {
					d[u] = d[v] + 1;
					q[r++] = u; 
				}
			}
		}
		return d[G.t] < MXD;
	}

	flow_t dfs(int v, flow_t f) {
		if (v == G.t)
			return f;
		flow_t res = 0;
		for (int &i = pos[v]; i < sz(G.g[v]); ++i) {
			int e = G.g[v][i];
			int u = G.es[e].u;
			flow_t delta = min(f, G.es[e].c - G.es[e].f);
			if (delta == 0 || d[u] != d[v] + 1)
				continue;
			delta = dfs(u, delta);
			f -= delta;
			res += delta;
			G.add_flow(e, delta);
			if (f == 0)
				break;
		}
		return res;
	}



	flow_t max_flow() {
		flow_t flow = 0;
		while (bfs()) {
			fill(pos, pos + G.n, 0);
			while (flow_t plus = dfs(G.s, flow_inf))
				flow += plus;
		}
		return flow;
	}
};

int n;
pii a[222], b[222];

int main() {
//    fin("t.in");
    sync;
    cin >> n;
    Network T(2 * n + 2, 0, 2 * n + 1);
    E(i, 1, n) {
    	T.add_edge(0, i, 1);
    	cin >> a[i].X >> a[i].Y;
    }
    E(i, 1, n) {
    	T.add_edge(n + i, 2 * n + 1, 1);
    	cin >> b[i].X >> b[i].Y;
    }
    E(i, 1, n)
    	E(j, 1, n) {
    		if (a[i].X < b[j].X && a[i].Y < b[j].Y)
    			T.add_edge(i, n + j, 1);
    	}

    DinicMaxFlow D(T);
    cout << D.max_flow() << endl;
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

int n, a;

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

	cin >> n >> a;

	cout << n*n - a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct SegTree{
	vi data;
	int size;
	SegTree(int _size){
		for(int i=1;;i<<=1)
			if(i>=_size){
				size=i;
				break;
			}
		data.assign(2*size,INT_MAX);
	}
	void Update(int i,int n){
		data[size+i]=n;
		for(int j=size+i;j;j>>=1)
			data[j]=min(data[j],n);
	}
	int Query(int a,int b,int i,int l,int r){
		if(b<=l || r<=a) return INT_MAX;
		if(a<=l && r<=b) return data[i];
		int res=INT_MAX,m=(l+r)/2;
		if(a<m) res=min(res,Query(a,b,i*2+0,l,m));
		if(m<b) res=min(res,Query(a,b,i*2+1,m,r));
		return res;
	}
	int Query(int a,int b){
		return Query(a,b,1,0,size);
	}
};

int main()
{
	for(int r,c,q;scanf("%d%d%d",&r,&c,&q),r|c|q;){
		bool flg=r>c; // グリッドが縦長
		if(r>c) swap(r,c);
		vvi grid(r,vi(c));
		if(flg)
			rep(j,c) rep(i,r)
				scanf("%d",&grid[i][j]);
		else
			rep(i,r) rep(j,c)
				scanf("%d",&grid[i][j]);
		vi r1(q),c1(q),r2(q),c2(q);
		rep(i,q)
			scanf("%d%d%d%d",&r1[i],&c1[i],&r2[i],&c2[i]);
		if(flg){
			swap(r1,c1);
			swap(r2,c2);
		}
		
		vector<SegTree> st(r,SegTree(c));
		rep(i,r) rep(j,c)
			st[i].Update(j,grid[i][j]);
		
		rep(i,q){
			int mn=INT_MAX;
			repi(j,r1[i],r2[i]+1)
				mn=min(mn,st[j].Query(c1[i],c2[i]+1));
			printf("%d\n",mn);
		}
	}
	
	return 0;
}

Measured memory_bytes: 21540
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, sum;
	cin >> n >> sum;
	sum /= 1000;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; i + j <= n && i * 10 + j * 5 <= sum; j++)
		{
			if (sum - i * 10 - j * 5 == n - i - j)
			{
				printf("%d %d %d\n", i, j, n - i - j);
				exit(0);
			}
		}
	}
	puts("-1 -1 -1");
	return 0;
}


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

// S[0~n-1]
// S[i] ='L':'R'=0:1

// 全てが連続 ans = n-1
// ans = すでに連続している個数
//一度の操作で 二人反転 ans+=2
//一度の操作で一人だけ反転させるのは一箇所だけ連続していない時のみのため
// (ans+= 1) == (n-1)

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    string SS;
    cin>>SS;
    vector<int> S(n,0);
    for(int i =0; i<n; i++){
        char s = SS[i];
        if(s =='R') S[i] = 1;
    }
    int ans = 0;
    for(int i = 0; i<n-1; i++){
        if(S[i] == S[i+1]) ans++;
    }
    ans += 2*k;
    ans = min((n-1), ans);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 848
use List::Util min;
$\="\n";
$,=",";
($n,$x,$y)=glob<>;
for $i(1..$n){
  for$j(1..$i-1){
    $a[min ($i-$j,abs($j-$x)+1+abs($y-$i),abs($j-$y)+1+abs($x-$i))]++;
  }
}
for(1..$n-1){
  print($a[$_]||0)
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

long long int expmod(int base, int index, int mod) {
	long long int ret;
	if (index == 0) return 1;
	ret = expmod(base, index / 2, mod);
	ret *= ret;
	ret %= mod;
	if (index % 2 == 1) {
		ret *= base;
		ret %= mod;
	}

	return ret;
}

int main(void) {
	int N;
	map<int, int> m;

	cin >> N;

	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		m[A]++;
	}

	if (N % 2 == 1) {
		if (m[0] != 1) {
			cout << "0" << endl;
			return 0;
		}
		m[0] = 2;
	}

	for (auto itr = m.begin(); itr != m.end(); itr++) {
		if (itr->second != 2) {
			cout << "0" << endl;
			return 0;
		}
	}

	cout << expmod(2, N / 2, 1000000007) << endl;

	system("pause");

	return 0;
}

Measured memory_bytes: 3200
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

x,y = list(map(int, input().split()))

lxy = [x,y]
lxy.sort()
lxy.reverse()
x,y = lxy
delta = abs(x - y)
asum = x + y
anum = asum // 3
delta2 = (delta + anum) // 2
if asum%3 != 0 or anum < delta2:
    print(0)
else:
    X,Y = [abs(delta2), abs(anum-delta2) ]
    ans = cmb(X+Y, Y)%(10**9+7)
    print(ans)

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

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  int n, x;
  scanf("%d%d",&n, &x);
  int right, left = 0;
  ll ans = 0;
  REP(i, n){
    scanf("%d",&right);
    if((left + right) > x){
      ans += (left + right) - x;
      left = x - left;
    }
    else{
      left = right;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll a;
  cin >> a;
  ll b;
  cin >> b;

  cout << a*b << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) emplace_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> V;

int main() {
	IOS;
	int n,m,p;
	ll cur;cin>>n>>m>>p;
	cur=p;
	up(i,1,10)cur=1ll*n*cur-m,cout<<cur<<"\n";
}

Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10 ** 9 + 7

x0 = 0
for i in range(n - 1):
    x0 += (x[i + 1] - x[i]) * (i + 1) * (n - i - 1)
    x0 %= mod
y0 = 0
for i in range(m - 1):
    y0 += (y[i + 1] - y[i]) * (i + 1) * (m - i - 1)
    y0 %= mod
print(x0 * y0 % mod)

Measured memory_bytes: 18576
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

vector<ll> dijkstrasssp(ll src, vector<ll>* adjList, ll n){
    vector<ll> dis(n, INT_MAX);
    vector<ll> parent(n, 0);
    dis[src]=0;
    parent[src]=src;
    set<pair<ll, ll> > s;
    s.insert({0, src});
    while(!s.empty()) {
        auto it = s.begin();
        ll dist = it->first;
        ll node = it->second;
        s.erase(s.begin());
        for(ll ch: adjList[node]){
            if(dis[ch]>dist + 1){
                auto it1 = s.find({dis[ch], ch});
                if(it1!=s.end()){
                    s.erase(it1);
                }
                dis[ch] = dist + 1;
                parent[ch] = node;
                s.insert({dis[ch], ch});
            }
        }
    }
    return parent;
}

int main() {
    cpp();
    ll n, m;
    cin>>n>>m;
    vector<ll>* adjList = new vector<ll>[n];
    for(ll i=0; i<m; i++){
        ll u, v;
        cin>>u>>v;
        --u, --v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    vector<ll> parent = dijkstrasssp(0, adjList, n);
    for(ll i=0; i<parent.size(); i++){
        if(parent[i]==INT_MAX){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    for(ll i=1; i<parent.size(); i++){
        cout<<(parent[i]+1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 19196
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
#define N 100009
#define LL long long
#define INF 0x7fffffff
#define mymin(x,y) (x>=y?y:x)
#define mymax(x,y) (x>=y?x:y)
LL gcd(LL a, LL b) {
	if (!a) return b;
	if (!b) return a;
	if (a > b) return gcd(a % b, b);
	return gcd(a, b % a);
}
int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	LL a, b;
	cin >> a >> b;
	LL n = gcd(a, b);
	if (n == 1) {
		cout << 1;
		return 0;
	}
	LL p = 2;
	LL ans = 0;
	while (p < 1e6 && n != 1) {
		if (!(n % p)) {
			ans++;
			while (!(n % p)) {
				n /= p;
			}
		}
		p++;
	}
	if (!ans) {
		cout << 2;
		return 0;
	}
	if (n > 1e6) ans++;
	cout << ans + 1;
	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

class trie {
public:
  trie(size_t max_size) {
    size = 1; // only root
    next.assign(26, vector<int>(max_size, -1));
    end.assign(max_size, false);
    //
    count.assign(26, vector<int>(max_size, 0));
    //
  }

  bool search(string s) {
    int now = 0;
    for (char c : s) {
      if (next[c - 'a'][now] == -1) return false;
      now = next[c - 'a'][now];
    }
    return end[now];
  }

  void insert(string s) {
    int now = 0;
    vector<int> path;
    for (char c : s) {
      path.push_back(now);
      if (next[c - 'a'][now] == -1) next[c - 'a'][now] = size++;
      now = next[c - 'a'][now];
    }
    end[now] = true;

    int mask = 0;
    for (int i = s.length() - 1; i >= 0; --i) {
      mask |= 1 << (s[i] - 'a');
      for (int j = 0; j < 26; ++j)
        if (mask >> j & 1) count[j][path[i]]++;
    }
  }
  //
  int solve(string s, char x) {
    int now = 0;
    for (char c : s) now = next[c - 'a'][now];
    return count[x - 'a'][now];
  }
  //

private:
  vector<vector<int>> next;
  vector<bool> end;
  //
  vector<vector<int>> count;
  //
  int size;
};

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  trie tr(1000001);
  rep(i, 0, n) {
    cin >> a[i];
    reverse(a[i].begin(), a[i].end());
    tr.insert(a[i]);
  }
  int ans = 0;
  rep(i, 0, n) {
    char last = a[i].back();
    a[i].pop_back();
    ans += tr.solve(a[i], last) - 1;
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
	int n, q, query, x, t;
	
	cin>>n>>q;
	
	queue<int> hoge[n];
	
	for(int i = 0; i < q; i++){
		cin>>query>>t;
		
		if(query == 0){
			cin>>x;
			hoge[t].push(x);
		} else if(query == 1){
			if(!hoge[t].empty())cout<<hoge[t].front()<<endl;
		} else {
			if(!hoge[t].empty())hoge[t].pop();
		}
	}
	
	return 0;
}


Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
ll n;
vector<ll>graph[100005];
ll dp[100005][2];
ll func(ll src,ll col,ll par)
{
    if(graph[src].size()==1 and graph[src][0]==par)
    {
        if(col==1)
            return 2;
        else
            return 1;
    }
    else if(dp[src][col]!=-1)
        return dp[src][col];
    ll ans=1,x=1;
    for(auto it:graph[src])
    {
        if(it!=par)
        {
            if(col==1)
                ans=(ans*func(it,0,src))%mod;
            x=(x*func(it,1,src))%mod;
        }
    }
    if(col==1)
        dp[src][col]=(x+ans)%mod;
    else
        dp[src][col]=x;
    return dp[src][col];
}
int main()
{
// #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
        cin>>n;
        for(ll i=1;i<=n-1;i++)
        {
            ll a,b;
            cin>>a>>b;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
        memset(dp,-1,sizeof(dp));
        ll ans=0;
        ans=func(1,1,-1);
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 14208
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    double a,b,x,sp;
    cin >> a >> b >> x;
    sp =(b-(x/a/a))*2;
    if(sp <= b) printf("%.10lf",atan2(sp,a)/asin(1)*90);
    else printf("%.10lf",(1 - atan2(x/a/b*2,b)/asin(1))*90);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <regex>
#include<ext/numeric>
#include<ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v)  (int)v.size()
#define WHITE -1
#define GREY   0
#define BLACK  1
#define CLR(a,v) memset(a,v,sizeof a)
#define PC(x) __builtin_popcount(x)
#define PCLL(x) __builtin_popcountll(x)
#define MP make_pair

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
//typedef unsigned int ui;

typedef complex<double> point;
//#define X real()
//#define Y imag()
#define vec(a,b) ((b)-(a))
#define dot(a,b) ((conj(a)*(b)).real())
#define cross(a,b) ((conj(a)*(b)).imag())
#define colliner pointOnLine
#define same(a,b) (lengthSqr(vec(a,b))<EPS)
#define lengthSqr(v) (dot(v,v))

const double PI = acos(-1.0);

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

int DX[] = { 1, 1, -1, -1, 2, 2, -2, -2 };
int DY[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

const int MAX = 135, MOD = 1e9 + 7, oo = (1 << 30), MAXLOG = 20;
const ll OO = 1ll << 60;
const double EPS = 1e-9;

string s, t;
int cst;
bool vis[26];

bool bad(int c) {
	for (int i = 0; i < sz(t); ++i)
		if (t[i] - 'a' != c)
			return 1;
	return 0;
}

int main() {

	cin >> s;
	int n = sz(s);
	for (int i = 0; i < n; ++i)
		vis[s[i] - 'a'] = 1;
	cst = oo;
	for (int i = 0; i < 26; ++i) {
		if (!vis[i])
			continue;
		t = s;
		int cnt = 0;
		while (sz(t) > 1 && bad(i)) {
			for (int j = 0; j < sz(t) - 1; ++j)
				if (t[j] - 'a' == i || t[j + 1] - 'a' == i)
					t[j] = (i + 'a');
			t.erase(sz(t) - 1, 1);
			++cnt;
		}
		cst = min(cst, cnt);
	}
	printf("%d\n", cst);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> l(n+1);
  int diff = 0;
  for(int i=1; i<=n; i++) {
    cin >> l[i];
    if(i != l[i]) {
      diff++;
    }
  }
  if(diff <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3612
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include<climits>
using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(i == 0 && a[i] == i+1){
      int tmp = a[i];
      a[i] = a[i+1];
      a[i+1] = tmp;
      cnt++;
    }else{
      if(a[i] == i + 1){
        if(i+1 != N && a[i+1] == i + 2){
          int tmp = a[i];
          a[i] = a[i+1];
          a[i+1] = tmp;
          cnt++;
        }else{
          int tmp = a[i];
          a[i] = a[i-1];
          a[i-1] = tmp;
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    int n; cin >> n;
    vector<long long> a(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        sum += x;
        a[i] = sum;
    }
    long long ans = 2e9;
    for (int i = 0; i < n - 1; i++) {
        ans = min(ans, abs(a[n - 1] - (2 * a[i])));
    }
    cout << ans;
}


Measured memory_bytes: 4756
N, A, B = [int(i) for i in input().split()]
Hn = [int(input()) for _ in range(N)]
dAB = A - B

def check(X):
  base = B * X
  counts = sum([max((h - base + dAB - 1)//dAB, 0) for h in Hn])
  return counts <= X
               
def min_binary_search(check, l=0, r=100000000000):
    while r - l > 1:
      mid = (l + r) // 2
      if check(mid):
        r = mid
      else:
        l = mid
    return r
print(min_binary_search(check))

Measured memory_bytes: 10936
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse = True)
af = [[ai * fi, ai, fi] for ai, fi in zip(a, f)]
af.sort()
def calc(cand):
    cost = 0
    for afi, ai, fi in af:
        if cand < afi:
            cost += ai - cand // fi
            if cost > k:
                return False
    return True

left = 0
right = af[-1][0]
while True:
    mid = (right + left) // 2
    if mid == left:
        if calc(left):
            print(left)
        else:
            print(right)
        break
    if calc(mid):
        right = mid
    else:
        left = mid


Measured memory_bytes: 127428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[200005];
ll a[200005];;
struct RMQ{
	#define s (1<<20)
	ll seg[s];
	void init(){
		fill(seg,seg+s,-1e18);
	}
	void update(int k,ll a){
		k+=s/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	ll query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return -1e18;
		if(a<=l && r<=b) return seg[k];
		else{
			ll vl=query(a,b,k*2+1,l,(l+r)/2);
			ll vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return max(vl,vr);
		}
	}
}rmq;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&h[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	rmq.init();
	rmq.update(0,0);
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ll v = rmq.query(0,h[i]-1,0,0,s/2-1);
		rmq.update(h[i],v+a[i]);
		ans=max(ans,v+a[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 10752
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, k = nm()
    a = nl()
    ng = 0
    ok = max(a) + 1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        cur = 0
        for x in a:
            cur += (x - 1) // mid
        if cur > k:
            ng = mid
        else:
            ok = mid
    print(ok)
    return

solve()


Measured memory_bytes: 31096