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

typedef pair <int, int> pii;

const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;
const int LOG = 18;

int N;
vector <int> ch[MAXN];
int anc[MAXN][LOG];
int depth[MAXN];
vector <int> nodes[MAXN];
vector <int> tmp[MAXN];
int pot[MAXN];
int dp[MAXN], cnt[MAXN];
vector <int> v[MAXN];
vector <pii> edges[MAXN];
stack <int> S[MAXN];
int root[MAXN];

void load() {
	scanf("%d", &N);
	N++;
	for (int i = 2; i <= N; i++) {
		scanf("%d", anc[i]);
		ch[++anc[i][0]].push_back(i);
	}
}

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
	else if (x < 0)
		x += MOD;
	return x;
}

inline int mul(int x, int y) {
	return (long long)x * y % MOD;
}

void dfs(int x, int d) {
	depth[x] = d;
	nodes[d].push_back(x);
	for (auto it : ch[x])
		dfs(it, d + 1);
}

int lca(int x, int y) {
	if (depth[x] > depth[y])
		swap(x, y);
	int diff = depth[y] - depth[x];
	for (int i = 0; i < LOG; i++)
		if (diff >> i & 1)
			y = anc[y][i];
	if (x == y)
		return x;
	for (int i = LOG - 1; i >= 0; i--)
		if (anc[x][i] != anc[y][i]) {
			x = anc[x][i];
			y = anc[y][i];
		}
	return anc[x][0];
}

void work(int x) {
	vector <int> val, pref, suff;
	cnt[x] = 0;
	for (auto it : tmp[x]) {
		work(it);
		cnt[x] += cnt[it];
		val.push_back(dp[it]);
	}
	if (!cnt[x]) {
		cnt[x] = 1;
		dp[x] = 1;
		return;
	}
			
	int sz = val.size();
	pref.resize(sz);
	suff.resize(sz);
	pref[0] = 1;
	for (int i = 1; i < sz; i++)
		pref[i] = mul(pref[i - 1], add(pot[cnt[tmp[x][i - 1]]], -val[i - 1]));
	suff[sz - 1] = 1;
	for (int i = sz - 2; i >= 0; i--)
		suff[i] = mul(suff[i + 1], add(pot[cnt[tmp[x][i + 1]]], -val[i + 1]));
	
	dp[x] = 0;
	for (int i = 0; i < sz; i++)
		dp[x] = add(dp[x], mul(val[i], mul(pref[i], suff[i])));
}

int calc(int dep) {
	if (!root[dep])
		return 0;
		
	for (auto it : edges[dep]) 
		tmp[it.first].push_back(it.second);
	
	work(root[dep]);
	
	for (auto it : edges[dep])
		tmp[it.first].clear();
	
	return dp[root[dep]];
}

void build(int dep) {
	for (int i = 0; i < nodes[dep].size(); i++) {
		v[nodes[dep][i]].push_back(dep);
		if (i) 
			v[lca(nodes[dep][i - 1], nodes[dep][i])].push_back(dep);		
	}
}

void go(int x) {
	sort(v[x].begin(), v[x].end());
	v[x].resize(unique(v[x].begin(), v[x].end()) - v[x].begin());
	for (auto it : v[x]) {
		if (S[it].empty())
			root[it] = x;
		else
			edges[it].push_back({S[it].top(), x});
		S[it].push(x);
	}
	for (auto it : ch[x])
		go(it);	
	for (auto it : v[x])
		S[it].pop();
}

int solve() {
	pot[0] = 1;
	for (int i = 1; i <= N; i++)
		pot[i] = mul(pot[i - 1], 2);

	dfs(1, 1);	
	
	for (int j = 1; j < LOG; j++)
		for (int i = 1; i <= N; i++)
			anc[i][j] = anc[anc[i][j - 1]][j - 1];
	
	for (int i = 1; i <= N; i++)
		build(i);
		
	go(1);
	
	int sol = 0;
	for (int i = 1; i <= N; i++) 
		sol = add(sol, mul(pot[N - (int)nodes[i].size()], calc(i)));
		
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 222848
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, A[SIZE];

  scanf("%d", &N);

  ll a = 0;
  for (int i=0; i<N; i++) {
    scanf("%d", A+i);
    a += A[i] * (i % 2 ? -1 : 1);
  }

  a /= 2;

  for (int i=0; i<N; i++) {
    printf("%lld%c", a * 2, " \n"[i == N-1]);
    a = A[i] - a;
  }

  return 0;
}


Measured memory_bytes: 1664
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =100010;
int dp[MAX_N];//i番目のつららが折れる時刻。つまりi!=0ならば既に折れている
pii len[MAX_N];
int n,L;
int main(){
	cin>>n>>L;
	for(int i =1;i <=n;i++){
		cin>>len[i].first;
		len[i].second = i;
	}
	len[0].first=0;
	len[0].second=0;
	/*rep(i,n+2){
		cout <<len[i].first<<endl;
	}*/
	sort(len+1,len+n+1,greater<pii>());
	memset(dp,0,sizeof(dp));
	int ans = 0;
	for(int i =1;i <=n;i++){
		int id =len[i].second;
		dp[id] =L-len[i].first+max(dp[id-1],dp[id+1]);
		ans =max(ans,dp[id]);
	}

	cout<<ans<<endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

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

    vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));
    dp[0][1] = 1;

    vector<ll> p(w + 1, 0);

    int c = 0;
    REP(i, 1 << w - 1) {
        if ((i & 3) == 3 || (i & 6) == 6 || (i & 12) == 12 || (i & 24) == 24 || (i & 48) == 48 || (i & 96) == 96) {
            continue;
        }
        c++;
        REP (j, w - 1) {
            if ((1 & i >> j) == 1) {
                p[j + 1]++;
            }
        }
    }

    FOR(i, 1, h + 1) {
        FOR(j, 1, w + 1) {
            dp[i][j] = dp[i - 1][j - 1] * p[j - 1] % MOD + dp[i - 1][j] * (c - (p[j - 1] + p[j])) % MOD + dp[i - 1][j + 1] * p[j] % MOD;
            dp[i][j] %= MOD;
        }
    }
    cout << dp[h][k] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <set>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,pii> plp;
#define mp make_pair
#define x first
#define y second

ll inf=1e15;

ll dist[53][2505],sol[53];
set<plp> s;
vector<pair<pii,ll> > veki[53][2505];
int bio[53][2505];


int main () {
	int n,m;
	ll sil;
	cin>>n>>m>>sil;
	for(int i=0;i<m;i++){
		int u,v,a;
		ll b;
		cin>>u>>v>>a>>b;
		for(int j=a;j<=n*50;j++){
			veki[u][j].push_back(mp(mp(v,j-a),b));
			veki[v][j].push_back(mp(mp(u,j-a),b));
		}
	}
	for(int i=1;i<=n;i++){
		ll c,d;
		int k;
		cin>>c>>d;
		if(c>50*n) k=50*n;
		else k=c;
		for(int j=0;j<50*n;j++){
			veki[i][j].push_back(mp(mp(i,min(j+k,50*n)),d));
		}
	}
	for(int i=1;i<=n;i++){
		sol[i]=inf;
		for(int j=0;j<=50*n;j++){
			s.insert(mp(inf,mp(i,j)));
			dist[i][j]=inf;
		}
	}
	if(sil>50*n) sil=50*n;
	sil=sil+0;
	s.erase(s.find(mp(inf,mp(1,sil))));
	s.insert(mp(0ll,mp(1,sil)));
	dist[1][sil]=0ll;
	ll udal;
	pii cvor;
	while(!s.empty()){
		cvor=s.begin()->second;
		udal=s.begin()->first;
		s.erase(s.begin());
		bio[cvor.x][cvor.y]=1;
		for(int i=0;i<veki[cvor.x][cvor.y].size();i++){
			int nx=veki[cvor.x][cvor.y][i].x.x;
			int ny=veki[cvor.x][cvor.y][i].x.y;
			if(bio[nx][ny]) continue;
			if(udal+veki[cvor.x][cvor.y][i].y<dist[nx][ny]){
				s.erase(mp(dist[nx][ny],mp(nx,ny)));
				dist[nx][ny]=veki[cvor.x][cvor.y][i].y+udal;
				s.insert(mp(dist[nx][ny],mp(nx,ny)));
			}
		}
	}
	for(int i=2;i<=n;i++){
		for(int j=0;j<=50*n;j++){
			sol[i]=min(sol[i],dist[i][j]);
		}
		cout<<sol[i]<<endl;
	}



return 0;
}



Measured memory_bytes: 30164
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

ll powdiv(ll a, ll b, ll c){
    ll res=1;
    if(b<0) return -1;
    else if(b==0) return 1;
    FOR(i,1,b){
        res*=a;
        res%=c;
    }

    return res;
}

int main()
{
	stringstream ss;

    ll div=1000000007;
    // 入力
    string S;
    cin>>S;
    int s=S.length();

    vector<ll> anum(s+1,0),abnum(s+1,0),qnum(s+1,0),qbnum(s+1,0),qqnum(s+1,0),aqnum(s+1,0);
    if(S[0]=='A') anum[0]=1;
    if(S[0]=='?') qnum[0]=1;
    FOR(i,1,s-1){
        if(S[i]=='?') qnum[i]=qnum[i-1]+1;
        else qnum[i]=qnum[i-1];
        if(S[i]=='A'){
            anum[i]=anum[i-1]+1;
        }
        else anum[i]=anum[i-1];
        // anum[i]=anum[i]%div;
    }
    FOR(i,1,s-1){
        if(S[i]=='B'){
            abnum[i] = anum[i-1] + abnum[i-1];
            qbnum[i] = qnum[i-1] + qbnum[i-1];
        }
        else {
            abnum[i] = abnum[i-1];
            qbnum[i] = qbnum[i-1];
        }
        if(S[i]=='?'){
            aqnum[i] = anum[i-1] + aqnum[i-1];
            qqnum[i] = qnum[i-1] + qqnum[i-1]; 
        // cout<<"qnum "<<qnum[i-1]<<endl;
        // cout<<"qqnum "<<qqnum[i]<<endl;
        // cout<<s<<endl;
        }
        else {
            aqnum[i] = aqnum[i-1];
            qqnum[i] = qqnum[i-1];
        }
        // abnum[i]=abnum[i]%div;
    }

    ll ans=0;
    ll qnumtot=qnum[s-1];
    ll powqnumtot0=powdiv(3,qnumtot,div);
    ll powqnumtot1=powdiv(3,qnumtot-1,div);
    ll powqnumtot2=powdiv(3,qnumtot-2,div);
    ll powqnumtot3=powdiv(3,qnumtot-3,div);
    FOR(i,2,s-1){
        if(S[i]=='C'){
            ans+=abnum[i-1]*powqnumtot0+(aqnum[i-1]+qbnum[i-1])*powqnumtot1+qqnum[i-1]*powqnumtot2;
        }
        else if(S[i]=='?'){
            ans+=abnum[i-1]*powqnumtot1+(aqnum[i-1]+qbnum[i-1])*powqnumtot2+qqnum[i-1]*powqnumtot3;
        }
        ans%=div;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<map>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#include<algorithm>
#include<array>
#include<cmath>
#include<vector>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

typedef double Real;
const Real EPS = 1e-8;
int sign(Real d) { return d > EPS ? 1 : d < EPS ? -1 : 0; }

//define class ...

struct Point {
	Real x, y;
	Point(Real x_ = 0, Real y_ = 0):x(x_), y(y_) {}

	Point operator+(const Point &p) const {
		return Point(x + p.x, y + p.y);
	}

	Point operator-(const Point &p) const {
		return Point(x - p.x, y - p.y);
	}

	Point operator*(Real s) const {
		return Point(x * s, y * s);
	}

	Point operator/(Real s) const {
		return Point(x / s, y / s);
	}

	bool operator<(const Point &p) const {
		return sign(x - p.x) == -1 || (sign(x - p.x) == 0 && sign(y - p.y) == -1);
	}

	bool operator==(const Point &p) const {
		return sign(x - p.x) == 0 && sign(y - p.y) == 0;
	}
};

istream &operator>>(istream &is, Point &p) {
	return is >> p.x >> p.y;
}

ostream &operator<<(ostream &os, Point &p) {
	return os << '(' << p.x << ", " << p.y << ')';
}

struct Line : public array<Point, 2> { //??????
	Line(const Point &a, const Point &b) { at(0) = a; at(1) = b; }
};

struct Segment : public array<Point, 2> { //??´???
	Segment(const Point &a, const Point &b) { at(0) = a; at(1) = b; }
};

struct Circle {
	Point c;
	Point r;
	Circle(const Point &c_, Real r_): c(c_), r(r_) {}
};

typedef vector<Point> Polygon;

// define function
Point rotate90(const Point &p) { // ???????¨???¨???
	return Point(-p.y, p.x);
}

Point rotate(const Point &p, Real theta) {
	const Real s = sin(theta), c = cos(theta);
	return Point(c * p.x - s * p.y, s * p.x + c * p.y);
}

Real angle(const Point &p) {
	return atan2(p.y, p.x);
}

Real norm(const Point &p) {
	return p.x * p.x + p.y * p.y;
}

Real abs(const Point &p) {
	return sqrt(norm(p));
}

Real dot(const Point &a, const Point &b) { // ??????
	return a.x * b.x + a.y * b.y;
}

Real cross(const Point &a, const Point &b) { // ??????
	return a.x * b.y - a.y * b.x;
}

bool is_parallel(const Line &a, const Line &b) {
	return sign( cross(a[1] - a[0], b[1] - b[0]) ) == 0;
} 

// define app function
Point project(const Line &l, const Point &p) {
	const Point a = p - l[0];
	const Point b = l[1] - l[0];
	return l[0] + b * (dot(a, b) / norm(b));
}


bool intersect(const Line &a, const Line &b) {
	return sign(cross(a[1] - a[0], b[1] - b[0])) != 0
			|| sign(cross(a[1] - a[0], b[1] - a[0])) == 0;
}


int main() {
	cout.setf(ios::fixed);
	cout.precision(10);
	Point p0, p1, p2;
	int q;	
	cin >> p0 >> p1;		
	cin >> q;	
	Line line = Line(p1, p0);
	rep(i, q) {
		cin >> p2;			
		Point p3 = project(line, p2);
		p3 = p3 - p2; 
		Point ans = p2 + p3*2;	
		cout << ans.x << " " << ans.y << endl;
	}

	return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/
template<typename T>
vector<T> cumulative_sum(vector<T> &v) {
    vector<T> sum(v.size() + 1);
    for(int i = 0; i < (int)v.size(); ++i){
        sum[i+1] = sum[i] + v[i];
    }
    return sum;
}
/*使うとき
vector<int> a(N);
auto cum = cumlative_sum(a)
とするとvector<int> cumが生成される

i番目までの仕切りの和
cum[i]: [0,i)の和（半開区間）

要素i~jの和が欲しい時
j+1 ~ i番目の仕切りまで数えればよい
int sum = cum[j+1]-cum[i]
*/
/*------------------------------------*/

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

    int N;
    cin>>N;
    vector<ll> A(N);
    ll suma = 0;
    rep(i,N){
        cin>>A[i];
        suma += A[i];
    }
    auto cum = cumulative_sum(A);
    ll ans = INFLL;
    //i番目の仕切りで区切るとき
    for(int i = 1; i<N; i++){
        ll l = cum[i];
        ll r = suma - cum[i];
        ll mid = (l + r)/2;
        ll cost = abs(l-mid) + abs(r - mid);
        chmin(ans, cost);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3456
import java.util.Scanner;
public class Main{

    
   public static void main(String[] args)throws Exception{
     	Scanner sc = new Scanner(System.in);
     	int A = sc.nextInt();
     	int B = sc.nextInt();
     	int C = sc.nextInt();
     	if(A == B + C){
        	System.out.println("Yes");
        }	else if(B == A + C){
        		System.out.println("Yes");
        	 }else if(C == A + B){
          		System.out.println("Yes");
          	}else{
				System.out.println("No");
        	 }
  
   }
 }

    



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除

ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  string sa,sb,sc;
  cin3(sa,sb,sc);
  ll na=sa.size(),nb=sb.size(),nc=sc.size();
  ll anow=0,bnow=0,cnow=0;
  bool acheck=false,bcheck=false,ccheck=false;
  ll nowcolor=1;
  loop(i,300){
    if(nowcolor==1&&anow==na){
      acheck=true;
      break;
    }
    if(nowcolor==2&&bnow==nb){
      bcheck=true;
      break;
    }
    if(nowcolor==3&&cnow==nc){
      ccheck=true;
      break;
    }
    if(nowcolor==1){
      if(sa[anow]=='a')nowcolor=1;
      if(sa[anow]=='b')nowcolor=2;
      if(sa[anow]=='c')nowcolor=3;
      anow++;
      continue;
    }
    if(nowcolor==2){
      if(sb[bnow]=='a')nowcolor=1;
      if(sb[bnow]=='b')nowcolor=2;
      if(sb[bnow]=='c')nowcolor=3;
      bnow++;
      continue;
    }
    if(nowcolor==3){
      if(sc[cnow]=='a')nowcolor=1;
      if(sc[cnow]=='b')nowcolor=2;
      if(sc[cnow]=='c')nowcolor=3;
      cnow++;
      continue;
    }
  }
  if(acheck)putout("A");
  if(bcheck)putout("B");
  if(ccheck)putout("C");
}

Measured memory_bytes: 256
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    p.sort()

    if len(p) == 0:
        print(x)
        return

    diff_min = 1000
    min_n = 1000
    for _ in range(0, 102):
        diff = abs(_ - x)
        if diff < diff_min:
            if _ not in p:
                diff_min = diff
                min_n = _

    print(min_n)


main()


Measured memory_bytes: 9172
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(1){
    c -= b;
    if(c <= 0){
      cout << "Yes\n";
      return 0;
    }
    a -= d;
    if(a <= 0){
      cout << "No\n";
      return 0;
    }
  }
}
    

Measured memory_bytes: 3552
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    
    class Program
    {

        const int INF = -1000000000;

        static int[] CreateMaxDigitLevel(int matchnum, int[] usenumber, int[] neednum)
        {           
            int[] maxdigitlev = new int[matchnum + 1];
            maxdigitlev[0] = 0;
           
            for(int nowmatch = 1; nowmatch <= matchnum; nowmatch++)
            {
                int max = INF;
                for(int j = 0; j < usenumber.Length; j++)
                {
                    int tmp_matchnum = nowmatch - neednum[usenumber[j]];
                    if(tmp_matchnum < 0)
                    {
                        continue;
                    }
                    int digit = maxdigitlev[tmp_matchnum] + 1;
                    if(digit > max && digit >= 0)
                    {
                        max = digit;
                    }
                }

                maxdigitlev[nowmatch] = max;
            }

            return maxdigitlev;
        }

        static string DesicionMaxDigitNum(int[] maxdigitlev, int[] neednum, int[] usenumber, int matchnum, int usenumbernum)
        {

            string maxstr = "";
           
            int nowmatchnum = matchnum;
            for(int nowdigit = maxdigitlev[matchnum]; nowdigit > 0; nowdigit--)
            {               
                for(int j = 0; j < usenumbernum; j++)
                {
                    int next_matchnum = nowmatchnum - neednum[usenumber[j]];
                    if(next_matchnum < 0)
                    {
                        continue;
                    }
                    
                    if(maxdigitlev[next_matchnum] == maxdigitlev[nowmatchnum] - 1)
                    {                       
                        nowmatchnum = next_matchnum;
                        maxstr += usenumber[j].ToString();
                        break;
                    }
                }
                
            }

            return maxstr;
        }
        
        static void Main(string[] args)
        {

            int[] neednum = new int[10];
            neednum[1] = 2;
            neednum[2] = 5;
            neednum[3] = 5;
            neednum[4] = 4;
            neednum[5] = 5;
            neednum[6] = 6;
            neednum[7] = 3;
            neednum[8] = 7;
            neednum[9] = 6;

            string[] str = Console.ReadLine().Split(' ');
            int matchnum = int.Parse(str[0]);
            int usenumbernum = int.Parse(str[1]);

            int[] usenumber = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] maxdigitlev = new int[matchnum + 1];

            Array.Sort(usenumber);          
            Array.Reverse(usenumber);       
            
            maxdigitlev = CreateMaxDigitLevel(matchnum, usenumber, neednum);

            string ansstr = DesicionMaxDigitNum(maxdigitlev, neednum, usenumber, matchnum, usenumbernum);

            Console.WriteLine(ansstr);

        }
    }
}


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

int main(){
  long long H, W;
  cin >> H >> W;
  long long ans1, ans2, ans3, ans4, ans5, ans6;
  ans1=H*((W+2)/3-W/3);
  ans2=W*((H+2)/3-H/3);
  ans3 = max({(H+2)/3*W,(H-(H+2)/3)*(W/2),(H-(H+2)/3)*((W+1)/2)})
  - min({(H+2)/3*W,(H-(H+2)/3)*(W/2),(H-(H+2)/3)*((W+1)/2)});
  ans4 = max({H/3*W,(H-H/3)*(W/2),(H-H/3)*((W+1)/2)})
  - min({H/3*W,(H-H/3)*(W/2),(H-H/3)*((W+1)/2)});
  ans5 = max({(W+2)/3*H,(W-(W+2)/3)*(H/2),(W-(W+2)/3)*((H+1)/2)})
  - min({(W+2)/3*H,(W-(W+2)/3)*(H/2),(W-(W+2)/3)*((H+1)/2)});
  ans6 = max({W/3*H,(W-W/3)*(H/2),(W-W/3)*((H+1)/2)})
  - min({W/3*H,(W-W/3)*(H/2),(W-W/3)*((H+1)/2)});

  cout << min({ans1,ans2,ans3,ans4,ans5,ans6}) << endl;
}

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

int main(){
  int N, ans=0;
  string S;
  cin >> N >> S;
  for(int i=0; i<N-2; i++){
    if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C')
      ans++;
  }
  cout << ans << endl;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<int> memo(n,0);
  ll ans = 0;
  for(int i=0; i<n-1; ++i){
    if(s[i] == 'B' && s[i+1] == 'C'){
      int x = i-1;
      int cnt = 0;
      while(x>=0 && s[x] == 'A'){
        ++cnt;
        --x;
      }
      ans += cnt;
      if(x>=0) ans += memo[x];
      memo[i+1] = cnt;
      if(x>=0) memo[i+1] += memo[x];
    }
  }
  cout << ans << endl;
}

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

int main() {
  long seven = 0;
  long K;
  cin >> K;
  for(long i = 1; i < 1000000; i++){
   seven = 10 * seven + 7;
   seven %= K;
   if(seven == 0){
    cout << i << endl;
    return 0;
   }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int n, p;
string s;

ll a[200010];

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

    if (p == 2 || p == 5) {
        ll ans = 0;
        rep(i, n) {
            if ((s[i] - '0') % p == 0) ans += 1 + i;
        }
        cout << ans << endl;
        return 0;
    } else {
        reverse(all(s));
        map<int, ll> m;
        m[0] = 1;
        ll x = 1;
        rep(i, n) {
            a[i+1] = (a[i] + x * (s[i] - '0')) % p;
            m[a[i+1]]++;
            x *= 10;
            x %= p;
        }

        ll ans = 0;
        rep(i, p) {
            ans += m[i] * (m[i] - 1) / 2;
        }
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 2564
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def solve(N,D):
    if D[0]:
        return 0

    try:
        _ = D[1::].index(0)
        return 0
    except:
        pass
    
    nums = Counter(D)
    nums = sorted(nums.items())
    if len(nums) != nums[-1][0]+1:
        return 0
        
    #print(nums)
    ans = 1
    for i in range(len(nums)-1):
        ans *= nums[i][1]**nums[i+1][1]
        ans %= 998244353
    return ans

def main():
    N = int(input())
    D = list(map(int, input().split()))
    
    print(solve(N,D))

if __name__ == '__main__':
    main()


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int n,m;
int dp[50001];
int c[20];

int solve(){
    dp[0]=0;
    REP(i,n+1){
        REP(j,m){
            if(i>=c[j]){
                dp[i]=min(dp[i],dp[i-c[j]]+1);
            }
        }
    }
    return dp[n];
}

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

    REP(i,m)cin >> c[i];
    REP(i,50001)dp[i]=50001;

    int ans=solve();
    cout << ans << endl;
}



Measured memory_bytes: 3304
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        System.out.println(n>k?k*x+(n-k)*y:n*x);
    }
}


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

#define endl ('\n')
#define all(x) (x).begin(),(x).end()

template<typename Type>
Type gcd(const Type a,const Type b){return(b==0)?a:gcd(b,a%b);}
template<typename Type>
Type lcm(const Type a,const Type b){return(a/gcd(a,b))*b;}

template<typename Type>
void sort(vector<Type>& v){
	sort(all(v));
}

int main(){
	int N,X,Y;
	cin >> N >> X >> Y;

	int ans[N]={};

	for(int i=1;i<=N;i++){
		for(int j=i+1;j<=N;j++){
			int k = min(abs(i-j),min(abs(i-X)+abs(j-Y)+1,abs(i-Y)+abs(j-X)+1));
			ans[k]++;
			//cout << i << ", " << j << ", " << k << endl;
		}
	}

	for(int k=1;k<N;k++) cout << ans[k] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int max(int a,int b)
{
	if(a>b)
	{
		return a;
	}
	else
	{
		return b;
	}
}
int max3(int a,int b,int c)
{
	if(a>=b&&a>=c)
	{
		return a;
	}
	else if(b>=a&&b>=c)
	{
		return b;
	}
	else
	{
		return c;
	}
}
int main(void)
{
	int n;
	scanf("%d",&n);
	int dp[n][3];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			scanf("%d",&dp[i][j]);
		}
	}
	
	for(int i=1;i<n;i++)
	{
		for (int j = 0; j < 3; ++j)
		{
			if(j==0)
			{
				dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
			}
			else if(j==1)
			{
				dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
			}
			else if(j==2)
			{
				dp[i][2]+=max(dp[i-1][0],dp[i-1][1]);
			}

		}
	}


	printf("%d\n",max3(dp[n-1][0],dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	string s;

	map<string, int> m;
	for(int i = 0; i < n; i++)
	{
		cin>>s;
		m[s]++;
		// if(s=='')
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;


	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(){
  long long int l[100];
  int x,i,a;

  scanf("%d",&x);

  l[0]=2;
  l[1]=1;
  for(i=2;i<=x;i++){

    l[i]=l[i-1]+l[i-2];

  }

  printf("%lld",l[x]);
  return 0;
}



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

int main()
{
    int a[100005],b[100005]={0};
    int p,q;
    int n,m,cnt=0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<m;i++)
    {
        scanf("%d %d",&p,&q);
        p--;
        q--;
        if(a[p]>a[q])
        {
            b[q]++;
        }
        else if(a[p]<a[q])
        {
            b[p]++;
        }
        else if(a[p]==a[q])
        {
            b[p]++;
            b[q]++;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(b[i]==0)
        {
            cnt++;
            //printf("%d ",i);
        }
    }
    printf("%d\n",cnt);
    
    return 0;
}


Measured memory_bytes: 4608
// Java implementation of Kosaraju's algorithm to print all SCCs
import java.io.*;
import java.util.*;
import java.util.LinkedList;

// This class represents a directed graph using adjacency list
// representation
public class Main
{ // Driver method
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        String str=in.nextLine();
        int ans=0;
        for (int i = 0; i <str.length(); i++) {
            if(str.charAt(i)=='+'){
                ans++;
            }else{
                ans--;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 21460
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split(/[ |\n]/);
  const n = Number(lines.shift());
  const arr = lines.map(Number);
  buildMaxHeap(arr, n);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr, n) {
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 148408
/**
*    created: 05.07.2020 21:02:25
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int c0 = 0;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    rep(i,n) {
        string s;
        cin >> s;
        if (s == "AC") c0++;
        else if (s == "WA") c1++;
        else if (s == "TLE") c2++;
        else c3++;
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  
  vector<int>dp(n,0);
  for(int i=1;i<n;i++){
    int mincost= abs(h.at(i)-h.at(max(0,i-k)))+dp.at(max(i-k,0));
    for (int j=max(0,i-k+1);j<i;j++){
      mincost= min(mincost,abs(h.at(i)-h.at(j))+dp.at(j));
    }
    dp.at(i)=mincost;
      
  }
  printf("%d",dp.at(n-1));
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>

using namespace std;

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

    long long N;
    vector<long long> vec_trans(5);

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

    long long min_val = *min_element(vec_trans.begin(), vec_trans.end());

    long long total = ((N - 1) / min_val + 1) + 4;

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, k, s, cut=0;
	scanf("%d%d", &n, &k);
	while(n != 0){
		n/=k;
		cut++;
	}
	printf("%d", cut);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
const ll INF = 4e18;
const ll MOD = 1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = a[0];
  for (int i = 1; i < n; i++) ans = __gcd(ans, a[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
const int mod = 1000000007;

int ys_num(int num){
    int ret = 1;
    for(int i = 1; i <= num/2; i++){
        if(num % i == 0){
            ret++;
        }
    }
    return ret;
}


int main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(i % 2 == 1 && ys_num(i) == 8){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;     // 
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    int n, m; cin >> n >> m;
    vector<PLL> p(m); REP(i,m) cin >> p[i].first >> p[i].second;

    sort(p.begin(), p.end());
    for (int i=0; i<m-1; i++) {
        if (p[i].first==p[i+1].first&&p[i].second!=p[i+1].second) {
            cout << "-1" << endl;
            return 0;
        }
    }

    for (int i=0; i<1000; i++) {
        string str = to_string(i);
        if ((int)str.size()==n) {
            bool f = true;
            for (int j=0; j<m; j++) {
                if ((str[p[j].first-1]-'0')==p[j].second) ;
                else f = false;
            }
            if (f == true) {
                cout << str << endl;
                return 0;
            }
        }
    }

    cout << "-1" << endl;

    return 0;
}


Measured memory_bytes: 3640
/*
                    Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
            
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }     
signed main()
{   jaldi
    int a;
    cin>>a;
    int b;
    cin>>b;
    if(a>b)
    {   int temp=a;
        a=b;
        b=temp;
    }
    if(a==1 && b==2)
    cout<<3;
    if(a==1 && b==3)
    cout<<2;
    if(a==2 && b==3)
    cout<<1;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<stack>
#include<algorithm>
using namespace std;
struct Num{
	int x,y,index;
}num[200005];
int right[200005],sz[200005],par[200005],left[200005],ans[200005];
bool cmp(Num a,Num b){
	return a.x<b.x;
}
int find(int x){
	if(x==par[x])
		return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)
		return;
	// if(sz[x]<sz[y]){
	// 	sz[y]+=sz[x];
	// 	sz[x]=0;
	// 	par[x]=y;
	// }
	else{
		sz[x]+=sz[y];
		sz[y]=0;
		par[y]=x;
	}
}
stack<int> st;
int main(){
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&num[i].x,&num[i].y);
		num[i].index=i;
		par[i]=i;
		sz[i]=1;
	}
	sort(num,num+n,cmp);
	st.push(0);
	for(i=1;i<n;i++){
		if(st.empty()||num[st.top()].y>num[i].y)
			st.push(i);
		else{
			auto x=st.top();
			while(st.size()&&num[i].y>num[st.top()].y){
				unite(i,st.top());
				st.pop();
			}
			st.push(x);
		}
	}
	for(i=0;i<n;i++)
		ans[num[i].index]=sz[find(i)];
	for(i=0;i<n;i++)
		printf("%d\n",ans[i]);
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// vector<int>を渡してあげると、それを元に遅延セグメント木を構築する。
// 区間加算です。いじれそうだったらいじって。

struct LazySegmentTree {
 private:
  int n;  // 最下段のノード数
  vector<ll> node, lazy;

 public:
  LazySegmentTree(vector<ll> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;  // 元のサイズ以上の最小の2冪
    node.resize(2 * n - 1, 0);
    lazy.resize(2 * n - 1, 0);

    // 最下段に突っ込む
    for (int i = 0; i < sz; i++) node[(n - 1) + i] = v[i];

    // 最下段以外を更新していく(下から上に)
    for (int i = n - 2; i >= 0; i--) {
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }
  }

  // 遅延評価をk番目について行う
  void eval(int k, int l, int r) {
    // 遅延配列が空でないなら、自ノード及び子ノードに伝搬する
    if (lazy[k]) {
      node[k] += lazy[k];

      // 最下段ならここは実行されません
      if (r - l > 1) {
        lazy[k * 2 + 1] += lazy[k] / 2;
        lazy[k * 2 + 2] += lazy[k] / 2;
      }
      lazy[k] = 0;  // 自分のぶんは役目を果たしたので
    }
  }

  // [a,b)に遅延評価をする。[l,r)は今呼ばれている区間。上から降りていく。
  void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
    // 右端を要素の長さに
    if (r < 0) r = n;
    // まず呼ばれたので自分の所に遅延評価を施す
    eval(k, l, r);
    // 俺は関係ない
    if (r <= a || b <= l) return;
    // 完全に範囲に入っているので
    if (a <= l && r <= b) {
      lazy[k] += (r - l) * x;  // 横幅ぶん掛けたのを足す
      eval(k, l, r);
    } else {  // 部分的に重なっているので子ノードに投げる
      add(a, b, x, k * 2 + 1, l, (l + r) / 2);
      add(a, b, x, k * 2 + 2, (l + r) / 2, r);
      node[k] = node[k * 2 + 1] + node[k * 2 + 2];
    }
  }

  // [a,b) 中の結果を返す。[l,r)は対象区間の左端と右端。
  ll getsum(int a, int b, int now = 0, int l = 0, int r = -1) {
    // 右端を初期化
    if (r < 0) r = n;

    // 俺は関係ないとき -> 答えの邪魔にならない値を返す
    if (r <= a || b <= l) return 0;

    // ここまで来た時点で少なくとも重なっているので、遅延評価
    eval(now, l, r);

    // 要求区間の中にノードがすっぽり入ってる → 計算候補として返す
    if (a <= l && r <= b) return node[now];

    // ノードの一部分だけ要求区間に入ってる → 子を再帰的に探索する
    ll vl = getsum(a, b, 2 * now + 1, l, (l + r) / 2);  // 子(左)
    ll vr = getsum(a, b, 2 * now + 2, (l + r) / 2, r);  // 子(右)
    return vl + vr;
  }
};

// ====================================================================

int main() {
  ll n, d, a;
  cin >> n >> d >> a;

  vector<pair<ll, ll>> v;
  for (int i = 0; i < n; i++) {
    ll x, h;
    cin >> x >> h;
    v.push_back(make_pair(x, h));  // 位置,体力
  }
  sort(v.begin(), v.end());

  vector<ll> pos(n);   // 出る順に位置を並べている
  vector<ll> moto(n);  // 出る順に体力を並べている
  for (int i = 0; i < n; i++) pos[i] = v[i].first;
  for (int i = 0; i < n; i++) moto[i] = v[i].second;

  ll w = 1 + d * 2;  // 幅
  ll ans = 0;
  LazySegmentTree laz(moto);  // 出てくる順に体力を並べた遅延セグ木
  // for (int i = 0; i < n; i++) {
  //   cout << laz.getsum(i, i + 1) << endl;
  // }
  for (int i = 0; i < n; i++) {
    ll now = laz.getsum(i, i + 1);
    if (now > 0) {               // 体力が残っている
      ans += (now + a - 1) / a;  // 回数を足す
      int right = lower_bound(pos.begin(), pos.end(), pos[i] + w) - pos.begin();
      laz.add(i, right, (now + a - 1) / a * a * -1);  // 引く
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 16620
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		TreeMap<String, Integer> map = new TreeMap<>();
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			int op = sc.nextInt();
			String key = sc.next();
			switch (op) {
				case 0:
					map.put(key, sc.nextInt());
					break;
				case 1:
					if (Objects.isNull(map.get(key))) {
						sb.append(0);
						sb.append('\n');
					} else {
						sb.append(map.get(key));
						sb.append('\n');
					}
					break;
				case 2:
					map.remove(key);
					break;
				case 3:
					String r = sc.next();
					Map<String, Integer> submap = map.subMap(key, r);
					for (String str : submap.keySet()) {
						sb.append(str);
						sb.append(' ');
						sb.append(map.get(str));
						sb.append('\n');
					}
					if (map.get(r) != null) {
						sb.append(r);
						sb.append(' ');
						sb.append(map.get(r));
						sb.append('\n');
					}
					break;
			}
		}
		System.out.print(sb.toString());
	}
}



Measured memory_bytes: 197140