akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;

int main(){
    int N; cin>>N;
    vector<ll> W(N+1);
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    for(int i = N-1; i > 0; i--){
        if(i==N-1)W[i] = A[i];
        else{
            W[i] = W[i+1] + A[i];
            W[i] %= MOD;
        }
    }
    ll res = 0;
    rep(i,N-1){
        res += W[i+1]*A[i];
        res %= MOD;
    }
    cout<<res%MOD<<endl;
}


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

int main() {
  int M,D;
  cin >> M >> D;
  int ans = 0;
  
  for(int i=1; i<=M; i++){
    for(int j=1; j<=D ;j++){
      if(j/10 >= 2 && j%10 >= 2){
        if((j/10)*(j%10) == i){
          ans += 1;
        }
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main()
{
  string S; cin >> S;
  
  int x,y;
  for (int i=0; i<S.size(); i++) { 
    if (S.at(i) == 'A') {
      x = i;
    break;
    }
  }
  
  for (int i=0; i<S.size(); i++) {   
    if (S.at(i) == 'Z') {
      y = i;
    }
  }
  
  cout << y - x + 1<< endl;  
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
        long K = sc.nextLong();
        long D = sc.nextLong();
        long res;
        long tika = Math.abs(X)/D;
        if(K<=tika){
            res = Math.abs(X) - D*K;
        }else if((K-tika)%2==0){
            res = Math.abs(X) - D*tika;
        }else{
            res = D*(tika+1) - Math.abs(X);
        }
		System.out.println(res);
	}
}

Measured memory_bytes: 35236
#include <stdio.h>

int main(void){
	int D;
	scanf("%d",&D);
	if(D == 25){
		printf("Christmas");
	}else if(D == 24){
		printf("Christmas Eve");
	}else if(D == 23){
		printf("Christmas Eve Eve");
	}else if(D == 22){
		printf("Christmas Eve Eve Eve");
	}

	return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int n;
int main() {
    scanf("%d%s", &n, s);
    int tag1 = 0, tag2 = 0, tag3 = 0;
    n--;
    for (int i = 0; i <= n; i++) {
        int now = s[i] - '0';
        if (now == 2) tag2 = 1;
        if ((i & n) == i) tag1 ^= now & 1, tag3 ^= ((now - 1) / 2) & 1;
    }
    return cout << (tag1 ? 1 : tag2 ? 0 : tag3 ? 2 : 0) << endl, 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>
#include <functional>

using namespace std;
using ll = long long;
using ld = double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll, ll>;
const ll INF = 1e17;
const ld eps = 1e-10;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	string s;
	cin >> s;
	s = "." + s + ".....";
	bool ans = true;
	if (C < A || D < B)
		ans = false;
	else {
		if ((A < B) != (C < D)) { // ぬかす
			if (B < A) {
				swap(A, B);
				swap(C, D);
			}
			while (s[B - 1] == '#' || s[B + 1] == '#') {
				if (s[B + 1] == '.')
					B++;
				else if (s[B + 2] == '.')
					B += 2;
				else {
					ans = false;
					break;
				}
			}
			if (D < B) {
				ans = false;
			}
		}
		if (ans) {
			while (A < C) {
				if (s[A + 1] == '.')
					A++;
				else if (s[A + 2] == '.')
					A += 2;
				else {
					ans = false;
					break;
				}
			}
			while (B < D) {
				if (s[B + 1] == '.')
					B++;
				else if (s[B + 2] == '.')
					B += 2;
				else {
					ans = false;
					break;
				}
			}
		}
	}
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}






Measured memory_bytes: 720
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    if(x==1&&y==1){
      System.out.println(1000000);
      return;
    }
    int ans = 0;
    if(x==1)ans+=300000;
    if(x==2)ans+=200000;
    if(x==3)ans+=100000;
    if(y==1)ans+=300000;
    if(y==2)ans+=200000;
    if(y==3)ans+=100000;
    System.out.println(ans);
  }
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
int P[MAXN], R[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> P[i + 1];

    return true;
}

void solve() {
    for (int i = 1; i <= n; ++i)
        R[P[i]] = i;

    ll ans = 0;
    set<int> st;
    st.insert(0);
    st.insert(n + 1);

    for (int i = 1; i <= n; ++i) {
        int m = R[i];
        int l = *(--st.upper_bound(m));
        int r = *st.upper_bound(m);
        st.insert(m);
        ans += 1ll * i * (m - l) * (r - m);
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 14464
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int main(void){
	int N,A[100010],B[100010],C[100010];
	ll ans=0;
	scanf("%d",&N);
	rep(i,N)scanf("%d",&A[i]);
	rep(i,N)scanf("%d",&B[i]);
	rep(i,N)scanf("%d",&C[i]);
	sort(A,A+N);
	sort(C,C+N);
	rep(i,N){
		ll c;
		//Biを固定
		if(A[0]>=B[i]){
			c=0;
		}else if(A[N-1]<B[i]){
			c=N;
		}else{
			int l=0,r=N-1;//lが可能
			while(r-l>1){
				int mid = (r+l)/2;
				if(A[mid]<B[i]){
					l = mid;
				}else{
					r = mid;
				}
			}
			c=l+1;
		}
		if(B[i]>=C[N-1]){
			c*=0;
		}else if(B[i]<C[0]){
			c*=N;
		}else{
			int l=0,r=N-1;//rが可能
			while(r-l>1){
				int mid = (r+l)/2;
				if(B[i]<C[mid]){
					r = mid;
				}else{
					l = mid;
				}
			}
			c*=N-r;
		}
		ans+=c;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int n;

void f(string s, int i) {
  if(s.size() == n) {
    cout << s << endl;
    return;
  }
  rep2(j, 1, i + 2) {
    string ns = s + (char)('a' + j - 1);
    f(ns, max(i, j));
  }
}

int main() {
  cin >> n;
  f("a", 1);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    string s;
    cin >> s;
    string t = "CODEFESTIVAL2016";
    int count = 0;
    for(int i = 0;i < 16;++i) {
        if(s.at(i) != t.at(i)) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
//vector<int> g1;
//g1.push_back(i);

using namespace std;
ll tzero;

void count0 (ll a)
{
	if (a>=5)
	{
		tzero = tzero+(a/5);
		return count0(a/5);
	}
}
int main()
{
	ll n;
	cin >> n;
	if (n%2==1) cout << 0;
	else 
	{
		ll no5 = n/10;
		tzero = no5;
		count0(no5);
		cout << tzero;
	}
}



Measured memory_bytes: 256
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Tue Jan 22 16:26:07 2019
//
package main

import "fmt"

func main() {
	var s int
	fmt.Scan(&s)

	arr := []int{s}
	for s != 1 {
		if s%2 == 0 {
			s /= 2
		} else {
			s = 3*s + 1
		}
		arr = append(arr, s)
	}

	arr = append(arr, []int{4, 2, 1}...)
	for i := range arr {
		for j := i + 1; j < len(arr); j++ {
			if arr[i] == arr[j] {
				fmt.Println(j + 1)
				return
			}
		}
	}

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;

int main() {
    string s;cin>>s;
    int i = 0,ans = 0;
    int left = 0,right = s.size()-1;
    while(1) {
        if(left>=right) {
            cout << ans;
            return 0;
        }

        if(s[left] == s[right]) {
            left++;
            right--;
        } else if(s[left] == 'x') {
            ans++;
            left++;
        } else if(s[right] == 'x') {
            ans++;
            right--;
        } else {
            cout << -1;
            return 0;
        }
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll com(ll r, ll c) {
  vector<ll> prime(r + 1, 0);
  for (ll i = r; i > r - c; --i) {
    ll now = i;
    for (ll j = 2; j * j <= i; ++j) {
      while (now % j == 0) {
        prime.at(j) += 1;
        now /= j;
      }
      if (now == 1) {
        break;
      }
    }
    if (now != 1) {
      prime.at(now) += 1;
    }
  }
  for (ll i = c; i >= 2; --i) {
    ll now = i;
    for (ll j = 2; j * j <= i; ++j) {
      while (now % j == 0) {
        prime.at(j) -= 1;
        now /= j;
      }
      if (now == 1) {
        break;
      }
    }
    if (now != 1) {
      prime.at(now) -= 1;
    }
  }
  ll res = 1;
  for (ll i = 1; i < r + 1; ++i) {
    res *= pow(i, prime.at(i));
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, P;
  cin >> N >> P;
  ll odd = 0;
  ll even = 0;
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (a % 2 == 1) {
      odd += 1;
    }
    else {
      even += 1;
    }
  }
  ll ans = 0;
  if (P % 2 == 0) {
    for (ll i = 0; i <= odd / 2; ++i) {
      ans += com(odd, i * 2);
    }
  }
  else {
    for (ll i = 0; i < odd / 2; ++i) {
      ans += com(odd, i * 2 + 1);
    }
  }
  ans *= pow(2, even);
  cout << ans << "\n";
}


Measured memory_bytes: 4020
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll val[3010][3010],dp[3010][3010][5];
int main(){
    int R,C,K;cin>>R>>C>>K;
    memset(val,0,sizeof(val));
    memset(dp,0,sizeof(dp));
    for(int i=0;i<K;++i){
        int r,c,v;cin>>r>>c>>v;
        val[r][c]=v;
    }
    for(int i=0;i<=R;++i){
        for(int j=0;j<=C;++j){
            for(int k=0;k<=3;++k){
                if(i>0){
                    dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
                    dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+val[i][j]);
                }
                if(j>0){
                    dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
                    if(k>0) dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+val[i][j]);
                }
            }
        }
    }
    ll ans=0;
    for(int k=0;k<=3;++k){
        ans=max(ans,dp[R][C][k]);
    }
    cout<<ans<<endl;
    return 0;
}

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

#include "atcoder/string.hpp"

#define LOG(FMT...) fprintf(stderr, FMT)

#define fir first
#define sec second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

ostream& operator<<(ostream& os, const pair<char, int>& unit) {
  return os << unit.first << "^" << unit.second;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  auto sa = atcoder::suffix_array(s);
  auto lcp = atcoder::lcp_array(s, sa);
  int n = s.length();
  ll ans = n * (n + 1LL) / 2 - accumulate(lcp.begin(), lcp.end(), 0LL);
  cout << ans << '\n';

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
      -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}



Measured memory_bytes: 15664
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

module Util =
    let strRev s =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

let esieve upper =
    let res = Array.create (upper + 1) true
    res.[0] <- false
    res.[1] <- false
    for n in 2 .. upper do
        if res.[n] then
            for m in 2 .. upper do
                let l = int64 n * int64 m
                if l <= int64 upper then res.[int l] <- false
    res

[<EntryPoint>]
let main _ =
    let Q = read int
    let lr = Array.zeroCreate Q
    for i in 0 .. Q - 1 do
        lr.[i] <- reada int

    let lim = int 1e5 + 1
    let sieve = esieve lim
    let vs = Array.zeroCreate lim
    for i in 0 .. lim - 1 do
        if sieve.[i] && sieve.[(i + 1) / 2] then vs.[i] <- 1
    let acc = Array.zeroCreate (lim + 1)
    for i in 0 .. lim - 1 do
        acc.[i + 1] <- acc.[i] + vs.[i]

    for i in 0 .. Q - 1 do
        let [| l; r |] = lr.[i]
        let ans = acc.[r + 1] - acc.[l]
        printfn "%d" ans
    0 // return an integer exit code


Measured memory_bytes: 26160
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
    int n, w; cin >> n >> w;
    vector<ll> val(n), wt(n);
    for(int i = 0; i < n; i++)
        cin >> wt[i] >> val[i];
    vector<ll> dp(w+1, 0);
    for(int i = 0; i < n; i++) {
        for(int j = w; j >= 0; j--){
            if(j >= wt[i]) {
                dp[j] = max(dp[j], dp[j-wt[i]] + val[i]);
            }
        }
    }
    cout << dp[w] << endl;
}

Measured memory_bytes: 3996
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    string s = read!string;

    auto a = s.indexOf('A');
    auto b = s.lastIndexOf('Z');
    writeln(b - a + 1);
}


Measured memory_bytes: 764
#include<stdio.h>
int main()
{
    double area,r,c;
    scanf("%lf",&r);
    area=3.14159265358979323846264338327950288419716939937510582097494459230781*r*r;
    c=2*3.14159265358979323846264338327950288419716939937510582097494459230781*r;
    printf("%lf %lf\n",area,c);
}



Measured memory_bytes: 2100
fun main(args: Array<String>) {

    val s = readLine()!!

    val (l, r) = s.chunked(2).map { it.toInt() }
    
    val yymm = r in (1..12)
    val mmyy = l in (1..12)

    if (yymm) {
        if(mmyy){
            println("AMBIGUOUS")
        }else{
            println("YYMM")
        }
    } else {
        if(mmyy){
            println("MMYY")
        }else{
            println("NA")
        }
    }
}

fun String.chunked(size: Int): List<String> {
    val nChunks = length / size
    return (0 until nChunks).map { substring(it * size, (it + 1) * size) }
}


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

string grid[500];
int pos[26][2][2];
bool use[26];
int n,m;
int res;

bool cluck(int y,int x){
  int k;
  int cnt[26];
  for(int i=0;i<26;i++)cnt[i] = 0;

  k = 1;
  while(y+k<n && grid[y+k][x] == '.')k++;
  if(y+k<n)cnt[grid[y+k][x]-'A']++;

  k = 1;
  while(x+k<m && grid[y][x+k] == '.')k++;
  if(x+k<m)cnt[grid[y][x+k]-'A']++;

  k = 1;
  while(y-k>=0 && grid[y-k][x] == '.')k++;
  if(y-k>=0)cnt[grid[y-k][x]-'A']++;

  k = 1;
  while(x-k>=0 && grid[y][x-k] == '.')k++;
  if(x-k>=0)cnt[grid[y][x-k]-'A']++;

  bool f = false;
  for(int i=0;i<26;i++){
    if(cnt[i]>=2){
      res += 2;
      f = true;
      for(int j=0;j<n;j++){
	for(int k=0;k<m;k++){
	  if(grid[j][k] == 'A'+i)grid[j][k] ='.';
	}
      }
    }
  }
  return f;
}

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++)cin >> grid[i];

  res = 0;
  while(1){
    bool f = false;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(grid[i][j]=='.')f |= cluck(i,j);
      }
    }
    if(!f)break;
  }

  cout << res << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

bool isOK(vector<int> &a, int index, int key)
{
    if (a[index] >= key)
        return true;
    else
        return false;
}
int binary_search(vector<int> &a, int key)
{
    int left = -1;             //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;
        if (isOK(a, mid, key))
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int>b(m);

    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];

    int ans = 0;
    
    vector<ll>c(m+1,0);
    
    //累積和
    for(int i = 0; i < m; i++){
        c[i+1] = c[i] + b[i];
    }

    ll t = 0;

    //にぶたん
    for(int i = 0; i <= n; i++){ //aから1冊ずつ確認
        if(i != 0){
            t += a[i - 1];
        }
        if(t > k)break;
        int l = -1; //index = 0が条件を満たすこともあるから、初期値は-1
        int r = m + 1; // index = m のとき条件を満たさない可能性もあるため、初期値は m より一つ大きめ

        while(r - l > 1){
            int mid = (r + l) / 2;

            if(t + c[mid] <= k){
                l = mid;
            }else{
                r = mid;
            }
        }
        ans = max(ans,i+l);
    }
    
    cout << ans << endl;


}

Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int S;
    cin >> S;
    int A,a;
    A = S / 100;
    a = S % 100;
    //cout << A << " " << a << endl;
    if(0 < A && 0 < a && A <= 12 && a <= 12) cout << "AMBIGUOUS" << endl;
    else if(0 < A && A <= 12) cout << "MMYY" << endl;
    else if(0 < a && a <= 12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int sum = 0;
	for (int i = 0; i < M; i++) {
		int A;
		cin >> A;
		sum += A;
	}
	if (sum > N) cout << -1 << endl;
	else cout << N - sum << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  string t;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='0' || s.at(i)=='1'){
      t+=s.at(i);
    }
    if(t.size()!=0 && s.at(i)=='B'){
      t.erase(t.end()-1);
    }
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 256
/*input
ATCODER
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> v;
int main()
{
	IOS;
	string s;
	cin>>s;
	REP(i,SZ(s))
		if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') v.pb(1);
		else v.pb(0);
	int ans=0;
	int l=0;
	v.pb(0);
	REP(i,SZ(v)){
		if(v[i]==0){
			ans=max(ans,i-l);
			l=i+1;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void insertionsort(int *A,int n){
		int i,j,k,v;
		
		for(i=1;i<n;i++){

			for(k=0;k<n-1;k++){
			printf("%d ",A[k]);
			}
			
			printf("%d\n",A[n-1]);
			v = A[i];
			j = i-1;
			while(j>=0&&A[j]>v){
				A[j+1]=A[j];
				j--;
				A[j+1]=v;
				
			}
			
		}
		
			for(k=0;k<n-1;k++){
			printf("%d ",A[k]);
			}
			printf("%d\n",A[n-1]);
}
	
	





int main(){
  int n,i,A[1000];
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  insertionsort(A,n);

  return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int f(int n){
    int ans=0;
    for(int x=1;x*x<n;x++){
        for(int y=1;x*x+y*y+x*y<n;y++){
            int N=n-(x*x+y*y+x*y);
            int d=x+y;
            int s=d*d+4*N;
            if((int)sqrt(s)*(int)sqrt(s)==s){
                int z=-d+sqrt(s);
                if(z%2==0){
                    z/=2;
                    if(z>0)ans++;
                    //cout<<x<<" "<<y<<" "<<z<<endl;
                }
            }
        }
    }
    return ans;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cout<<f(i)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3604
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
  p = i - 1
  while p >= 0 and A[p] > A[p + 1]:
    A[p], A[p + 1] = A[p + 1], A[p]
    p -= 1
  for j in range(N):
    print(A[j], end = " \n"[j + 1 == N])


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

typedef long long ll;
#define endl "\n"

const int M = (int) 1e9+7;
int n,k;
ll ans=1;
vector<ll> pos, neg;
int pcnt=0, ncnt=0;

ll solve(){
    cin>>n>>k;
    for (int i=0; i<n; ++i){
        ll foo; cin>>foo;
        if (foo>0) pos.push_back(foo);
        else neg.push_back(abs(foo));
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int P=pos.size(), N=neg.size();
    if (k==n ? N%2==0 : P || k%2==0){
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        for ( ; k; --k){
            if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[ncnt])){
                ans=ans*pos[pcnt]%M; ++pcnt;
            }
            else{
                ans=ans*neg[ncnt]%M; ++ncnt;
            }
        }
        if (ncnt&1){
            ans=1;
            if (pcnt<P && ncnt>=1 && (ncnt>=N || pcnt<1 || pos[pcnt]*pos[pcnt-1]>neg[ncnt]*neg[ncnt-1])){
                for (int tt=0; tt<pcnt+1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt-1; ++tt)
                    ans=ans*neg[tt]%M;
            }
            else{
                for (int tt=0; tt<pcnt-1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt+1; ++tt)
                    ans=ans*neg[tt]%M;
            }
        }
        return ans;
    }
    for(; k; --k) {
        if(pcnt<P &&(ncnt>=N || pos[pcnt]<neg[ncnt])) {
            ans=ans*pos[pcnt]%M; ++pcnt;
        }
        else {
            ans=ans*neg[ncnt]%M; ++ncnt;
        }
    }
    return (M-ans)%M;
}

int main(){
    // INT VS LL
    // freopen("input.txt", "r", stdin);
    //    INT VS LL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<solve();
    return 0;
}


Measured memory_bytes: 5624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int h = Integer.parseInt(lines[0]);
            int w = Integer.parseInt(lines[1]);
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if((i+j)%2==0){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 31036
#include <stdio.h>

int main(){
    char b;
    b=getchar();
    if (b=='A'){
        printf("T\n");
    }else if(b=='T'){
        printf("A\n");
    }else if(b=='G'){
        printf("C\n");
    }else if(b=='C'){
        printf("G\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<string> S(N);rep(i,N)cin >> S[i];

    map<char,LL> m;
    rep(i,N){
        char t = S[i][0];
        if(t == 'M' || t == 'A' || t == 'R' || t == 'C' || t == 'H')m[t]++;
    }

    vector<LL> st;
    for(auto t : m){
        st.push_back(t.S);
    }

    int lim = st.size();

    LL ans = 0;

    rep(i,lim)for(int j = i+1;j < lim-1;j++)for(int k = j+1;k < lim;k++){
        ans += st[i]*st[j]*st[k];
    }

    cout << ans << endl;
}


Measured memory_bytes: 6144
i=3;main(n,j){for(scanf("%d",&n);j=n-i+1&~1,n>3&5e3<j;i+=3);for(i=n-j;i;printf(n<4?i=0,"2 3 25":"%d ",2*i--))for(;j;printf("%d ",6*j---3));}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,x,a[MAXN];
int main()
{
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int ans=0;
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]>x)
        {
            printf("%d\n",ans);
            return 0;
        }
        ans++;
        x-=a[i];
    }
    if(x) ans--;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc102/tasks/abc102_b
# Python 3rd Try
import sys


def solve(cells):
    answer = 0
    cells.sort(reverse=True)
    answer = cells[0] - cells[-1]
    return answer


if __name__ == "__main__":
    X = list(map(int, sys.stdin.readline().split()))
    AI = list(map(int, sys.stdin.readline().split()))
    print(solve(AI))


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, A[200001] = {}, B[200001] = {}, timeMemo = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		B[i] = B[i] * 1e6 + i;
	}
	stable_sort(B, B + N + 1);
	for (int i = 1; i <= N; i++) {
		timeMemo += A[B[i] % 1000000];
		if (timeMemo > B[i] / 1000000) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long N = scan.nextLong();
    String[] alp = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    long dec = 0;
    StringBuilder sb = new StringBuilder();
    while(N / 27 > 0){
      dec = N % 26;
      if (dec == 0) {
        dec = 26;
        N = N - 1;
      }
      int d = (int)dec;
      sb.append(alp[d - 1]);
      N = N / 26;  
    }
    dec = N % 26;
    if (dec == 0) {
      dec = 26;
    }
    int d = (int)dec;
    sb.append(alp[d - 1]);
    StringBuffer str = new StringBuffer(sb);
    String Name = str.reverse().toString();
    System.out.println(Name);
  }
}



Measured memory_bytes: 35764
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n,x,t;
  cin>>n>>x>>t;
  cout<<(n+x-1)/x*t<<'\n';
  
  return 0;
}
//2020.08.22 20:00:48


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

int mine(int h, int w, vector<vector<char>> map, int x, int y) {
  if (x < 0 || x >= w) {
    return 0;
  }
  if (y < 0 || y >= h) {
    return 0;
  }
  return (map[x][y] == '#') ? 1 : 0;
}

int main() {
  int h, w;
  cin >> h;
  cin >> w;
  vector<vector<char>> map;
  map.resize(w);
  for(int i = 0; i < w; i++) {
    map[i].resize(h);
  }
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> map[j][i];
    }
  };

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if (map[j][i] == '#') {
	continue;
      }
      int cnt = 0;
      cnt += mine(h, w, map, j - 1, i - 1);
      cnt += mine(h, w, map, j - 1, i);
      cnt += mine(h, w, map, j - 1, i + 1);
      cnt += mine(h, w, map, j, i - 1);
      cnt += mine(h, w, map, j, i + 1);
      cnt += mine(h, w, map, j + 1, i - 1);
      cnt += mine(h, w, map, j + 1, i);
      cnt += mine(h, w, map, j + 1, i + 1);
      map[j][i] = '0' + cnt;
    }
  }

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cout << map[j][i];
    }
    cout << endl;
  };
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

ll dp[200000];
ll h[200000];
ll MAX_len = 200000000000;

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    for(ll i=0;i<sizeof(dp)/sizeof(*dp);i++){
        dp[i]=MAX_len;
        h[i] = -1;
    }
    
    for(ll i=0;i<N;i++){
        cin >> h[i];
    }
    
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    
    for(ll i=2;i<N;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    
    cout << dp[N-1] << endl;
                  
                  

    
    
    

    
    return 0;
}




Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int n; lint c; cin >> n >> c;
    vector<pair<lint, lint> > sushi;
    rep(i, n){
        lint x, v; cin >> x >> v;
        sushi.push_back(make_pair(x, v));
    }
    sort(all(sushi));

    vector<lint> f(100001), g(100001);
    f[0] = 0; g[0] = 0;
    lint sumv = 0;
    rep(i, n){
        sumv += sushi[i].second;
        f[i + 1] = max(f[i], sumv - sushi[i].first);
        g[i + 1] = max(g[i], sumv - sushi[i].first * 2);
    }

    lint sumb = 0;
    lint res = max(f[n], g[n]);
    repr(i, n){
        sumb += sushi[i].second;
        lint b = c - sushi[i].first;
        res = max(res, max(sumb - b * 2 + f[i], sumb - b + g[i]));
    }

    cout << res << endl;
}

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

int main() {
  long long int n = 0;
  cin >> n;
  long long int a = 0, b = 0, c = 0, d = 0, e = 0;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  
  long long int addtime = ceil((double) n / (double) min(a, min(b, min(c, min(d, e)))));
  cout << 4 + addtime << endl;
}

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

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++)
#define all(v) v.begin(),v.end()
#define v vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    string s;
    cin >> s;
    rep(i, 3){
        cout << s[i];
    }
    cout << endl;
}

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

int main()
{
    int W, a1, b1, a2, b2;
    int ans, res;

    cin >> W >> a1 >> b1; a2 = a1 + W; b2 = b1 + W;
    ans = a1 - b1;
    if ((a1 < b2 and a2 > b1) or (b1 < a2 and b2> a1))
    {
        cout << 0 << endl;
        return 0;
    }
    if (ans < 0 ) ans *= -1;
    res = a1 - b2;
    if (res < 0) res *=-1;
    if (ans > res) ans = res;
    res = a2 - b1;
    if (res < 0) res *=-1;
    if (ans > res) ans = res;
    res = a2 - b2;
    if (res < 0) res *=-1;
    if (ans > res) ans = res;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


// https://kyopro-friends.hatenablog.com/entry/2019/01/12/231106
vector<vector<ll> > dp(1001, vector<ll>(20001));

bool comp(tuple<int, int, int> a, tuple<int, int, int> b) {
  int wi, si, vi, wj, sj, vj;
  tie(wi, si, vi) = a;
  tie(wj, sj, vj) = b;
  // 上から i, j がいいか, j, i がいいか
  // 大きいほうが嬉しい
  if (min(si, sj - wi) <= min(sj, si - wj)) return 0; // debuged, b < a to 0
  return 1;
}

void solve() {
  int n;
  cin >> n;
  vector<tuple<int, int, int> > d(n);
  rep(i, n) {
    int w, s, v;
    cin >> w >> s >> v;
    d[i] = make_tuple(w, s, v);
  }

  sort(all(d), comp);
  rep(i, n) {
    int w, s, v;
    tie(w, s, v) = d[i];
    // cout << w << " " << s << " " << v << endl;
    rep(j, s + 1) {
      chmax(dp[i + 1][j + w], dp[i][j] + v);
    }
    rep(j, 20001) chmax(dp[i + 1][j], dp[i][j]);
  }
  ll ma = 0;
  rep(i, n + 1) chmax(ma, *max_element(all(dp[i])));
  cout << ma << endl;
  // rep(i, n + 1) { rep(j, 40) cout << dp[i][j] << " "; cout << endl; }
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  string ans;
  if(c-a<=d&&a-c<=d) ans ="Yes";
  else if (b-a<=d&&a-b<=d&&c-b<=d&&b-c<=d) ans ="Yes";
  else ans = "No";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
s = input()
ans,x,s = 0,["A","T","G","C"],s+"X"
for i in range(len(s)):
    if s[i] in x:
        for j in range(i+1,len(s)):
            if s[j] not in x: break
        ans = max(ans,j-i)
print(ans)

Measured memory_bytes: 3060
// 座圧debut
// よくわからない.
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

#define inRange(x,a,b) (a <= x && x <= b)
#define N 1000
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int w, h, n;
int X1[N], X2[N], Y1[N], Y2[N];

// 座圧後の配列には線分の両端点の+1,0,-1の3点が残る可能性がある(?)
// よって2*3で6倍
bool mat[6*N][6*N];

int compress(int *x1, int *x2, int width){
    vector<int> xs;

    for(int i = 0; i < n; i++){
        for(int d = -1; d <= 1; d++){
            int dx1 = x1[i]+d, dx2 = x2[i]+d;
            if(inRange(dx1, 0, width))  xs.push_back(dx1);
            if(inRange(dx2, 0, width))  xs.push_back(dx2);
        }
    }

    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());

    for(int i = 0; i < n; i++){
        x1[i] = distance(xs.begin(), find(xs.begin(), xs.end(), x1[i]));
        x2[i] = distance(xs.begin(), find(xs.begin(), xs.end(), x2[i]));
    }

    return xs.size()-1;
}

int main(){
    while(cin >> w >> h, w+h){
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
        }
        
        w = compress(X1, X2, w);
        h = compress(Y1, Y2, h);

        memset(mat, 0, sizeof(mat));

        for(int i = 0; i < n; i++){
            for(int y = Y1[i]; y < Y2[i]; y++){
                for(int x = X1[i]; x < X2[i]; x++){
                    mat[y][x] = true;
                }
            }
        }

        // for(int i = 0; i < h; i++){
        //     for(int j = 0; j < w; j++){
        //         cout << mat[i][j] << " ";
        //     }
        //     cout << endl;
        // }

        int ans = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(mat[i][j])   continue;

                ans++;
                queue<pair<int,int>> q;
                q.push({i,j});

                while(!q.empty()){
                    pair<int,int> p = q.front();    q.pop();
                    int y = p.first, x = p.second;
                    if(mat[y][x]) continue;
                    mat[y][x] = true;
                    for(int k = 0; k < 4; k++){
                        int ny = y + di[k], nx = x + dj[k];
                        if(!inRange(ny, 0, h-1) || !inRange(nx, 0, w-1) || mat[ny][nx])    continue;
                        q.push({ny,nx});
                    }
                }
            }
        }

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


Measured memory_bytes: 38200
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N,K;
  cin>>N>>K;
  int L[N];
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  sort(L,L+N);
  reverse(L,L+N);
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=L[i];
  }
  printf("%d",ans);

}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

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


	int N = 0;
	while ((ct = getcha()) >= '0') N = N * 10 + ct - '0';

	int kotae = 0;
	rep(i, N) {
		int A = 0;
		if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = ct - '0';
		else while ((ct = *ci++) >= '0') A = ct - '0';
		kotae ^= A;
	}

	if (kotae & 1) printf("NO\n");
	else printf("YES\n");


	Would you please return 0;
}

Measured memory_bytes: 256
echo H,W,A,B=`tr \  ,`\;M,C,Z=10**9+7,1,0 '
for I in range(1,H'{'):C=C*(W+H-B+~I)*pow(','-A+1):Z+=C;C=C*(B-1+I)*(H-I)*pow((W+H-B+~I)*'}I,M-2,M\)%M '
print Z%M'|pypy

Measured memory_bytes: 89184
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = input()

if S == 'hi' or S == 'hihi' or S == 'hihihi' or S == 'hihihihi' or S == 'hihihihihi':
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std; 
#define all(c) c.begin(),c.end()
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ; 
typedef vector<int> vi;
#define mod 1000000007 

int main()
{
  //  freopen("input.txt","r",stdin);
   ios::sync_with_stdio(0);
   // cin.tie(0);
   
int d,t,s;
cin>>d>>t>>s;
if(d>s*t)
cout<<"No";
else cout<<"Yes";
  


    return 0;
}

Measured memory_bytes: 3648