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

const int N = 3005;
int n, a[N];
long long dp[N][N][2];
bool calc[N][N][2];

long long f(int l, int r, bool ply) {
  if (calc[l][r][ply])
    return dp[l][r][ply];

  calc[l][r][ply] = true;

  if (l == r)
    return dp[l][r][ply] = (ply ? -a[l] : a[l]);

  long long x = f(l+1, r, !ply) + (ply ? -a[l] : a[l]);
  long long y = f(l, r-1, !ply) + (ply ? -a[r] : a[r]);

  return dp[l][r][ply] = (ply ? std::min(x, y) : std::max(x, y));
}

int32_t main() {
  scanf("%d", &n);

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

  printf("%lld\n", f(0, n-1, 0));
  return 0;
}


Measured memory_bytes: 158208
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,A,B;
	while(cin>>A>>B) {
		ll ans = 0;
		if(13<=A) ans=B;
		else if(6<=A) ans=B/2;
		
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
    if(a<=b&&b<=c){cout<<a<<" "<<b<<" "<<c<<endl;}
    else if(a<=c&&c<=b){cout<<a<<" "<<c<<" "<<b<<endl;}
    else if(b<=a&&a<=c){cout<<b<<" "<<a<<" "<<c<<endl;}
    else if(b<=c&&c<=a){cout<<b<<" "<<c<<" "<<a<<endl;}
    else if(c<=a&&a<=b){cout<<c<<" "<<a<<" "<<b<<endl;}
    else{cout<<c<<" "<<b<<" "<<a<<endl;}
    
    return 0;
	}



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

const int MAX_N = 10000001;

bool is_prime[MAX_N];

void calc_prime(int n){
	for(int i = 0; i <= n; ++i)
		is_prime[i] = true;
	is_prime[0] = is_prime[1] = 0;
	
	for(int i = 2; i <= n; ++i){
		if(is_prime[i])
			for(int j = 2 * i; j <= n; j += i)
				is_prime[j] = false;
	}
}

int main() {
	int n;
	calc_prime(MAX_N);
	while(1){
		cin >> n;
		if(n == 0)
			break;

		int c = n;
		while(1){
			if(is_prime[c - 8] && is_prime[c - 6] && is_prime[c - 2] && is_prime[c]){
				cout << c << endl;
				break;
			}
			c--;
		}
	}
	return 0;
}

Measured memory_bytes: 10924
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;
/**==Info==
*Program:4
*Problem:SHorten Diameter
*Date:2018-8-8
*Algorithm:Teacher's BFS
*Stats:Unknown*/
int n,k;
vector<int> nei[2005];
int dis[2005];
queue<int> q;
queue<int> eq;
void BFS(){
	while(!q.empty()){
		int last=q.front();
		q.pop();
		for(int i=0;i<nei[last].size();i++){
			if(dis[nei[last][i]]==1e8){
				dis[nei[last][i]]=dis[last]+2;
				q.push(nei[last][i]); 
			}
		}
	}
}

int Spot(int pos){
	for(int i=0;i<n;i++) dis[i]=1e8;
	dis[pos]=0;
	q=eq;
	q.push(pos);
	BFS();
	int a=0;
	for(int i=0;i<n;i++){
		//cout<<"dis[i] is "<<dis[i]<<endl;
		if(dis[i]>k) a++;
	}
	return a;
}

int Edge(int pos1,int pos2){
	for(int i=0;i<n;i++) dis[i]=1e8;
	dis[pos1]=1;
	dis[pos2]=1;
	q=eq;
	q.push(pos1);
	q.push(pos2);
	BFS();
	int a=0;
	for(int i=0;i<n;i++){
		if(dis[i]>k) a++;
	}
	return a;
}

int main(){
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);  
	}
	
	//cout<<"Are you kidding me?????"<<endl;
	int mn=1e9;
	for(int i=0;i<n;i++){
		mn=min(mn,Spot(i));
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<nei[i].size();j++){
			if(nei[i][j]>i){
				mn=min(mn,Edge(nei[i][j],i));
			}
		}
	}
	cout<<mn;
	return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N,C,K;
    cin >> N >> C >> K;
    vector<int> t(N);
    rep(i,0,N) cin >> t[i];
    sort(t.begin(),t.end());
    int ans=0;
    vector<bool> done(N);
    rep(i,0,N){
        if(done[i]) continue;
        ++ans;
        rep(j,i,N){
            if(t[i]+K<t[j] or j-i>=C) break;
            done[j]=true;
        }
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    while (1) {
        int n;
        cin >> n;
        if (n == 0)break;
        VI m(n + 1, 0), s(n + 1, 0), l(n + 1, 0);//[n]=場
        string t;
        cin >> t;

        int i = 0;
        for (char c : t) {
            if (c == 'M')m[i]++;
            else if (c == 'S') {
                s[i]++;
                m[n] += m[i];
                s[n] += s[i];
                l[n] += l[i];
                m[i] = s[i] = l[i] = 0;
            }
            else {
                l[i]++;
                m[i] += m[n];
                s[i] += s[n];
                l[i] += l[n];
                m[n] = s[n] = l[n] = 0;
            }
            ++i %= n;
        }
        VI ans(n);
        FOR(i, 0, n)ans[i] = m[i] + s[i] + l[i];
        SORT(ans);
        FOR(i, 0, n)cout << ans[i] << " ";
        cout << m[n] + s[n] + l[n] << "\n";
    }
    
}


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


#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int a[300];
int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

   // ios_base::sync_with_stdio(0);
   // cin.tie(0);
   int n,i,j,ans=0;
   cin>>n;
   n*=2;
   fr(i,0,n-1)
    scanf("%d",&a[i]);

   sort(a,a+n);
   for(i=0;i<n;i+=2)
    ans+=min(a[i],a[i+1]);

   cout<<ans<<endl;


    return 0;
}




Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e3+10;
char s[SIZE][SIZE];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m;
bool Out(int x,int y){return x<0||y<0||x>=n||y>=m;} 
bool u[SIZE][SIZE];
int v[SIZE*SIZE];
PII bfs[SIZE*SIZE];
int main(){
    R(n,m);
    REP(i,n)RS(s[i]);
    int r=0;
    REP(i,n)REP(j,m){
        if(s[i][j]=='#'){
            u[i][j]=1;
            bfs[r++]={i,j};
        }
    }
    int an=0;
    REP(i,r){
        auto me=bfs[i];
        REP(j,4){
            PII nxt={me.F+dx[j],me.S+dy[j]};
            if(Out(nxt.F,nxt.S)||u[nxt.F][nxt.S])continue;
            u[nxt.F][nxt.S]=1;
            v[r]=v[i]+1;
            an=v[r];
            bfs[r++]=nxt;
        }
    }
    W(an);
    return 0;
}


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

int main() {
  int n , m;
  cin >> n >> m;
  if ( m > n){
    cout << "No" << endl;
    return 0;
  }
  vector <string> a(n),b(m);
  for ( int i=0 ; i< n ; i++){
    cin >> a.at(i);
  }
  for ( int i=0 ; i< m ; i++){
    cin >> b.at(i);
  }
  
  for ( int i= 0 ; i <= n-m ; i++){
    for ( int j=0 ; j<= n-m ; j++ ){
      bool ans = true ;
      for ( int k=0 ; k<=m-1 ; k++){
        for (int l=0 ; l<=m-1 ; l++){
         if ( b.at(k).at(l) != a.at(i+k).at(j+l)){
           ans = false ;
           break ;
         }
        }
        if(!ans){
          break ;
        } 
        }
      if (ans){
          cout << "Yes" << endl;
          return 0 ;
      }
    }
  }
    cout <<  "No" << endl;
}

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

int main(){
    int H, W, N;
    cin >> H >> W >> N;

    int ans = 0;

    if(N % max(H, W) == 0) ans = N / max(H, W);
    else ans = N / max(H, W) + 1;

    cout << ans << endl;

    return 0;
}

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

signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int p = n / 2;
    if (v[p] == v[p - 1])
        cout << 0 << "\n";
    else
        cout << v[p] - v[p - 1] << "\n";
}

Measured memory_bytes: 1024
// 2015/04/20 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int C;

void selectionSort(int A[], int N)
{
	for(int i=0; i<=N-1; i++){
		int minj = i;

		for(int j=i; j<=N-1; j++){
			if(A[j]<A[minj]){
				minj = j;
			}
		}

		if(i!=minj){
			swap(A[i], A[minj]);
			C++;
		}
	}
}

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

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

	C = 0;

	selectionSort(A, N);

	for(int i=0; i<N; i++){
		cout << A[i];

		if(i<N-1){
			cout << ' ';
		}
		else{
			cout << endl;
		}
	}
	cout << C << endl;

	return 0;
}

Measured memory_bytes: 1164
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
        int[] ks = new int[M];
        int[][] ss = new int[M][N];
        for (int i = 0; i < M; i++) {
            ks[i] = in.nextInt();
            for (int j = 0; j < ks[i]; j++) {
                ss[i][j] = in.nextInt() - 1;
            }
        }

        int[] p = new int[M];
        for (int i = 0; i < M; i++) {
            p[i] = in.nextInt();
        }

        long ans = 0;
        int[] sum = new int[N];
        for (int i = 0; i < (1 << N); i++) {
            Arrays.fill(sum, 0);
            for (int j = 0; j < N; j++) {
                if (((i >> j) & 1) == 1) {
                    sum[j] = 1;
                }
            }

            boolean allOn = true;
            for (int j = 0; j < M; j++) {
                int isOn = 0;
                for (int k = 0; k < ks[j]; k++) {
                    isOn += sum[ss[j][k]];
                }
                isOn %= 2;
                if (isOn != p[j]) {
                    allOn = false;
                    break;
                }
            }

            if (allOn) {
                ans++;
            }
        }

        out.println(ans);
    }
}

class Shop implements Comparable<Shop> {
    String name;
    int p;
    int index;

    Shop(String name, int p, int index) {
        this.name = name;
        this.p = p;
        this.index = index;
    }

    @Override
    public int compareTo(Shop o) {
        if (name.compareTo(o.name) == 0) {
            if (this.p == o.p) {
                return 0;
            } else if (this.p < o.p) {
                return 1;
            } else {
                return -1;
            }
        }

        return name.compareTo(o.name);
    }

    @Override
    public String toString() {
        return name + " " + p;
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>
#include <tuple>
#include <queue>

using namespace std;

int bfs(const vector<string> &table)
{
    const int h = table.size();
    const int w = table[0].size();

    vector<vector<bool>> visited(h, vector<bool>(w, false));

    queue<tuple<int, int, int>> que;
    que.emplace(0, 0, 0);
    visited[0][0] = true;

    vector<int> dx = {0, 1, 0, -1};
    vector<int> dy = {1, 0, -1, 0};

    while (!que.empty())
    {
        int depth, y, x;
        tie(depth, y, x) = que.front();
        que.pop();

        if (y == h - 1 && x == w - 1)
        {
            return depth;
        }

        for (int i = 0; i < 4; i++)
        {
            const int ny = y + dy[i];
            const int nx = x + dx[i];

            if (0 <= ny && ny < h && 0 <= nx && nx < w && table[ny][nx] == '.' && !visited[ny][nx])
            {
                visited[ny][nx] = true;
                que.emplace(depth + 1, ny, nx);
            }
        }
    }
    return -1;
}

int main()
{
    int h, w;
    cin >> h >> w;

    int black = 0;

    vector<string> table(h);
    for (auto &row : table)
    {
        cin >> row;
        for (auto &ch : row)
        {
            if (ch == '#')
            {
                black++;
            }
        }
    }

    const int turn = bfs(table);

    if (turn == -1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << (h * w - black - turn - 1) << endl;
    }   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

struct BIT{
    vector<ll> bit; //1-indexed
    int n;
    BIT(int n) : n(n), bit(vector<ll>(n+1, 0)) {}
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x){
        while(i <= n){
            bit[i] += (ll)x;
            i += i & -i;
        }
    }
    //xより大きい値(区間和)が現れる最初のインデックス. (l,u]の範囲
    int lower_bound(ll x) {
        ll ret = 0;
        ll k = 1;
        while(2 * k <= n) k <<= 1;
        for(; k > 0; k >>= 1) {
            if(ret + k < n && bit[ret + k] < x) {
                x -= bit[ret + k];
                ret += k;
            }
        }
        return ret + 1;
    }
    //x以上の値(区間和)が現れる最初のインデックス. [l,u)の範囲
    int upper_bound(ll x) {
        ll ret = 0;
        ll k = 1;
        while(2 * k <= n) k <<= 1;
        for(; k > 0; k >>= 1) {
            if(ret + k < n && bit[ret + k] <= x) {
                x -= bit[ret + k];
                ret += k;
            }
        }
        return ret + 1;
    }
    ll between(int i, int j){
        if(i > j) return 0;
        return sum(j) - sum(i-1);
    }
};

int main(void)
{
    ll N,D,A;
    cin >> N >> D >> A;
    vector<pll> x(N);
    REP(i, N) cin >> x[i].fi >> x[i].se;
    SORT(x);
    vector<ll> X(N), H(N);
    REP(i, N) {
        X[i] = x[i].fi;
        H[i] = x[i].se;
    }

    BIT bit(N);

    ll ans = 0;
    REP(i, N){
        int s_id = lower_bound(ALL(X), X[i]-2*D) - X.begin();
        H[i] -= bit.between(s_id+1, i+1);

        ll t = 0;//攻撃回数
        if(H[i] > 0){
            if((H[i]%A) == 0) t = H[i]/A;
            else t = H[i]/A+1;
            bit.add(i+1, t*A);
        }
        
        ans += t;
    }
    pr(ans);
}

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

//----- [n - 1 % 5]個のはじきを返す関数 -----//
int f_haziki(int);

int main(void)
{
	//入力変数
	int n = 0;
	//数列格納配列
	int h_retu[100] = {0};

	while (true)
	{
		cin >> n;
		if (n == 0)
		{
			return 0;
		}
		//はじき
		int haziki = 32;

		//数列の入力
		for (int i = 0; i < n; i++)
		{
			cin >> h_retu[i]; 
		}

		//カウント変数
		int count = 0;
		while (haziki > 0)
		{
			//兄の取った個数
			haziki -= f_haziki(haziki);
			if (haziki <= 0)	{	haziki = 0;	}
			cout << haziki << endl;
			//弟の取った個数
			haziki -= h_retu[count % n];
			count++;
			if (haziki <= 0)	{	haziki = 0;	}
			cout << haziki << endl;
		}
	}

	return 0;
}




//*****----- [n - 1 % 5]個のはじきを返す関数 -----*****//

int f_haziki(int n)
{
	return (n - 1) % 5;
}

Measured memory_bytes: 1156
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        lrs: [(i64, i64); m]
    }
    let mut min = 0;
    let mut max = n as i64;
    for lr in lrs {
        min = std::cmp::max(lr.0, min);
        max = std::cmp::min(lr.1, max);
    }
    if max - min < 0 {
        println!("0");
    } else {
        println!("{}", max - min + 1);
    }
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
const int MAXN=5017;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long a, b, c, d, k;
    cin>>a>>b>>c>>k;
    if(k%2==0) cout<<a-b<<endl;
    else cout<<b-a<<endl;
    
}

Measured memory_bytes: 764
from sys import stdin

h,n = [int(x) for x in stdin.readline().rstrip().split()]
a = [0]*n
b = [0]*n

for i in range(n):
    a[i],b[i] = [int(x) for x in stdin.readline().rstrip().split()]

#最高で削られる可能性がある体力
H = max(a)

inf = 10**10

#体力をちょうどi削るために必要な最低の魔力
dp = [inf for _ in range(h+H+1)]
dp[0] = 0

for i in range(n):
    for j in range(h+1):
        if dp[j+a[i]] > dp[j] + b[i]:
            dp[j+a[i]] = dp[j] + b[i]

print(min(dp[h:]))

Measured memory_bytes: 41452
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	h,w = MI()
	if h == 1 or w == 1:
		print(1)
	else:
		if h*w % 2 == 0:
			print(h*w//2)
		else:
			print(h*w//2+1)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
//#include<unordered_map>
#include<utility>
#include<cmath>
//#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU

int MOD=1000000009;
vector<vvi> X(60);
vvi mul(vvi A,vvi B){
    vvi C(A.size(),vi(B[0].size()));
    rep(i,A.size())rep(k,B.size())rep(j,B[0].size())
        (C[i][j]+=A[i][k]*B[k][j])%=MOD;
    return C;
}
vvi pow(vvi A,ll n){
    vvi B(A.size(),vi(A.size()));
    rep(i,A.size())B[i][i]=1;
    rep(i,60)if(1ll<<i&n)
        B=mul(B,X[i]);
    return B;
}
void init(vvi A){
    rep(i,60){
        X[i]=A;
        A=mul(A,A);
    }
}
signed main(){
    int n,m,k,cnt=1;
    while(cin>>m>>n>>k,n|m|k){
        vvi in(k);
        rep(i,k){
            int a,b;
            cin>>b>>a;
            a--;b--;
            in[i]=vi{a,b};
        }
        vi y=vi{0,n-1};
        rep(i,k)y.pb(in[i][0]);
        sort(all(y));
        y.erase(unique(all(y)),y.end());
        vvi G(y.size());
        rep(i,k)G[lower_bound(all(y),in[i][0])-y.begin()].pb(in[i][1]);

        vvi A(m,vi(m));
        rep(i,m)rep(j,m)if(abs(i-j)<=1)A[i][j]=1;
        init(A);
        vvi X(m,vi(1));
        X[0][0]=1;
        rep(j,G[0].size())X[G[0][j]][0]=0;
        rep(i,y.size()-1){
            X=mul(pow(A,y[i+1]-y[i]),X);
            rep(j,G[i+1].size())X[G[i+1][j]][0]=0;
        }
        cout<<"Case "<<cnt++<<": "<<X[m-1][0]<<endl;
    }
}



Measured memory_bytes: 6000
#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;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
#define int long long
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, A, W, T, R;
string S;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> S;
		if (S == "AC") A++;
		else if (S == "WA") W++;
		else if (S == "TLE") T++;
		else R++;
	}
	cout << "AC x " << A << '\n';
	cout << "WA x " << W << '\n';
	cout << "TLE x " << T << '\n';
	cout << "RE x " << R << '\n';
}


Measured memory_bytes: 3660
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
	int n;cin>>n;
	string s[110];
	map<string,int> kosuu;
	string ans="Yes";
	for(int i=0;i<n;i++)cin>>s[i];
	for(int i=0;i<n;i++)
	{
		kosuu[s[i]]++;
		if(i>=1)
		{
			char l=s[i-1][s[i-1].length()-1],f=s[i][0];
			if(kosuu[s[i]]>=2 || (l!=f))
			{
				ans="No";
				break;
			}
			
		}
	} 
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  char b; cin >> b;
  if (b == 'A') cout << 'T';
  else if (b == 'T') cout << 'A';
  else if (b == 'C') cout << 'G';
  else cout << 'C';
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii;
// d = distance(lower_bound(all(x)), upper_bound(all(x)));
int INF = 1e9;
int M = 1e9+7;
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
//#include <algorithm>

int main(){
  int N; cin >> N;
  cout << pow(N,3) << endl;
}

Measured memory_bytes: 256
/*input
2 11 4
*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb                push_back
#define pp                pop_back
#define nl                cout << "\n"
#define MIN(con)          (*min_element(ALL(con)))
#define MAX(con)          (*max_element(ALL(con)))
#define NX(cont)          next_permutation(ALL(cont))
#define PX(cont)          prev_permutation(ALL(cont))
#define prec(n)           cout << fixed << setprecision(n)
#define PI                3.14159265358979323846264338327951
#define all(c)            c.begin(),c.end()
#define rep(i,a,b)        for(ll i=a;i<b;i++)
#define sp                cout << " "
#define mod               1000000007    //9
#define ifalse            ios_base::sync_with_stdio(false),cin.tie(NULL)

using ll = long long;
using ld = long double;
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > T LCM(T a, T b)            { return (a * b) / GCD(a, b); }
template < typename T > string toString(T a)       { return to_string(a); }  // Convert int to string
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}  // Convert string to int

ll add(ll x, ll y) { x += y; if(x >= mod) x -= mod; return x; }
ll sub(ll x, ll y) { x -= y; if(x < 0) x += mod; return x; }
ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; }

ll powr(ll a, ll b) {
    ll x = 1LL;
    while(b) {
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}

ll inv(ll a) { return powr(a, mod - 2); }
const int inv2 = (mod + 1) >> 1;
const ll INF =  1e18;
const int inf = 1e9;

bool check(ll n)
{
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;
    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}

/*********************************************START**************************************************************/

int main()
{
    ifalse;
    int a, b, c;
    cin >> a >> b >> c;

    int ans = min(c, b / a);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1000005
    const ll MOD = 1000000000 + 7;
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
           int x ;
           cin >> x;
           
           cout << 1 - x << endl;
        }
    }



Measured memory_bytes: 3516
#include<stdio.h>
int main(void){
    while(1){
        int R0,W0,C,R;
        scanf("%d%d%d%d",&R0,&W0,&C,&R);
        if(R0+W0+C+R==0) break;
        int cnt=0;
        for(int x=0;;x++){
            if(((1.0*R0+x*R)/W0)>=C){
                cnt=x;
                break;
            }
        }
        printf("%d\n",cnt);
    }
}



Measured memory_bytes: 2104
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S; cin >> S;
    bool cur = false;
    vector<char> bef, aft;
    int Q; cin >> Q;
    F0R(i, Q) {
        int T; cin >> T;
        if (T == 1) {
            cur = !cur;
        } else {
            int F; cin >> F;
            char C; cin >> C;
            if (F == 1 && !cur || F == 2 && cur) {
                bef.pb(C);
            } else {
                aft.pb(C);
            }
        }
    }

    if (cur) {
        F0Rd(i, sz(aft)) cout << aft[i];
        reverse(all(S));
        cout << S;
        F0R(i, sz(bef)) cout << bef[i];
    } else {
        F0Rd(i, sz(bef)) cout << bef[i];
        cout << S;
        F0R(i, sz(aft)) cout << aft[i];
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 976
import java.io.BufferedReader
import java.util.*

fun main() = abc114d()

@OptIn(ExperimentalStdlibApi::class)
fun abc114d() = SimpleFastIOWithToken_abc114d().exec {
    val n = readLong()

    val cumulativePF = mutableMapOf<Long, Long>().withDefault { 0 }
    for (it in 1..n) for ((k, v) in primeFactorization(it)) {
        cumulativePF.merge(k, v, Long::plus)
    }

    fun check(x: Long, border: Long) = cumulativePF.getValue(x) >= border - 1

    var answer = 0

    for (i in 2..n) {
        if (check(i, 75)) answer++
    }
    for (i in 2..n) for (j in 2..n) {
        if (i == j) continue
        if (check(i, 25) && check(j, 3)) answer++
        if (check(i, 15) && check(j, 5)) answer++
    }

    for (i in 2..n) for (j in i + 1..n) for (k in 2..n) {
        if (i == j || i == k || j == k) continue
        if (check(i, 5) && check(j, 5) && check(k, 3)) answer++
    }

    println(answer)
}

private fun primeFactorization(n: Long): Map<Long, Long> {
    val factors = mutableMapOf<Long, Long>()
    var temp = n
    var i = 2L
    while (i * i <= temp) {
        while (temp % i == 0L) {
            factors[i] = (factors[i] ?: 0) + 1
            temp /= i
        }
        i++
    }
    if (temp > 1) factors[temp] = 1
    return factors
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc114d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc114d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 38228
#include <algorithm>
#include <cstring>
#include <cstdio>
long long dp[100005][3];
int arr[100005];
char op[100005]; 
int main()
{
	// freopen("ARC066-E.in", "r", stdin); 
	int n; 
	scanf("%d%d", &n, arr); 
	for (int i = 1; i < n; i++)
		scanf("%*c%c%d", op + i, arr + i); 
	memset(dp, -0x3f, sizeof(dp)); 
	dp[0][0] = arr[0]; 
	for (int i = 1; i < n; i++)
	{
		if (op[i] == '+')
		{
			dp[i][0] = std::max(dp[i - 1][0], dp[i - 1][1]) + arr[i]; 
			dp[i][1] = dp[i - 1][1] - arr[i];
			dp[i][2] = dp[i - 1][2] + arr[i];
		}
		else
		{
			dp[i][1] = std::max(dp[i - 1][0], dp[i - 1][1]) - arr[i];
			dp[i][2] = std::max(dp[i - 1][1], dp[i - 1][2]) + arr[i];
		}
	}
	printf("%lld\n", std::max(dp[n - 1][0], std::max(dp[n - 1][1], dp[n - 1][2])));
	return 0; 
}


Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	int N, M;
	cin>>N>>M;
	if(N==M)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func find(arr []int, n int) bool {
	for _, v := range arr {
		if v == n {
			return true
		}
	}
	return false
}

func solve(h []int) int {
	// fmt.Println(h)
	c := 0
	for {
		s := -1
		for i, n := range h {
			if n != 0 {
				s = i
				break
			}
		}
		if s == -1 {
			return c
		}

		i := s + 1
		for {
			if i >= len(h) || h[i] == 0 {
				break
			}
			i++
		}
		e := i

		for i := s; i < e; i++ {
			h[i]--
		}
		c++
		// fmt.Println(s, e, h)
	}
}

func main() {
	N, _ := strconv.Atoi(read())

	h := make([]int, N)
	chars := strings.Split(read(), " ")
	for i := 0; i < N; i++ {
		h[i], _ = strconv.Atoi(chars[i])
	}

	ans := solve(h)
	fmt.Println(ans)
}


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

typedef long int lint;
typedef long long int llint;

#define INF 1073741824
#define LINF 4611686018000000000
#define MOD 1000000007

int main() {
    int n;
    string ss;
    cin >> n >> ss;
    int ans = 0;
    int check = ss.size() - 1;
    int count = 0;
    for (int i = 0; i <= check; i++) {
        if (ss[i] == 'W') {
            bool ok = true;
            for (int j = check; j > i; j--) {
                count++;
                if (ss[j] == 'R') {
                    check = j - 1;
                    ans++;
                    ok = false;
                    break;
                }
            }
            if (ok) break;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3464
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, Q; cin >> N >> Q;
    vector<int> C(N); for (auto &c : C) cin >> c, c--;
    vector<int> L(Q), R(Q);
    for (int i = 0; i < Q; i++) cin >> L[i] >> R[i], L[i]--;
    vector<int> indices(Q); iota(begin(indices), end(indices), 0);
    int sqN = sqrt(N) + 1;
    sort(begin(indices), end(indices), [&](int i, int j) {
        return make_pair(L[i]/sqN, R[i]) < make_pair(L[j]/sqN, R[j]);
    });
    vector<int> ans(Q), cnt(N);
    int l = 0, r = 0, type = 0; // [l, r)
    auto add = [&](int i) {
        cnt[C[i]]++;
        if (cnt[C[i]] == 1) type++;
    };
    auto sub = [&](int i) {
        cnt[C[i]]--;
        if (cnt[C[i]] == 0) type--;
    };
    for (int i : indices) {
        while (r < R[i]) add(r++);
        while (L[i] < l) add(--l);
        while (R[i] < r) sub(--r);
        while (l < L[i]) sub(l++);
        ans[i] = type;
    }
    for (int a : ans) {
        cout << a << '\n';
    }
    return 0;
}

Measured memory_bytes: 15480
N = int(input())
S = input()

pre={}
back={}

for i in range(len(S)):
    n = pre.get(S[i], 0)
    n = n+1
    pre[S[i]] = n

ans = 0
for i in range(len(S)):
    n = pre[S[i]]
    if(n > 1):
        pre[S[i]] = n-1
    else:
        pre.pop(S[i])
    back[S[i]] = back.get(S[i], 0) + 1
    c = [x for x in list(pre.keys()) if x in list(back.keys())]
    ans = max(ans,len(c))

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int[][] d = new int[n][4];
			for(int i=0;i<n;i++){
				for(int j=0;j<4;j++){
					d[i][j] = stdIn.nextInt();
				}
			}
			// sort
			for(int i=0;i<n;i++){
				int max = i;
				for(int j=i+1;j<n;j++){
					if(d[max][2]<d[j][2]){
						max = j;
					}
					else if(d[max][2]==d[j][2]&&d[max][3]>d[j][3]){
						max = j;
					}
					else if(d[max][2]==d[j][2]&&d[max][3]==d[j][3]&&d[max][0]>d[j][0]){
						max = j;
					}
				}
				for(int j=0;j<4;j++){
					int tmp = d[i][j];
					d[i][j] = d[max][j];
					d[max][j] = tmp;
				}
			}
			int pass = 0;
			for(int i=0;i<n;i++){
				if(pass<10){
					int my = 0;
					for(int j=0;j<i;j++){
						if(d[i][1]==d[j][1]){
							my++;
						}
					}
					if(my<3){
						pass++;
						System.out.println(d[i][0]);
					}
				}
				else if(pass<20){
					int my = 0;
					for(int j=0;j<i;j++){
						if(d[i][1]==d[j][1]){
							my++;
						}
					}
					if(my<2){
						pass++;
						System.out.println(d[i][0]);
					}
				}
				else if(pass<26){
					int my = 0;
					for(int j=0;j<i;j++){
						if(d[i][1]==d[j][1]){
							my++;
						}
					}
					if(my==0){
						pass++;
						System.out.println(d[i][0]);
					}
				}
			}
		}
	}
}

Measured memory_bytes: 12000