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

int threesum(int x, int n)
{
    if(x + (x-1) + (x-2) < n)
        return 0;
    int count = 0;
    for(; x > 0; --x )
    {
        int n1 = n - x;
        if(n1 < 0)
            continue;
        for(int j = x - 1; j > 0; --j)
        {
            int n2 = n1 - j;
            if(n2 <= 0 || n2 >= j)
                continue;
            ++count;
        }
    }
    return count;
}

int main()
{
    int n, x;
    vector<int> resp;
    while(true)
    {
        cin>>n >> x;
        if(n == 0 && x ==0)
            break;
        resp.push_back(threesum(n,x));
    }
    for(int i = 0; i < resp.size(); ++i)
    {
        cout<<resp[i]<<endl;
    }

    return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

vector<ull> powb, rhash;

void rolling_hash(string str, ull base) {
    ull N = str.size();
    powb.resize(N + 1);
    rhash.resize(N + 1);
    powb[0] = 1;
    rhash[0] = 0;
    for (int i = 0; i < N; i++) {
        rhash[i + 1] = str[i] + rhash[i] * base;
        powb[i + 1] = powb[i] * base;
    }
}

//[l,r)
ull get_hash(ull l, ull r) {
    return rhash[r] - rhash[l] * powb[r - l];
}

int main() {
    ll n, m;
    string s;
    cin >> n >> m >> s;
    rolling_hash(s, ull(1e9+7));
    ll L = 0, R = 1;
    set<ull> st;
    REP(i, m) {
        string q;
        cin >> q;
        if (q[0] == 'L') {
            q[1] == '+' ? L++ : L--;
        } else{
            q[1] == '+' ? R++ : R--;
        }
        st.insert(get_hash(L,R));
    }
    cout << st.size() << endl;
    return 0;
}



Measured memory_bytes: 21752
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int l;
    cin >> l;
    double x = (l/3.0) * (l/3.0) * (l/3.0);
    // cout << l/3.1 << endl;
    printf("%.7f", x);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    vector<ll> s;
    ll n;
    cin>>n;
    rep(i,n){
        ll a;
        cin>>a;
        s.push_back(a);
    }

    sort(s.begin(),s.end());

    ll smax = s[s.size()-1];
    ll mid1 = (smax)/2;

    ll samin = 1000000001;
    ll p = 0;



    rep(i,n-1) {
        ll k=s[i];

        if(mid1<s[i]){
            k = smax-s[i];
        }


       // cout<<s[i]<<" "<<k<<endl;
        if(samin>=abs(mid1-k)){
            samin = abs(mid1-k);
            p=i;
        }
    }


    cout<<smax<<" "<<s[p]<<endl;





    return 0;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<queue<int>>tree(N + 1);
  vector<queue<int>>length(N + 1);
  vector<long long>Le(N - 1);
  for (int i = 0; i < N - 1; i ++) {
    int a, b;
    cin >> a >> b >> Le[i];
    tree[a].push(b);
    tree[b].push(a);
    length[a].push(i);
    length[b].push(i);
  }
  int Q, K;
  cin >> Q >> K;
  queue<int>que;
  vector<long long>ans(N + 1, -1);
  ans[K] = 0;
  que.push(K);
  while(!que.empty()) {
    int u = que.front();
    while(!tree[u].empty()) {
      int ne = tree[u].front();
      long long ln = Le[length[u].front()];
      tree[u].pop();
      length[u].pop();
      if (ans[ne] != -1) continue;
      que.push(ne);
      ans[ne] = ans[u] + ln;
    }
    que.pop();
  }
  for (int i = 0; i < Q; i ++) {
    int a, b;
    cin >> a >> b;
    cout << ans[a] + ans[b] << endl;
  }
}


Measured memory_bytes: 138880
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define INFTY 2147483647//2147483647


int min(int n,int *A){
    int m = INFTY;
    int gap,six = 6,nine = 9;
    gap = n-nine;
    if(A[n] != INFTY){
        return A[n];
    }
    while(nine <= n && gap >= 0){
        gap = n-nine;
        if(A[gap] == INFTY){
            min(gap,A);
        }
        if(m>A[gap]){
            m = A[gap];
        }
        nine = nine*9;
    }
    gap = n-six;
    while(six <= n && gap >= 0){
        gap = n-six;
        if(A[gap] == INFTY){
            min(gap,A);
        }
        if(m>A[gap]){
            m = A[gap];
        }
        six = six*6;
    }
    A[n] = m+1;
    return A[n];
}

int main(void){
    int i;
    int *A = (int*)malloc(100001*sizeof(int));
    for(i=0;i<100001;i++){
        A[i] = INFTY;
    }
    for(i=0;i<6;i++){
        A[i] = i;
    }
    int N;
    scanf("%d",&N);
    int m = min(N,A);
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 1280
//Sentou
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> 

using namespace std;

int a[200100];

int main()
{
	int n,t;
	scanf("%d%d",&n,&t);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	int be = 0,en = 0,ans = 0;
	for(int i = 1;i <= n;i++)
	{
		if(a[i] >= en)ans += en - be,be = a[i],en = a[i] + t;
		else
		{
			en = max(en,a[i] + t);
		}
	}
	printf("%d\n",ans + en - be);
}

Measured memory_bytes: 896
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repbit(n) for(ll bit=0,bit<(1<<n),bit++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
inline constexpr int modpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a>c&&c>b)cout<<"Yes";
    else if(a<c&&c<b)cout<<"Yes";
    else cout<<"No";
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    int n = (int)s.size();
    vector<ll> from(4);
    from[0] = 1ll;
    for(int i=0;i<n;++i){
        ll a{},b{},c{},d{};
        d = from[0];
        a = from[1];
        b = from[2];
        c = from[3];
        if(s[i] == 'A'){
            (a += from[0])%=mo;  
        }
        else if(s[i] == 'B'){
            (b += from[1])%=mo;
        }
        else if(s[i] == 'C'){
            (c += from[2])%=mo;
        }else {
            (a += from[1] * 2%mo)%=mo;
            (b += from[2] * 2%mo)%=mo;
            (c += from[3] * 2%mo)%=mo;
            (d += from[0] * 2%mo)%=mo;
            (a += from[0])%=mo;
            
            (b += from[1])%=mo;
            
            (c += from[2])%=mo;
        }
        from[1] = a;
        from[2] = b;
        from[3] = c;
        from[0] = d;
    }
    cout << from[3]%mo << endl;
    return 0;
}

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner scan = new Scanner(System.in);
        int a,b,c;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        
        if (a <= c && b >= c){
            System.out.println("Yes");
        }
        else System.out.println("No");
    
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int dp[3001][3001];
int prv[3001][3001];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	string s, t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	memset(prv, -1, sizeof(prv));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(s[i] == t[j]) {
				if(dp[i + 1][j + 1] < dp[i][j] + 1) {
					prv[i + 1][j + 1] = 0;
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
			}
			if(dp[i + 1][j + 1] < dp[i][j + 1]) {
				dp[i + 1][j + 1] = dp[i][j + 1];
				prv[i + 1][j + 1] = 1;
			}
			if(dp[i + 1][j + 1] < dp[i + 1][j]) {
				dp[i + 1][j + 1] = dp[i + 1][j];
				prv[i + 1][j + 1] = 2;
			}
		}
	}
	string ans = "";
	int curx = n, cury = m;
	while(true) {
		if(prv[curx][cury] == 0) {
			ans += s[curx - 1];
			curx--;
			cury--;
		}
		else if(prv[curx][cury] == 1) {
			curx--;
		}
		else if(prv[curx][cury] == 2) {
			cury--;
		}
		else {
			break;
		}
	}
	reverse(all(ans));
	cout << ans;

	return 0;
}

Measured memory_bytes: 144220
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <iomanip>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

int main(void) {
    vector<int> seq;
    int N,a,p=-1,c = 1;
    cin >> N;
    for(int i = 0; i < N;i++) {
        cin >> a;
        if(a == p) {
            c++;
        }
        else {
            if(c!= 1) {
                seq.push_back(c);
                c = 1;
            }
            p = a;
        }
    }
    if(c!= 1) {
        seq.push_back(c);
    }
    int res = 0;
    for(auto e:seq)
        res += e/2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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; }

using ll = long long;
using ull = unsigned long long;
using namespace std;
using P = pair<int,int>;
using PP = pair<int,P>;

int main(){
    int h, w, m; cin >> h >> w >> m;
    vector<int> H(h+1,0), W(w+1,0);
    vector<int> hh(m), ww(m);
    map<pair<int,int>,int> check;
    rep(i,m){
        cin >> hh[i] >> ww[i];
        H[hh[i]]++; W[ww[i]]++;
        check[make_pair(hh[i],ww[i])]++;
    }

    vector<int> c1;
    int c1m = 0;
    rep(i,h+1) chmax(c1m,H[i]);
    rep(i,h+1) if(H[i] == c1m) c1.push_back(i);
    sort(all(c1),greater<int>());

    vector<int> c2;
    int c2m = 0;
    rep(i,w+1) chmax(c2m,W[i]);
    rep(i,w+1) if(W[i] == c2m) c2.push_back(i);
    sort(all(c2),greater<int>());

    rep(i,(int)c1.size()) rep(j,(int)c2.size()){
        if(!check[make_pair(c1[i],c2[j])]){
            cout << c1m + c2m << endl;
            return 0;
        }
    }
    cout << c1m + c2m - 1 << endl;
    return 0;
}

Measured memory_bytes: 30804
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int n;
vector<int> G[100010];
int ret[100010];
int max_d[100010];
void dfs(int v,int d,int c){
	if(max_d[v] >= d)return;
	max_d[v] = d;
	if(ret[v] == 0)ret[v] = c;
	for(int u: G[v]){
		dfs(u,d-1,c);
	}
}

int main(){
	int m;
	int a[100010],b[100010];
	scanf("%d%d",&n,&m);
	rep1(i,m){
		scanf("%d%d",&a[i],&b[i]);
		G[a[i]].pb(b[i]);
		G[b[i]].pb(a[i]);
	}
	int q;
	int v[100010],d[100010],c[100010];
	scanf("%d",&q);
	rep1(i,q){
		scanf("%d%d%d",&v[i],&d[i],&c[i]);
	}
	
	rep1(i,n){
		ret[i] = 0;
		max_d[i] = -1;
	}
	rrep1(i,q){
		dfs(v[i],d[i],c[i]);
	}
	rep1(i,n){
		printf("%d\n",ret[i]);
	}
}

Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    if(r < 1200) {
        cout << "ABC" << endl;
    } else if(r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    } 
    
    return 0;
}





Measured memory_bytes: 256
# tenka1-2018-beginnerC - Align
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    A.sort()
    if N & 1:
        low, high, mid = A[: N // 2], A[N // 2 + 1 :], A[N // 2]
        x = (sum(high) - sum(low)) * 2 - mid + low[-1]
        y = (sum(high) - sum(low)) * 2 + mid - high[0]
        ans = max(x, y)
    else:
        low, high = A[: N // 2], A[N // 2 :]
        ans = (sum(high) - sum(low)) * 2 - high[0] + low[-1]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14380
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const int INF = 1e9;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll hash_val[200010] = {};
ll get_val(ll lv, ll rv){
    return hash_val[rv+1] ^ hash_val[lv];
}

int min_val[(1LL<<26)+10];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.size();
    rep(i,0,N){
        ll v = S[i] - 'a';
        hash_val[i+1] = (hash_val[i] ^ (1LL<<v));
    }
    int dp[200010] = {};
    dp[0] = 0;
    rep(i,0,N) dp[i+1] = INF;
    rep(i,0,(1LL<<26)+1) min_val[i] = INF;
    min_val[0] = 0;
    rep(i,0,N){
        ll tt = get_val(0,i);
        rep(j,0,26){
            ll v = (get_val(0, i) ^ (1LL<<j));
            dp[i+1] = min(dp[i+1], min_val[v]+1);
        }
        dp[i+1] = min(dp[i+1], min_val[tt] + 1);

        min_val[tt] = min(min_val[tt], dp[i+1]);
    }
    print(dp[N]);
}

Measured memory_bytes: 265236
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[110];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int m=INF;
	for(int i=1;i<=100;i++){
		int sum=0;
		REP(j,N){
			sum+=(A[j]-i)*(A[j]-i);
		}
		m=min(m,sum);
	}
	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 256
def toggle_case(c):
    ascii_code = ord(c)
    if 65 <= ascii_code <= 90:
        return chr(ascii_code + 32)
    elif 97 <= ascii_code <= 122:
        return chr(ascii_code + -32)
    
    return c

res = list(input())
res = [toggle_case(c) for c in res]
print("".join(res))


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

int main(){

    int h, w; cin >> h >> w;
    vector<vector<char> > red(h, vector<char> (w, '.'));
    vector<vector<char> > blue(h, vector<char> (w, '.'));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c; cin >> c;
            red[i][j] = blue[i][j] = c;
        }
    }

    for(int i = 0; i < h; i++){
        red[i][0] = '#';
        blue[i][w - 1] = '#';
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w - 1; j++){

            if(i % 2 == 0) red[i][j] = '#';
            else blue[i][j + 1] = '#';
        }
    }


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

    cout << endl;

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

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, k;

signed main() {
	cin >> n >> k;
	cout << n - (k - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
vector<int>x(n);
rep(i,n){
    cin>>x[i];
}
ll ans=(int)1e14;
rep(i,n-k+1){
    ll l=x[i];
    ll r=x[i+k-1];
    ll l_cost=abs(l)+abs(r-l);
    ll r_cost=abs(r)+abs(r-l);
    ans=min(ans,min(l_cost,r_cost));
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
    aa=a[i]
    c+=min(a[i],b[i])
    a[i]=max(0,a[i]-b[i])
    if a[i]==0:
        c+=min(a[i+1],b[i]-aa)
        a[i+1]=max(0,a[i+1]+aa-b[i])
print(c)


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

int main(){
	string s;
	cin >> s;
	int cnt = 0;
	int ans = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') cnt++;
		else cnt = 0;
		ans = max(ans, cnt);
	}
	cout << ans;
}


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

#define el '\n'

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n, nw;
  cin >> n >> nw;
  vector<long long> dp(nw+1); // 0..w
  //dp[i] max val on weight i

  long long w[n-1], v[n-1];
  for(int i = 0; i < n; i++){
    cin >> w[i] >> v[i];
    for(int w_now = nw-w[i]; w_now >= 0; w_now--){
      dp[w_now+w[i]] = max(dp[w_now+w[i]], dp[w_now]+v[i]);
    }
  }
  long long ans = 0;
  for(int i = 0; i <= nw; i++){
    ans = max(ans, dp[i]);
  }
  cout << ans << el;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <cmath>

int main() {
	int a, b;
	std::cin >> a >> b;
	if ((a + b) % 2 == 0)
	{
		std::cout << (a + b) / 2 << "\n";
	} else {
		std::cout << "IMPOSSIBLE" << "\n";
	}
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1000000007;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    ans += 100000 * max(0, 4 - X);
    ans += 100000 * max(0, 4 - Y);
    ans += 400000 * (X == 1 && Y == 1);
    cout << ans << endl;
}




Measured memory_bytes: 256
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		for (int i = 0; i < adjMatrix.length; i++) {
			for (int j = 0; j < adjMatrix[0].length; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		Iterator<LinkedList<Integer>> yIterator = this.adjList.iterator();
		int yIndex = 0;
		while(yIterator.hasNext()) {
			Iterator<Integer> xIterator = yIterator.next().iterator();
			
			while(xIterator.hasNext()) {
				int xIndex = xIterator.next();
				adjMatrix[yIndex][xIndex] = 1;
			}
			yIndex++;
		}
		String row = "";
		for (int i = 0; i < adjMatrix.length; i++) {
			for (int j = 0; j < adjMatrix[0].length; j++) {
				row = row + adjMatrix[i][j] + " ";
			}
			row = row.substring(0, row.length()-1) + '\n';
		}
		System.out.print(row);
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}



Measured memory_bytes: 283472
H,W,D = map(int,input().split())

one_to_HW = [[0,0] for i in range(0,H*W+1,1)]

for i in range(1,H+1,1):
    A = [0]+list(map(int,input().split()))
    for j in range(1,W+1,1):
        one_to_HW[A[j]] = [i,j]
    
path = [0]*(H*W+1)

for i in range(D,H*W+1,1):#一つ前からたどり着くのに魔力
    path[i]=abs(one_to_HW[i][0]-one_to_HW[i-D][0])+abs(one_to_HW[i][1]-one_to_HW[i-D][1])

for i in range(D,H*W+1,1):#累積
    path[i]=path[i]+path[i-D]

ans = []
Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(path[r]-path[l])

for i in range(Q):
    print(ans[i])



Measured memory_bytes: 99124
#include <stdio.h>
#include <math.h>

int checkprime(int x)
{
	int i, prime_max;
	prime_max = sqrt(x);
	
	for(i = 2; i <= prime_max; i++)
	{
		if(x % i == 0)
		{
			return 0;
		}
	}
	
	//printf(">%d\n", x);
	return 1;
}

int main(void)
{
	int n, temp, num_prime;
	int i;
	while(scanf("%d", &n)==1)
	{
		num_prime = 0;
		for(i = 0; i < n; i++)
		{
			scanf("%d", &temp);
			if(temp >= 2){
				num_prime = num_prime + checkprime(temp);
			}
		}
		
		printf("%d\n", num_prime);
	}
	
	return 0;
}

Measured memory_bytes: 596
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
    int n;
    P[] ps;
 
 
    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ps = new P[n];
 
        long t = 0;
        for (int i = 0; i < n; i++) {
            ps[i] = new P(sc.nextLong(), sc.nextLong());
            t += ps[i].a;
        }
 
        Arrays.sort(ps);
        for (int i = 0; i < n; i++) {
            if (t > ps[i].b) t = ps[i].b;
            if (t - ps[i].a < 0) {
                System.out.println("No");
                return;
            }
            t -= ps[i].a;
        }
 
        System.out.println("Yes");
    }
 
    class P implements Comparable<P> {
        long a, b;
        P(long a, long b) {
            this.a = a;
            this.b = b;
        }
 
        @Override
        public int compareTo(P o) {
            return (o.b == b) ? 0 : (o.b - b > 0) ? 1 : -1;
        }
    }
 
 
    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 108620
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int N = 2e5+5;
int a[N];
int main()
{
      int n;
      cin>>n;
      for(int i=1;i<=n;i++)
        cin>>a[i];

      sort(a+1,a+n+1);
      reverse(a+1,a+n+1);//从大到小排列了

      queue<int> q;//输入队列
      for(int i=2;i<=n;i++)
        q.push(a[i]),q.push(a[i]);

      long long ans=a[1];
      for(int i=3;i<=n;i++)
      {
          ans+=q.front();
          q.pop();
      }
      cout<<ans<<endl;
      return 0;
}


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

using namespace std;

int main()
{
	long long n;
	cin >> n;
	auto k = (long long)sqrt(n);
	for (int i = k; i > 0; i--)
	{
		if (n%i == 0)
		{
			cout << to_string(n/i).size() << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
N,Y = map(int,input().split())

flag = "Notyet"
for i in range(N+1):
  for j in range(N+1-i):
    noguchi = i
    higuchi = j
    yukichi = N - i - j
    
    if noguchi * 1000 + higuchi * 5000 + yukichi * 10000 == Y:
      print(yukichi,higuchi,noguchi)
      flag = "Complete"
      sys.exit()
      
if flag == "Notyet":
  print("-1 -1 -1")

Measured memory_bytes: 65516
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,h;cin>>n>>h;
	vector<ll> a(n);
	vector<ll> b(n);
	ll x,y;
	for(int i = 0; i < n; i++) {
		cin>>x>>y;
		a[i] = x;
		b[i] = y;
	}
	sort(ALL(a),greater<ll>());
	sort(ALL(b),greater<ll>());
	b.pb(0LL);
	ll ans = 0;
	ll div = 0;
	ll i = 0;
	while(h > 0){
		if(b[i] >= a[0]){
			h -= b[i];
			ans++;
			i++;
		}		
		else{
			div = ((h + (a[0] - 1))/ a[0]);
			break;
		}
	}
	cout << div + ans << endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (min > n) {
                min = n;
            }
            if (max < n) {
                max = n;
            }
        }
        System.out.println(max - min);
    }
}


Measured memory_bytes: 23380
#include<iostream>
#include<string>
#include<algorithm>
#include <math.h>
using namespace std;
int main()
{
	long long N,D;
	cin >> N >> D;

	long long X[200000], Y[200000];

	for (long long i = 0; i < N; i++)
	{
		cin >> X[i];
		cin >> Y[i];
	}
	string s;
	//cin >> s;

	//int A[5]
	//sort(A, A + 5);
	long long a = 0;
	long double b = 0;
	long long count = 0;
	for (long long i = 0; i < N; i++)
	{
		a = 0;
		a = X[i] * X[i] + Y[i] * Y[i];
		b = sqrt(a);
		if (b <= D)
		{
			count++;
		}
	}

	if (true)
	{
		cout << count << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 6716
#include<bits/stdc++.h>
#define maxn 132000
#define endl '\n'
using namespace std;
struct op {
	int l,r;
};
int seg[maxn<<1];
void push(int p,int lch,int rch) {
	seg[lch] += seg[p];
	seg[rch] += seg[p];
	seg[p] = 0;
}
void modify(int l,int r,int ql,int qr,int p) {
	if(l == ql && r == qr) {
		seg[p]++;
	}
	else {
		int mid = (l+r)>>1 , lch = p<<1 , rch = p<<1|1;
		push(p,lch,rch);
		if(qr <= mid)
			modify(l,mid,ql,qr,lch);
		else if(ql > mid)
			modify(mid+1,r,ql,qr,rch);
		else {
			modify(l,mid,ql,mid,lch);
			modify(mid+1,r,mid+1,qr,rch);
		}
	}
}
int query(int l,int r,int pos,int p) {
	if(l == r)
		return seg[p];
	else {
		int mid = (l+r)>>1 , lch = p<<1 , rch = p<<1|1;
		push(p,lch,rch);
		if(pos <= mid)
			return query(l,mid,pos,lch);
		else
			return query(mid+1,r,pos,rch);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	vector<op> ops;
	for(int i=1,l,r;i<=n;i++) {
		cin >> l >> r;
		ops.emplace_back(op{l,r});
	}
	sort(ops.begin(),ops.end(),[=](op a,op b)->bool
		{return a.r - a.l < b.r - b.l;});
	int sum = n , idx = 0;
	for(int d=1;d<=m;d++) {
		while(idx < n && ops[idx].r - ops[idx].l + 1 < d) {
			modify(1,m,ops[idx].l,ops[idx].r,1);
			idx++;
			sum--;
		}
		int ans = sum;
		for(int i=d;i<=m;i+=d)
			ans += query(1,m,i,1);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  if(s%1000/100==s%100/10){
    if(s/1000==s%1000/100 || s%100/10==s%10){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
  long n;
  cin >> n;
  for(long i=0;i<n;i++){
    if(n==1){
      cout << 1 << endl;
    }else if((i+1)*(i+1)>n){
      cout << i*i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
	int H, W;
	int n1 = scanf("%d %d\n", &H, &W);
	if(n1 < 2){
		printf("error\n");
		exit(1);
	}
	
	char str[H][W+2];
	for(int i=0;i<H;i++){
		if(fgets(str[i], W+2, stdin) == NULL){
			printf("error\n");
			exit(1);
		}
	}

	for(int i=0;i<W+2;i++) printf("#");
	printf("\n");

	for(int i=0;i<H;i++){
		printf("#");
		for(int j=0;j<W;j++){
			printf("%c", str[i][j]);
		}
		printf("#\n");
	}

	for(int i=0;i<W+2;i++) printf("#");
	printf("\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

const int N = (int)1e5 + 9;
int bit[N];
vector<pii> T[N];

void dfs(int u, int par){
  for(auto x : T[u]){
    if(x.fi == par) continue;
    bit[x.fi] = bit[u] ^ x.se;
    dfs(x.fi, u);
  }
}

int main(){
  fastIO;
  int n;
  cin >> n;
  int u, v, w;
  for(int i = 1 ;i < n; i ++ ){
    cin >> u >> v >> w;
    T[u].push_back(mp(v,w%2));
    T[v].push_back(mp(u,w%2));
  }
  dfs(1,-1);
  for(int i = 1; i <= n; i ++ ){
    cout << bit[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  REP(i, N)
  cin >> a[i];
  vector<ll> sum1(N + 1), sum2(N + 1); // sum1：普通の累積和， sum2：和が最大となるような累積和
  sum1[0] = sum2[0] = 0;
  REP(i, N)
  {
    sum1[i + 1] = sum1[i] + a[i];
    sum2[i + 1] = sum2[i] + max(0ll, a[i]);
  }
  ll ans = 0;
  REP(i, N - K + 1)
  {
    ll res = sum2[i] - sum2[0] + max(0ll, sum1[i + K] - sum1[i]) + sum2[N] - sum2[i + K];
    ans = max(res, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  c=input()
  if c=='AC':
    ac+=1
  elif c=='WA':
    wa+=1
  elif c=='TLE':
    tle+=1
  else:
    re+=1

print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))

Measured memory_bytes: 9232
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int X;
    cin >> X;
    
    for(int i=0; i<1000; i++){
        for(int j=-1000; j<1000; j++){
            if((long long int)pow(i,5)-pow(j,5) == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

using namespace std;

#define N 12000

int n,x,y,d,cnt[2],c[2][N];
bool f[N],g[N];
char s[N];

int main(){
    scanf("%s%d%d",s+1,&x,&y); n=strlen(s+1);
    int i;
    for (i=1;i<=n && s[i]=='F';i++) x--;
    d=0;
    for (;i<=n;i++)
        if (s[i]=='F'){c[d][c[d][0]]++; cnt[d]++;}
        else{d^=1; c[d][0]++;}
    x=abs(x); y=abs(y);
    if ((cnt[0]+x)&1 || (cnt[1]+y)&1){puts("No"); return 0;}
    x=(cnt[0]+x)>>1; y=(cnt[1]+y)>>1;
    f[0]=1;
    for (int i=1;i<=c[0][0];i++)
        for (int j=x;j>=c[0][i];j--)
            f[j]|=f[j-c[0][i]];
    g[0]=1;
    for (int i=1;i<=c[1][0];i++)
        for (int j=y;j>=c[1][i];j--)
            g[j]|=g[j-c[1][i]];
    if (f[x] && g[y]) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int N=14;
const int INF=1e9;
string str[20],s[20];
int dp[20][1<<15],ok[20][20];
int n;
int check(int x,int y)
{
	int i,j,r=0,l1=s[x].size(),l2=s[y].size();
	for(i=0;i<l1;i++)
	{
		for(j=0;i+j<l1&&j<l2;j++)if(s[x][i+j]!=s[y][j])break;
		if(i+j==l1&&r<j)r=j;
	}
	return r;
}
bool ck(int x,int y)
{
	int l1=str[x].size(),l2=str[y].size();
	int i,j;
	for(i=0;i<l2;i++)
	{
		for(j=0;j<l1&&i+j<l2;j++)if(str[x][j]!=str[y][i+j])break;
		if(j==l1)return true;
	}
	return false;
}
int dfs(int x,int zt)
{

	if(dp[x][zt]!=-1)return dp[x][zt];
	dp[x][zt]=INF;
	int i;
	for(i=0;i<n;i++)
	{
		if((zt&(1<<i))&&i!=x)
		{
			int t=dfs(i,zt-(1<<x))+s[x].size()-ok[i][x];

			if(dp[x][zt]>t)dp[x][zt]=t;
		}
	}

	return dp[x][zt];
}
int main()
{      
	int i,j,k;
	while(~scanf("%d",&n))
	{       
                memset(dp,-1,sizeof(dp));
		if(!n)break;
		for(i=0;i<n;i++)cin >> str[i];
		k=0;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(i!=j&&ck(i,j))break;
			}
			if(j==n)s[k++]=str[i];
		}

		n=k;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				ok[i][j]=check(i,j);
			}
		}
		
		for(i=0;i<n;i++)dp[i][1<<i]=s[i].size();
		int L=(1<<n);
		for(i=0;i<n;i++)dfs(i,L-1);
		int r=INF;
		for(i=0;i<n;i++)if(r>dp[i][L-1])r=dp[i][L-1];
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 3808
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CXYZTriplets {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> f(100000);
      for(int i=1; i<=100; i++) {
        for(int j=1; j<=100; j++) {
          for(int k=1; k<=100; k++) {
            f[i*i+j*j+k*k+i*j+j*k+k*i]++;
          }
        }
      }
      for(int i=1; i<=n; i++) {
        cout << f[i] << '\n';
      }


    }
};

signed main() {
  CXYZTriplets solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>

void swap(int *a,int *b){
	int h;
	h=*a;
	*a=*b;
	*b=h;
}

int main(){
	int n,m,i,place[100],c,j,sort[100],p;
	scanf("%d %d",&n,&m);
	while(n!=0){
		for(j=0;j<m;j++){
			place[j]=0;
			sort[j]=-1;
		}
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				scanf("%d",&c);
				place[j]+=c;
				if(sort[j]==-1) sort[j]=j;
				for(c=0;c<m;c++){
					if(sort[c]==j){
						p=c;
						c=m;
					}
				}
				for(c=p;c>0;c--){
					if(place[sort[c]]>place[sort[c-1]]){
						swap(&sort[c],&sort[c-1]);
					}else{
						c=0;
					}
				}
			}
		}
		for(i=1;i<m;i++){
			if(place[sort[i]]==place[sort[i-1]]){
				if(sort[i]<sort[i-1]){
				swap(&sort[i],&sort[i-1]);
				i=0;
				}
			}
		}
		printf("%d",sort[0]+1);
		for(i=1;i<m;i++){
			printf(" %d",sort[i]+1);
		}
		printf("\n");
		scanf("%d %d",&n,&m);
	}
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H+2);
  for(int j=0; j<W+2; ++j){
    S.at(0).push_back('.');
    S.at(H+1).push_back('.');
  }
  for(int i=1; i<H+1; ++i){
    string str;
    cin >> str;
    if(str.size()!=W){
      return 0;
    }
    S.at(i) = "." + str + ".";
  }   
  for(int i=1; i<H+1; ++i){
    for(int j=1; j<W+1; ++j){
      if(S.at(i).at(j)=='.'){
        int num = 0;
        for(int k=i-1; k<i+2; ++k){
          for(int l=j-1; l<j+2; ++l){
            if(S.at(k).at(l)=='#' && (k!=i || l!=j)){
              num++;
            }
          }
        }
        S.at(i).at(j) = '0' + num;
      }
    }
  }
  for(int i=1; i<H+1; ++i){
    for(int j=1; j<W+1; ++j){
      cout << S.at(i).at(j);
    }
    cout << endl;
  }
  return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+7;

int dp[maxn][4];
ll s[maxn],tot,mx,mn,now,ans=1e18,a[maxn];
int px=1,py=1,n;

void upd(){
    if(now<mn) mn=now;
    else if(now>mx) mx=now;
}

void solve()
{
    for(int mid=1;mid<=n;++mid)
    {
        while(px<=mid&&2ll*s[px]<=s[mid]) ++px;
        while(py<=n&&2ll*s[py]<=tot+s[mid]) ++py;

        //dbg(px,py);
        for(int i=px;i>=px-1;i--)
            for(int j=py;j>=py-1;j--)
            {
                mx=mn=s[i];
                now=s[mid]-s[i]; upd();
                now=s[j]-s[mid]; upd();
                now=tot-s[j];    upd();
                ans=min(ans,mx-mn);
                //dbg(mx,mn);
            }
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];

    for(int i=1;i<=n;++i)
    {
        s[i]=s[i-1]+a[i];
    }
    s[n+1]=tot=s[n];
    solve();
    print(ans);
    return 0;
}

Measured memory_bytes: 6672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

ll N, M, V, P;
VL A;

bool check(ll i){
    if(i < P) return true;
    if(A[i] + M < A[P-1]) return false;
    ll c = 0;
    c += (P - 1) * M;
    c += (N - i) * M;
    for(ll j = P-1; j < i; j++){
        c += min(M, max(A[i] + M - A[j], 0LL));
    } 
    if(c >= M * V) return true;
    else return false;
}

int main(){
    cin >> N >> M >> V >> P;
    A.resize(N);
    rep(i, 0, N) cin >> A[i];

    sort(A.begin(), A.end(), greater<ll>());

    ll L = -1, R = N;
    while(R - L > 1){
        ll mid = L + (R-L)/2;
        if(check(mid)){
            L = mid;
        }else{
            R = mid;
        }
    }

    cout << L+1 << endl;
    return 0;
}

Measured memory_bytes: 1024
S = input()

T = ""

while T in S and T != S:

    if S[len(T)] == "d":

        if len(S) == len(T) + 5:
            T += "dream"

        elif len(S) == len(T) + 7:

            T += "dreamer"

        elif len(S)>=len(T)+5 and (S[len(T) + 5] == "d"):
            T += "dream"
        
        elif len(S)>=len(T)+7 and (S[len(T) + 7] == "d" or S[len(T) + 7] == "e"):
            T += "dreamer"

        else:
            T += "dream"

    else:

        if len(S) == len(T) + 5:
            T += "erase"

        elif len(S)>=len(T)+6 and S[len(T) + 5] == "r":
            T += "eraser"

        else:
            T += "erase"

    #print (T)

#print (T)

if T == S:
    print ("YES")

else:
    print ("NO")


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    vector<ll> L(N);
    REP(i,N)cin >> L[i];
    ll count = 0;
    REP(i,N){
        REP(o,N){
            REP(t,N){
                if(L[i] == L[o])continue;
                if(L[i] == L[t])continue;
                if(L[t] == L[o])continue;
                ll a = L[i],b = L[t],c = L[o];
                if(a > b){
                    swap(a,b);
                }
                if(b > c){
                    swap(c,b);
                }
                if(a+b>c)count++;
            }
        }
    }
    cout << count/6 << "\n";
}

Measured memory_bytes: 3656