akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll N,ans,keta=0;

int main(){
    cin>>N;
    for(int i=sqrt(N);i>=1;i--){
        if(N%i==0){
            ans=N/i;
            break;
        }
    }
    while(ans){
        ans/=10;
        keta++;
    }
    out(keta);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	bool a[30];
	
	for(int i = 1; i <= 30; i++){
		a[i] = true;
	}
	
	int num;
	
	for(int i = 0; i < 28; i++){
		cin >> num;
		a[num] = false;
	}
	
	for(int i = 1; i <= 30; i++){
		if(a[i]){
			printf("%d\n", i);
		}
	}
	
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void solve() {
	int n; cin >> n;
	int l[200]; rep(i, 2 * n) cin >> l[i];
	sort(l, l + 2 * n);
	reverse(l, l + 2 * n);
	int ans = 0;
	for (int i = 1; i < 2 * n; i += 2) {
		ans += l[i];
	}
	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}


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

using namespace std;
typedef long long ll;

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

  if (n > 999) cout << "ABD" << "\n";
  else cout << "ABC" << "\n";
}


Measured memory_bytes: 3644
#問題数n
n = int(input())
#それぞれの問題にかかる時間t
t = input().split()
#ドリンクの種類m
m = int(input())
#ドリンクを飲んだときに問題pを解くのにかかる時間x
for i in range(m):
  p, x = map(int, input().split())
  ans = 0
  for j in range(n):
    if p == j + 1:
      ans += x
    else:
      ans += int(t[j])
  print(ans)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cstdio>

//#include <cstdint>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <climits>
#include <functional>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <ctime>

#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forn1(i, n) for(int i = 1; i <= int(n); i++)
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld PI = acosl(ld(-1));
const ld EPS = 1e-11;

template <typename T> inline T sqr(const T& x) {
	return x * x;
}

template <typename T> inline T abs(const T& x) {
	return x > 0 ? x : -x;
}

inline bool inside(int x, int y, int n, int m) {
	return x >= 0 && x < n && y >= 0 && y < m;
}

inline int rnd() {
	return abs(rand() ^ (rand() << 15));
}

inline int rnd(int n) {
	assert(n > 0);
	return rnd() % n;
}

inline int rnd(int lf, int rg) {
	return lf + rnd(rg - lf + 1);
}

inline li rndLL() {
	return rnd() * 1LL * rnd() + rnd();
}

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

const int N = int(2e5) + 555;



inline void gen() {
	return;
}

inline bool read() {
	return true;
}

inline void solve() {
	string s;
	cin >> s;
	forn(i, sz(s)) forn(j, i) if (s[j] == 'C' && s[i] == 'F') {
		puts("Yes");
		return;
	}
	puts("No");
	return;
}

int main() {
#ifdef _DEBUG
	assert(freopen("input.txt", "rt", stdin));
	assert(freopen("output.txt", "wt", stdout));
#endif

	cout << setprecision(10) << fixed;
	cerr << setprecision(10) << fixed;

	srand(int(time(NULL)));

	int T = 1;
	//#define MULTITEST
#ifdef MULTITEST
	assert(scanf("%d", &T) == 1);
#endif

	forn(i, T) {
#ifdef _DEBUG
		cerr << "TEST == " << i << endl;
#endif
		assert(read());
		solve();
	}

#ifdef _DEBUG
	cerr << "TIME == " << clock() << " ms" << endl;
#endif
	return 0;
}

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

int main(){
  int n; cin >> n;
  
  bool ans = false;
  
  for(int i = 1; i < 10; i++){
  for(int j = 1; j < 10; j++){
  
  	if(i*j == n){
    	ans = true;
    }
  
  }
  }
  
  if(ans){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

const e = ["dream", "dreamer", "erase", "eraser"];

void main()
{
  string s; readV(s);

 loop: while (!s.empty) {
    foreach (ei; e) {
      if (s.endsWith(ei)) {
        s = s[0..$-ei.length];
        continue loop;
      }
    }

    writeln("NO");
    return;
  }

  writeln("YES");
}


Measured memory_bytes: 508
#include<cstdio>
#include<utility>

using namespace std;

int abs(int x){
    if (x > 0) return x;
    else return -x; 
}

int main(){
    int H,W,D;
    scanf("%d %d %d", &H, &W, &D);
    int A[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            scanf("%d", &A[i][j]);
        }
    }
    int Q;
    scanf("%d", &Q);
    int L[Q], R[Q];
    for(int i = 0; i < Q; i++){
        scanf("%d %d", &L[i], &R[i]);
    }
    int n = H * W;
    int a[n];
    pair<int, int> p[n];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            p[A[i][j]-1].first = i;
            p[A[i][j]-1].second = j;
        }
    }
    for(int i = 0; i < D; i++){
        a[i] = 0;
        for(int j = i + D; j < H * W; j += D){
            a[j] = a[j-D] + abs(p[j].first - p[j-D].first) + abs(p[j].second - p[j-D].second);
        }
    }
    // for(int i = 0; i < H*W; i++){
    //     printf("<%d %d> ", p[i].first, p[i].second);
    // }
    
    // for(int i = 0; i < H*W; i++){
    //     printf("%d ", a[i]);
    // }
    // puts("");
    
    for(int i = 0; i < Q; i++){
        printf("%d\n", a[R[i]-1] - a[L[i]-1]);
    }
    
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define N 1000002
#define mod 1000000007
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mxN = 1e5 + 5;
int h[mxN];
int cache[mxN];
int n,k;
int dp(int idx){
	if(idx==n)
		return 0;
	if(idx>n)
		return INT_MAX;
	int &ans = cache[idx];
	if(ans!=-1)
		return ans;
	int best = INT_MAX;
	for(int i = 1;i<=k;i++){ 
		if(idx+i<=n)
			best = min(abs(h[idx+i] - h[idx]) + dp(idx+i),best);
	}
	return ans = best;
}
void solve(){
	cin>>n;cin>>k;
	memset(cache,-1,sizeof(cache));
	for(int i = 1 ; i <= n;i++)
		cin>>h[i];
	cout<<dp(1)<<'\n';
}
int main() {	
	// IOS
	ll T;
	// cin>>T;
	
	T = 1;
	// ll i = 1;
	while(T--){
		// cout<<"Case #"<<i<<": ";
		
		solve();
		// i++;
	}
	return 0;
	
}

Measured memory_bytes: 12156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            String[] values = line.split(",");
            double x1 = Double.parseDouble(values[0]);
            double y1 = Double.parseDouble(values[1]);
            double x2 = Double.parseDouble(values[2]);
            double y2 = Double.parseDouble(values[3]);
            double xq = Double.parseDouble(values[4]);
            double yq = Double.parseDouble(values[5]);
            double xr = -xq;
            double yr = yq;
            if (x1 != x2) {
                double a = (y2 - y1) / (x2 - x1);
                xr = -2.0 * a / (1 + a * a) * (y1 - yq - a * (x1 - xq)) + xq;
                yr = 2.0 / (1 + a * a) * (y1 - yq - a * (x1 - xq)) + yq;
            }
            out.println(xr + " " + yr);
        }
    }
}

Measured memory_bytes: 9792
#include <stdio.h>

int n, a[1000000];
int solve(int i, int m) {
  if ( m == 0 ) return 1;
  if ( i >= n ) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - a[i]);
  return res;
}

int main(void){
  int i, q, m, tmp;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &m);
    if ( solve(0, m) ) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2680
def count(s1, s2):
    dst = 0
    for c1, c2 in zip(s1, s2):
        if c1 != c2: dst+=1

    return dst

def execute(S, T):
    dst = len(T)

    for i in range(len(S) - len(T)+1):
        s = S[i:i+len(T)]
        c = count(s, T)
        if c < dst:
            dst = c

    return dst

if __name__ == '__main__':
    S = input()
    T = input()

    print(execute(S, T))

Measured memory_bytes: 9040
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	pair<long long, long long>s[60], sc[60];
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> s[i].first >> s[i].second;
	for (int i = 1; i <= m; i++){
		pair<long long, long long>c; cin >> c.first >> c.second;
		for (int j = 0; j < n; j++){
			long long dis = abs(s[j].first - c.first) + abs(s[j].second - c.second);
			if (i == 1 || sc[j].second > dis) {
				sc[j].first = i;
				sc[j].second = dis;
			}
		}
	}
	for (int i = 0; i < n; i++)cout << sc[i].first << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(long long i=m;i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




int main(){

    int n;
    cin>>n;



    cout<<(1000-n%1000)%1000<<endl;







}

Measured memory_bytes: 3624
num = STDIN.gets.chomp.to_i
target = STDIN.gets.chomp.split(' ').map(&:to_f)

def average(target)
  le = target.length
  tmp = target.inject(:+) / le
  tmp.round
end

avg = average(target)
result = 0
target.each do |t|
 result += (t.to_i - avg).abs ** 2
end
p result





Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct M {
  using T = lint;
  static T op(const T a, const T b) { return max(a, b); }
  static constexpr T e() { return numeric_limits<T>::min(); }
};

template<class M> struct ST {
  using T = typename M::T;
  int n;
  V<T> t;

  ST(int n) : n(n) {
    t.assign(2 * n, M::e());
  }

  void build() {
    for (int i = n - 1; i; i--) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }

  T get(int l, int r) {
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) { 
      if (l & 1) resl = M::op(resl, t[l++]); 
      if (r & 1) resr = M::op(t[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    for (t[i += n] = a; i >>= 1;) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  V<lint> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  VV<lint> dp; assign(dp, 2, n + 1);
  for (int i = 1; i < k + 1; i++) {
    ST<M> st(n + 1);
    for (int j = 0; j < n + 1; j++) st.t[j + n + 1] = dp[i - 1 & 1][j];
    st.build();
    for (int j = i; j < n + 1; j++) {
      dp[i & 1][j] = i * a[j - 1] + st.get(max(j - m, 0), j);
    }
  }
  cout << *max_element(dp[k & 1].begin(), dp[k & 1].end()) << '\n';
}


Measured memory_bytes: 4224
#include <stdio.h>

int main() {
  int a,b,c;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);

  if (a < b && a < c) {
    if (b < c)
      printf("%d %d %d\n", a, b, c);
    else
      printf("%d %d %d\n", a, c, b);
  } else if (b < a && b < c) {
    if (a < c)
      printf("%d %d %d\n", b, a, c);
    else
      printf("%d %d %d\n", b, c, a);
  } else {
    if (a < b)
      printf("%d %d %d\n", c, a, b);
    else
      printf("%d %d %d\n", c, b, a);
  }

  return 0;
}



Measured memory_bytes: 1784
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    string str;
    cin>>str;
    str[5]=' ';
    str[13]=' ';
    cout<<str<<endl;
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int, input().split()))
lis[0] -= 1
for i in range(n - 1):
    if lis[i] < lis[i + 1]:
        lis[i+1] -= 1
    elif lis[i] > lis[i + 1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
 int x, a, b;
  cin >> x >> a >>b;
  
  if(b <= a) cout << "delicious" << endl;
  else if(a < b && b <= a+x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_2_A&lang=ja
//DPL_2_A
//巡回セールスマン問題,Traveling Salesman Problem
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

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>
struct node {
	vector<edge<T>> edges;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll V,E; cin>>V>>E;
  WeightedGraph<ll> graph(V);
  REP(i,E){
    ll s,t,d; cin>>s>>t>>d;
    graph.at(s).edges.emplace_back(t,d);
  }
  ll bit_max=1LL<<V;
  ll INF=2LL<<60;
  vector<vector<ll>> dp(V,vector<ll>(bit_max,INF));
  dp[0][0]=0;//0からスタート
  // FOR(i,0,V){
  //   dp.at(i).at(0)=0;
  // }
  FOR(m,0,bit_max){
    FOR(i,0,V){
      for(const auto&e:graph.at(i).edges){
        ll next_m = m|(1LL<<e.to);
        if(next_m==m) continue;
        chmin(dp[e.to][next_m], dp[i][m]+e.cost);
      }
    }
  }
  dump(dp);
  // ll ans=INF;
  // REP(i,V){
  //   chmin(ans,dp[i][bit_max-1]);
  // }
  ll ans=dp[0][bit_max-1]; //0ゴールの値
  if (ans>=INF) ans=-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7064
#include<bits/stdc++.h>
using namespace std;
int h,w,a,b;
const int N=200010;
int fac[N],inv[N];
const int mod=1000000007;
int qp(int x,int k)
{
	int res=1;
	while(k)
	{
		if(k&1)res=1ll*res*x%mod;
		x=1ll*x*x%mod;
		k>>=1;
	}
	return res;
}
void init()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<N;i++)
		fac[i]=1ll*fac[i-1]*i%mod;
	inv[N-1]=qp(fac[N-1],mod-2);
	for(int i=N-2;i>=1;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int C(int a,int b)
{
	if(a<b)return 0;
	return 1ll*fac[a]*inv[b]%mod*inv[a-b]%mod;
}
int ans;
int main()
{
	init();
	scanf("%d%d%d%d",&h,&w,&a,&b);
	ans=C(h-1+w-1,h-1);
	for(int i=1;i<=min(a,b);i++)
		ans=(ans-1ll*C(h-a+b-1,b-i)*C(w-b+a-1,a-i)%mod+mod)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
n=int(input())
x=[0]*101
ans=0
for i in range(1,n+1):
    v=str(i)
    w=int(v[0]+v[-1])
    x[w]+=1

for i in range(101):
    if x[i]!=0:
        v=str(i)
        w=int(v[-1]+v[0])
        ans+=x[i]*x[w]
print(ans)

Measured memory_bytes: 40428
#include <iostream>
#include <cmath>

using namespace std;

int n, k, res, a[105];

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

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

	int res1 = 0, res2 = 0;
	for (int i = 0; i < n; ++i)
	{
		res1 = a[i] * 2;
		res2 = abs(a[i] - k) * 2;

		res += (res1 < res2) ? res1 : res2;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[][] house1 = new int[3][10];
		int[][] house2 = new int[3][10];
		int[][] house3 = new int[3][10];
		int[][] house4 = new int[3][10];
		StringBuilder output = new StringBuilder();
		
		// 入居者数の初期化
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 10; j++) {
				house1[i][j] = 0;
				house2[i][j] = 0;
				house3[i][j] = 0;
				house4[i][j] = 0;
			}
		}
		
		// 入居者数の更新
		int infonum = scan.nextInt();
		for (int i = 0; i < infonum; i++) {
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			if (b == 1) {
				house1[f-1][r-1] += v;
			}
			if (b == 2) {
				house2[f-1][r-1] += v;
			}
			if (b == 3) {
				house3[f-1][r-1] += v;
			}
			if (b == 4) {
				house4[f-1][r-1] += v;
			}
		}
		
		// 出力
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 10; j++) {
				output.append(" ").append(house1[i][j]);
			}
			output.append('\n');
		}
		output.append("####################").append('\n');
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 10; j++) {
				output.append(" ").append(house2[i][j]);
			}
			output.append('\n');
		}
		output.append("####################").append('\n');
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 10; j++) {
				output.append(" ").append(house3[i][j]);
			}
			output.append('\n');
		}
		output.append("####################").append('\n');
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 10; j++) {
				output.append(" ").append(house4[i][j]);
			}
			output.append('\n');
		}
		System.out.print(output);
	}

}

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

int main(){
	int N, W;
	cin >> N >> W;
	vector<ll> w(N), v(N);
	for (int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
	}

	ll w1 = w[0];
	vector<vector<ll>> x(4);
	for (int  i = 0; i < N; i++){
		ll id = w[i] - w1;
		x[id].push_back(v[i]);
	}

	for (int i = 0; i < 4; i++){
		sort(x[i].begin(), x[i].end(), greater<ll>());
	}

	array<array<ll, 100>, 4> d;
	for (int i = 0; i < d.size(); i++) d[i].fill(0);
	for (int i = 0; i < 4; i++){
		d[i][0] = 0;
		for (int j = 1; j <= x[i].size(); j++){
			d[i][j] += d[i][j - 1] + x[i][j - 1];
		}
	}

	ll res = 0;
	for (int i = 0; i <= x[0].size(); i++){
		for (int j = 0; j <= x[1].size(); j++){
			for (int k = 0; k <= x[2].size(); k++){
				for (int l = 0; l <= x[3].size(); l++){
					ll sum_w = (j + 2*k + 3*l) + w1*(i + j + k + l);
					if (sum_w > W) continue;

					ll sum_v = d[0][i] + d[1][j] + d[2][k] + d[3][l];
					res = max(res, sum_v);
				}
			}
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


const int MAX = 101;
vector<int> d[MAX];
int cz[MAX];
int sn[MAX];
int sm[MAX];
bool dfs(int v){
  if(cz[v])return 0;
  cz[v] = 1;
  for(int el:d[v]){
    if(sm[el] == -1 || dfs(sm[el])){
      sn[v] = el;
      sm[el] = v;
      return 1;
    }
  }
  return 0;
}
int n,m;
int a[MAX][MAX];
void wys(){
  R(i,n){
    R(j,m)
      cout << a[i][j] + 1 << " ";
    cout << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  R(i,n)R(j,m){
    cin >> a[i][j];a[i][j]--;
  }
  R(_,m){
    R(i,n){
      d[i].clear();
      for(int j = _; j < m; j++)
        d[i].PB(a[i][j]/m);
    }
    R(i,n){
      sn[i] = sm[i] = -1;
      cz[i] = 0;
    }
    bool x = 1;
    while(x){
      x = 0;
      R(i,n)cz[i] = 0;
      R(i,n)if(sn[i] == -1)if(dfs(i)){
        x = 1;
      }
    }
    R(i,n){
      for(int j = _; j < m; j++){
        if(a[i][j] / m == sn[i]){
          swap(a[i][_], a[i][j]);
          break;
        }
      }
    }
  }
  wys();
  R(j,m){
    vector<int> pom;
    R(i,n)pom.PB(a[i][j]);
    sort(ALL(pom));
    R(i,n)a[i][j] = pom[i];
  }
  wys();
}


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	
	int ans = 1;
	for(int i=2 ; i<=n ; i++)
	{
	    for(int j=i*i ; j<=n ; j*=i)
	        ans = max(ans , j);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import sys

class Stack:
    def __init__(self, max):
        self.max = max
        self.stack = list(range(max))
        self.top = 0

    def push(self, value):
        if self.top == self.max:
            raise IndexError('?????????????????????????????????')

        self.stack[self.top] = value
        self.top += 1

    def pop(self):
        if self.top == 0:
            raise IndexError('??????????????????????????¨??????')

        self.top -= 1
        return self.stack[self.top]

def main():
    expr = sys.stdin.readline().strip().split(' ')
    stack = Stack(100)
    
    for i in expr:
        if i == '*' or i == '+' or i == '-':
            n1 = stack.pop()
            n2 = stack.pop()
            ans = eval(n2 + i + n1)
            stack.push(str(ans))
        else:
            stack.push(i)

    print(stack.pop())
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 7560
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  set<string> s;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    s.insert(w[i]);
  }

  bool flag = true;
  for (int i = 0; i < n - 1; i++) {
    if (w[i][w[i].size()-1] != w[i+1][0]) {
      flag = false;
    }
  }
  if (s.size() != n) {
    flag = false;
  }

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

  return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=0;i<=(n);i++)

int main(){
	int n = 0, k = 0;
	char s[100] = {};

	cin >> n >> k;

	rep(i, n) cin >> s[i];

	s[--k] += 'a' - 'A';

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A,B;
  int sum=0;
  scanf("%d %d",&A,&B);
  if(A>B){
    sum += A;
    A--;
  }else{
    sum += B;
    B--;
  }
  if(A>B){
      sum += A;
    A--;
  }else{
    sum += B;
    B--;
  }
  printf("%d\n",sum);
  return 0;
}
    

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	int ans=0;
	if(abs(a-c)<=d) ans=1;
	else if(abs(a-b)<=d&&abs(b-c)<=d) ans=1;
	
	cout<<((ans)?"Yes":"No")<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(int i=n;i<=N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define piii pair<int,pii>
#define piiii pair<pii,pll>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 1e6+5;
const ll MAX2 = 11;
const ll MOD = 1010205047;
const ll MOD2 = 1000005329;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 200;

ll n,q,x[MAX],z,a,b,ans;
 
int main(){
//	cout<<fixed<<setprecision(10);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    rep(i,1,n)cin>>x[i], ans^=x[i];
    rep(i,1,n)cout<<(x[i]^ans)<<" "; cout<<endl;
	return 0;
}

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

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


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

using namespace std;

int main() {
  int x, ans = 1;
  scanf("%d", &x);
  for (int i = 0; i < 32; i++) {
    if (i * i <= x) {
      ans = i * i;
    }
  }
  for (int i = 0; i < 11; i++) {
    if (i * i * i > ans && i * i * i <= x) {
      ans = i * i * i;
    }
  }
  for (int i = 0; i < 6; i++) {
    if (i * i * i * i > ans && i * i * i * i <= x) {
      ans = i * i * i * i;
    }
  }
  for (int i = 0; i < 5; i++) {
    if (i * i * i * i * i > ans && i * i * i * i * i <= x) {
      ans = i * i * i * i * i;
    }
  }
  for (int i = 0; i < 4; i++) {
    if (i * i * i * i * i * i > ans && i * i * i * i * i * i <= x) {
      ans = i * i * i * i * i * i;
    }
  }
  for (int i = 0; i < 10; i++) {
    int a = 2;
    for (int j = 0; j < i; j++) {
      a *= 2;
    }
    if (a > ans && a <= x) {
      ans = a;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List 

main :: IO ()
main = do
    ns <- map read . words <$> getLine
    putStrLn $ show (length (qsort ns))
    
qsort :: [Int] -> [Int]
qsort []   = []
qsort (x:xs) = qsort smaller ++ [x] ++ qsort larger
               where
                  smaller = [a | a <- xs, a < x]
                  larger  = [b | b <- xs, b > x]

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

#define fst first
#define snd second
#define fore(i,a,b) for(int i=a, ThxDem=b; i<ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define SZ(s) int(s.size())
#define DBG(x) cerr <<#x << " = " << (x) << "\n"

#define SQR(x) ((x) * (x))

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 11

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<bool> vbool;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vbool> vvbool;

int main(){FIN
	ll n;
	cin >> n;
	vll dp(3),ns(3),aux;
	fore(i,0,n){
		fore(j,0,3)cin >> ns[j];
		aux.assign(3,0);
		fore(j,0,3){
			fore(k,0,3){
				if(j!=k) aux[k] = max(aux[k],dp[j]+ns[k]);
			}
		}
		dp = aux;
	}
	cout << max(dp[0],max(dp[1],dp[2])) << "\n";
	return 0;
}


Measured memory_bytes: 3520
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dif = [A[i] - B[i] for i in range(N)]
if sum(A) < sum(B):
  print(-1)
else:
  dif.sort()
  if dif[0] >= 0:
    print(0)
  else:
    p, n = N - 1, 0
    while dif[n] < 0:
      n += 1
    ms = sum(-dif[i] for i in range(n))
    S = dif[p]
    num = n + 1
    while S < ms:
      p -= 1
      S += dif[p]
      num += 1
    print(num)

Measured memory_bytes: 18620
#!/usr/bin/env python3
import sys
import heapq
INF = float("inf")


class Graph(object):

    def __init__(self, N):
        self.N = N
        self.E = []

    def add_edge(self, edge):
        """
        args:
          edge : (from_, to_, weight)
        """
        s, t, w = edge
        if s > t:
            s, t = t, s
        self.E.append([s, t, w])


class UnionFind(object):
    """UnionFind木
    """

    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, i):
        if self.tree[i] == i:
            return i
        else:
            self.tree[i] = self.root(self.tree[i])
            return self.tree[i]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.tree[x] = y


def solve(N: int, x: "List[int]", y: "List[int]"):

    XYN = sorted(zip(x, y, range(N)))
    YXN = sorted(zip(y, x, range(N)))
    edges = []
    for i in range(N-1):
        (x1, y1, n1), (x2, y2, n2) = XYN[i:i+2]
        heapq.heappush(edges, [min(abs(x1-x2), abs(y1-y2)), n1, n2])
        (y1, x1, n1), (y2, x2, n2) = YXN[i:i+2]
        heapq.heappush(edges, [min(abs(x1-x2), abs(y1-y2)), n1, n2])
    tot, counter = 0, 0
    group = UnionFind(N)
    while len(edges) > 0 and counter <= N:
        w, f, t = heapq.heappop(edges)
        if not group.same(f, t):
            tot += w
            counter += 1
            group.unite(f, t)

    print(tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65936
n,x = gets.split.map &:to_i
a = gets.split.map &:to_i

s = 0
i = 0
while i != n-1
    y = a[i]+a[i+1]-x
    if y > 0
        if a[i+1] >= y
            a[i+1] -= y
        else
            a[i] = a[i] - (y-a[i+1])
            a[i+1] = 0
        end
        s += y
    end
    i += 1
end
p s

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int n,d,a;
	cin>>n>>d>>a;
	vector<pair<int,int>> v;
	int x,h;
	for(int i=0;i<n;i++)
	{
		cin>>x>>h;
		v.push_back({x,h});
	}
	sort(v.begin(),v.end());
	int c=0;
	int b[n+2];
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++)
	{
		b[i+1]+=b[i];
		int t1=(v[i].second+a-1)/a;
		t1-=b[i+1];
		t1=max(0ll,t1);
		b[i+1]+=t1;
		c+=t1;
		int l=i+1,r=n-1;
		int a1=i;
		while(l<=r)
		{
			int m=(l+r)/2;
			if((v[m].first-v[i].first)<=2*d)
			{
				l=m+1;
				a1=m;
			}
			else
				r=m-1;
		}
		//cout<<c<<" "<<a1<<" "<<t1<<endl;
		b[a1+2]-=t1;
	}
	cout<<c<<endl;
	return 0;
}



Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;

double eps=1e-7;
bool eq(double a,double b){
  double EPS = max( abs(a) , abs(b) ) * eps;
  EPS=max(EPS,eps);
  return (-EPS<a-b&&a-b<EPS);
}

double cross(P a,P b){
  return imag(b*conj(a));
}

double dist(P a,P b,P c){
  b-=a;c-=a;
  return cross(b,c)/abs(b);
}

P reflect(P a,P b,P c){
  b-=a;c-=a;
  return a+conj(c/b)*b;
}

int N;
P t[1000];
map<int, map<int,bool> > mp;

bool check(P a,P b){
  bool res=true;
  int cnt=0;
  for(int i=0;i<N;i++){
    if( eq( 0, dist(a,b,t[i])) ){cnt++;continue;}
    P target=reflect(a,b,t[i]);
    int px=round(target.real());
    int py=round(target.imag());
    if(!eq(px,target.real()))res=false;
    if(!eq(py,target.imag()))res=false;
    if(mp.count(px)==0)res=false;
    if(mp[px].count(py)==0)res=false;
  }
  if(cnt>1 && cnt%2==1 )res=false;
  return res;
}

bool solve(){
  P b=t[0];
  int cnt=0;
  for(int i=1;i<N;i++){
    b+=t[i];
    double v=cross(t[1]-t[0],t[i]-t[0]);
    if(eq(v,0))cnt++;
  }
  if(cnt==N-1)return false;

  b/=(double)N;
  
  bool flag=false;
  for(int i=0;i<N;i++){
    P a=t[i];
    if( eq(0, abs(a-b) ) )continue;
    if(check(a,b))flag=true;
  }

  for(int i=1;i<N;i++){
    P c=t[0];
    P d=t[i];
    P nc=(c+d)*0.5;
    P nd=nc+(d-c)*P(0,1);
    if(check(nc,nd))flag=true;
  }  
  return flag;
}

int main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++){

    int x,y;
    scanf("%d %d",&x,&y);
    t[i]=P(x,y);
    mp[x][y]=true;
    for(int j=0;j<i;j++)assert(t[i]!=t[j]);
  }
  printf( solve() ? "Yes\n" : "No\n" );
  return 0;
}

Measured memory_bytes: 6972
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int cnt = s.nextInt();
		String[] values = new String[cnt];

		for(int i=0 ; i<cnt ; i++) {
			values[i] = s.next();
		}
		String[] before = (String[]) values.clone();
		String[] v = (String[]) values.clone();

		bubbleSort(values);
		checkStable(before, values);
		selectionSort(v);
		checkStable(before, v);
	}

	public static void bubbleSort(String[] values){
		for(int i=0 ; i<values.length ; i++) {
			for(int j = values.length-1 ; j > i ; j--) {
				if(new Integer(values[j].substring(1, 2)).intValue() < new Integer(values[j-1].substring(1, 2)).intValue()) {
					String tmp = values[j-1];
					values[j-1] = values[j];
					values[j] = tmp;
				}
			}
		}
		String dispStr = "";
		for(int i=0 ; i<values.length ; i++) {
			if(i != values.length - 1)
				dispStr += values[i] + " ";
			else
				dispStr += values[i];
		}
		System.out.println(dispStr);
	}

	public static void selectionSort(String[] values) {
		for(int i=0 ; i<values.length ; i++) {
			int mini = i;
			for(int j=i ; j<values.length ; j++) {
				if(new Integer(values[mini].substring(1, 2)).intValue() > new Integer(values[j].substring(1, 2)).intValue()) {
					mini = j;
				}
			}
			String tmp = values[mini];
			values[mini] = values[i];
			values[i] = tmp;
		}
		String dispStr = "";
		for(int i=0 ; i<values.length ; i++) {
			if(i != values.length - 1)
				dispStr += values[i] + " ";
			else
				dispStr += values[i];
		}
		System.out.println(dispStr);
	}

	public static void checkStable(String[] before, String[] after) {
		String[] beforeSuit = new String[4];
		String[] afterSuit = new String[4];

		for(int i=1 ; i<10 ; i++) {
			int beforeIndex = 0;
			int afterIndex = 0;
			for(int j=0 ; j<before.length ; j++) {
				if(i == new Integer(before[j].substring(1, 2)).intValue()) {
					beforeSuit[beforeIndex] = before[j].substring(0, 1);
					beforeIndex++;
				}
			}

			for(int k=0 ; k<after.length ; k++) {
				if(i == new Integer(after[k].substring(1, 2)).intValue()) {
					afterSuit[afterIndex] = after[k].substring(0, 1);
					afterIndex++;
				}
			}

			for(int l=0 ; l<4 ; l++) {
				if(beforeSuit[l] == null || afterSuit[l] == null)
					continue;
				if(! beforeSuit[l].equals(afterSuit[l])) {
					System.out.println("Not stable");
					return;
				}
			}
			beforeSuit = new String[4];
			afterSuit = new String[4];
		}
		System.out.println("Stable");
	}
}

Measured memory_bytes: 18424
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}

int main(){
    string s;cin >> s;
    int n = s.size();
    vector<vector<ll>> dp(n+1, vector<ll>(4,0));
    for(int i = n; 0 <= i; --i){
        for(int j = 3; 0 <= j; --j){
            if(i == n){
                dp[i][j] = (j == 3 ? 1 : 0);
            }
            else{
                dp[i][j] += dp[i+1][j] * (s[i] == '?' ? 3 : 1);
                if(j < 3 && (s[i] == '?' || s[i] == "ABC"[j])){
                    dp[i][j] += dp[i+1][j+1];
                }
            }
            dp[i][j] %= MOD;
        }
    }

    // rep(i,n+1){
    //     rep(j,4)print(i,j,dp[i][j]); 
    // }
    cout << dp[0][0] << endl;
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n;
    cin >> n;
    vll h(n);
    vector<bool> is_low(n, false);
    vi count(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        if (h[i] >= h[i + 1]) is_low[i] = true;
    }
    int cnt = 0;
    for (int i = 0; i < is_low.size(); ++i) {
        if (is_low[i]) {
            cnt++;
        } else {
            count.pb(cnt);
            cnt = 0;
        }
    }
    sort(count.begin(), count.end(), greater<int>());
    cout << count[0] << endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int tapSize = sc.nextInt();
    int target = sc.nextInt();
    int tapCnt = 1;
    int useTap = 0;
    while(tapCnt < target){
      tapCnt--;
      tapCnt += tapSize;
      useTap++;
    }
    
    System.out.println(useTap);
  }
}

Measured memory_bytes: 22996
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

ll a[110], b[110];

int main() {
	
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		ll a, b;
		cin >> a >> b;
		if (a > b)swap(a, b);

		ll ans = 0;
		ans += 2 * (a - 1);
		if (a == b||a+1==b) {
			cout << ans << endl;
		}
		else {

			ll ok = 0;
			ll ng = b-a+1;
			while (abs(ok - ng) > 1) {
				ll mid = (ok + ng) / 2;
				if ((a+mid)*(a+mid) < a*b) {
					ok = mid;
				}
				else {
					ng = mid;
				}
			}
			ans += ((a+ok)*(a+ok+1)<a*b)?2*ok+1:2*(ok);
			if (ok == 0)ans = 2 * (a - 1)+1;
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
	out << "(" << P.first << ", " << P.second << ")";
	return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
int n , m ;
string s;
int dp[200005];
int go[200005];
int32_t main(){
	cin>>n>>m>>s;
	rep(i, 0 , 200000) dp[i] = (int) 1e9 , go[i] = -1;
	dp[n] = 0;
	go[n] = -1;
	deque<int> dq;
	dq.push_back(n);
	for(int j = n-1 ; j >= 0 ; j--){
		if(s[j] == '1') continue;
		while(dq.size() && dq.front() > j +m){
			dq.pop_front();
		}
		if(dq.size()){
			dp[j] = dp[dq.front()] +1;
			go[j] = dq.front();
			while(dq.size() && dp[dq.back()] >= dp[j]){
				dq.pop_back();
			}
			dq.push_back(j);
		}
 	}
 	if(dp[0] == (int) 1e9){
 		cout<<-1<<endl;
 		return 0;
 	}
 	else{
 		int curr = 0;
 		while(curr != n){
 			cout<< go[curr] - curr <<" ";
 			curr = go[curr];
 		}
 	}
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, a, b, c, d;
    vector<map<int, int>> mp(2);
    vector<set<pii>> st(2);
    cin >> n;
    fore(i,0,n) {
        cin >> a;
        mp[i&1][a]++;
    }
    fore(i,0,2) {
        st[i].insert({0, -1});
        for (auto &x : mp[i]) {
            st[i].insert({x.S, x.F});
        }
    }
    auto it1 = st[0].rbegin();
    auto it2 = st[1].rbegin();
    int ans = 0;
    if (it1->S != it2->S) {
        ans = n-(it1->F)-(it2->F);
    } else {
        a = it1->F;
        b = next(it1)->F;
        c = it2->F;
        d = next(it2)->F;
        ans = n-max(a+d, b+c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9600
#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 long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N; i++)
    cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll ans = 0;

  for (int j = 0; j < N; j++)
  {
    ll numA = lower_bound(A.begin(), A.end(), B[j]) - A.begin();
    ll numC = N - (upper_bound(C.begin(), C.end(), B[j]) - C.begin());
    ans += numA * numC;
  }

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

// Ai < Bj < Ckなる組(i, j, k)を求める問題．jを固定すればAi < Bjなるiの数とBj < Ckなるkの数の個数の積となり1重ループで解くことが出来る．
// あるパーツを調べてlower_boundとupper_boundで条件を満たすパーツを調べる
// Aの使える個数はlower_bound(A.begin(), A.end(), B[j]) - A.begin()
// upper_boundはある値より初めて大きい値が出た時のイテレータを返す


Measured memory_bytes: 2560
#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>;

int main(){
    string s;
    cin >> s;
    ll n;
    n=s.size();
    ll a=0,b=0;
    rep(i,n){
        if(i%2==0){
            if(s[i]=='0'){
                ++a;
            }
            else{
                ++b;
            }
        }
        else{
            if(s[i]=='1'){
                ++a;
            }
            else{
                ++b;
            }
        }
    }    

    cout << min(a,b) << endl;

    return 0;
}

Measured memory_bytes: 3740
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 300005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

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

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");
	
	int N, M;
	scanf("%d %d", &N, &M);
	vector <int> dp(N + 1, 0);
	dp[0] = dp[1] = 1;

	vector <int> a(M);
	for (int j = 0; j < M; j++) scanf("%d", &a[j]);
	int ptr = 0;
	for (int i = 0; i <= N; i++) {
		if (ptr < M and a[ptr] == i) dp[a[ptr]] = 0, ptr++;
		else if(i >= 2) dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
	}
	printf("%d\n", dp[N]);
	return 0;
}

Measured memory_bytes: 1024