akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int max = -1,ans=0;
        for(int i=0;i<n;i++){
            int h = scanner.nextInt();
            if(max <= h){
                max = h;
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int x;

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> x;
    ff(i,1,360){
        if(x*i % 360 == 0){
            cout << i << "\n";
            return 0;
        }
    }
    return 0;
}


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

template<class edge_type,class weight_type> std::pair<std::vector<weight_type>,bool> bellmanford(const int size,const std::vector<edge_type> &edges ,const int start){
    std::vector<weight_type> dist(size,std::numeric_limits<weight_type>::max());
    bool negative_cycle=false;
    dist[start]=0;
    for(int i=0; i<size; ++i){
        bool update=false;
        for(const edge_type &e:edges){
            const int u=e.from,v=e.to;
            if(dist[u]!=std::numeric_limits<weight_type>::max() and dist[v]>dist[u]+e.weight){
                dist[v]=dist[u]+e.weight;
                update=true;
            }
        }
        if(!update) break;
        if(i==size-1 and update) negative_cycle=true;
    }
    return std::make_pair(dist,!negative_cycle);
}

struct edge{
    int from,to,weight;
};

void solve(){
    int v,e,r;
    cin >> v >> e >> r;
    vector<edge> edges;
    rep(i,0,e){
        int s,t,d;
        cin >> s >> t >> d;
        edges.push_back(edge{s,t,d});
    }
    auto ans=bellmanford<edge,int>(v,edges,r);
    if(!ans.second){
        cout << "NEGATIVE CYCLE" << endl;
        return;
    }
    rep(i,0,v){
        if(ans.first[i]==std::numeric_limits<int>::max()) cout << "INF" << endl;
        else cout << ans.first[i] << 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: 9148
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;
    vector<P> items(M);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        ll key = 0;
        rep(j, b) {
            ll c;
            cin >> c;
            c--;
            key |= (1 << c);
        }
        items[i] = make_pair(key, a);
    }
    vector<ll> dp(1 << N, INF);
    dp[0] = 0;
    rep(s, 1 << N) {
        rep(i, M) {
            P p = items[i];
            dp[s | p.first] = min(dp[s | p.first], dp[s] + p.second);
        }
    }
    ll ans = dp[(1 << N) - 1];
    cout << (ans == INF ? -1 : ans) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

using i64 = long long;
constexpr i64 MOD = 1000000007;
constexpr int MAX = 500000;

i64 fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
                fac[i] = fac[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
        }
}

i64 COM(int n, int k) {
        if (n < k || n < 0 || k < 0) return (0);
        return (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
}

int main() {
        int N, K;
        int A[100005];

        ll maxc = 0, minc = 0;

        cin >> N >> K;  
        COMinit();
        for (int i = 1; i <= N; i++) cin >> A[i];
        sort(A + 1, A + N + 1);
        for (int i = 1; i <= N - K + 1; i++) (minc += (ll)A[i] * COM(N - i, K - 1)) %= MOD;
        for (int i = K; i <= N; i++) (maxc += (ll)A[i] * COM(i - 1, K - 1)) %= MOD;
        
        cout << (maxc + MOD - minc) % MOD << endl;

    return (0);
}

Measured memory_bytes: 12416
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(index, begin, end) for (int (index) = (begin); (index) < (end); (index)++)
#define RE(index, end) REP(index, 0, end)
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define DINT(x) printf(#x " = %d\n", x);
#define GETINT(x) scanf("%d", &x)
#define GETLL(x) scanf("%lld", &x)
#define GETSTR(x) scanf("%s", x)

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

struct town_t
{
	vector<int> roads;
	int danger;
	ll cost;
};

int town_n, road_n, ztown_n, danger_n,
	low_yen, high_yen;
vector<town_t> towns;
vector<int> ztowns;

void setDanger()
{
	queue<int> que;
	RE(i, ztown_n)
	{
		towns[ztowns[i]].danger = danger_n;
		que.push(ztowns[i]);
	}
	while (!que.empty())
	{
		int now_town = que.front();
		que.pop();
		vector<int> &roads = towns[now_town].roads;
		int next_danger = towns[now_town].danger - 1;
		RE(i, roads.size())
		{
			if (towns[roads[i]].danger < next_danger)
			{
				towns[roads[i]].danger = next_danger;
				if (next_danger > 1)
				{
					que.push(roads[i]);
				}
			}
		}
	}
}

void exploreRoad()
{
	towns[0].cost = 0;
	towns[0].danger = 0;
	towns[town_n - 1].danger = 0;
	while (true)
	{
		bool updated = false;
		RE(i, town_n)
		{
			if (towns[i].danger == danger_n)
			{
				continue;
			}
			vector<int> &roads = towns[i].roads;
			RE(j, roads.size())
			{
				town_t &town_to = towns[roads[j]];
				if (town_to.danger == danger_n)
				{
					continue;
				}
				ll to_cost = towns[i].cost +
					((town_to.danger > 0) ? high_yen : low_yen);
				if (towns[i].cost != LLINF &&
					town_to.cost > to_cost)
				{
					town_to.cost = to_cost;
					updated = true;
				}
			}
		}
		if (!updated)
		{
			break;
		}
	}
}

int main()
{
	GETINT(town_n);
	GETINT(road_n);
	GETINT(ztown_n);
	GETINT(danger_n);
	GETINT(low_yen);
	GETINT(high_yen);
	ztowns.reserve(ztown_n);
	RE(i, ztown_n)
	{
		int temp;
		GETINT(temp);
		ztowns.push_back(temp - 1);
	}
	towns.resize(town_n, { vector<int>(), 0, LLINF });
	RE(i, road_n)
	{
		int a, b;
		GETINT(a);
		GETINT(b);
		a--;
		b--;
		towns[a].roads.push_back(b);
		towns[b].roads.push_back(a);
	}
	danger_n++;
	setDanger();
	exploreRoad();
	printf("%lld\n", towns[town_n - 1].cost - low_yen);
	return 0;
}

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

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

	cout << ans << "\n";
	return 0;
}

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

int main(){
    int n;
    std::cin >> n;
  
  	int ans = 0;
  	for(int i = 1; i <= n; ++i){
		if(0 == i % 2){
          continue;
        }
      
      	int count = 0;
		for(int j = 1; j <= std::sqrt(i); ++j){
          	int k = i / j;
          	if(k != j && i == k * j){
               	count += 2;
            }
        }

	    if(8 == count){
          	++ans;
        }
    }
  
  	std::cout << ans << std::endl;
  
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int N,A[100],i,j,k,v;

  scanf("%d",&N);

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}
int char_to_int(char val) {
    return val - '0';
}

int main() {
  int N; cin >> N;
  vector<int> A(N - 1); REP(i, N - 1) cin >> A[i];
  map<int, int> m;

  for(int i = 0; i < N ; ++i) {
    m[i + 1] = 0;
  }

  REP(i, N - 1) {
    m[A[i]]++;
  }

  for(auto i = m.begin(); i != m.end(); ++i) {
    std::cout << i->second << std::endl;
  }
}

Measured memory_bytes: 13556
#include<iostream>
#include<vector>
#include<queue>
#include<climits>
using namespace std;

struct Edge{ int to,cost; };

typedef pair<int,int> P;
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void dijkstra(Graph &G,vector<int> &d,int n,int s){
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(),d.end(),INT_MAX);
	d[s]=0;
	que.push(P(0,s));
	
	while(!que.empty()){
		P p=que.top();
		que.pop();
		
		int a=p.second;
		if (d[a]<p.first){
			continue;
		}
		for (int i=0;i<G[a].size();i++){
			Edge e = G[a][i];
			if (d[e.to]>d[a]+e.cost){
				d[e.to]=d[a]+e.cost;
				P p2=P(d[e.to],e.to);
				que.push(p2);
			}
		}
	}
}

int main(){
	int n,i,j,k;
	vector<int> d(n);
	Edge e;
	
	cin >> n;
	
	Graph G(n);
	
	for (i=0;i<n;i++){
		cin >> k >> k;
		for (j=0;j<k;j++){
			cin >> e.to >> e.cost;
			G[i].push_back(e);
		}
	}
	
	dijkstra(G,d,n,0);
	
	for (i=0;i<n;i++){
		cout << i << " " << d[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 17428
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <stdlib.h>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <queue>
#include<unordered_map>
#include <queue>
#include <list>
#define mod 1000000007
typedef unsigned long long int ll;
using namespace std;

  

 
//    0 1 1 2 3 5 
  // 2

int main() 
{ 
    // Input number of nodes 
    int n;ll wt;
    cin>>n;
    ll p=(ll)(pow(n,3));
    cout<<p<<"\n";
  
    return 0; 
} 



Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

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


signed main(){

	int N, A, B, C;
	cin >> N >> A >> B >> C;
	int len[8];
	rep(i, N) cin >> len[i];

	int ans = INF;
	for (int i = 0; i < (2 << (2*N)); i++){
		set<int> s[3];
		int tmp = i;
		int keta = 0;
		while (tmp > 0){
			if (tmp % 4 == 1) s[0].insert(keta);
			else if (tmp % 4 == 2) s[1].insert(keta);
			else if (tmp % 4 == 3) s[2].insert(keta);
			tmp /= 4;
			keta++;
		}

		if (s[0].size() == 0 || s[1].size() == 0 || s[2].size() == 0) continue;

		int MP = 0;
		int total = 0;
		for (int k : s[0])
			total += len[k];
		MP += abs(total - A) + (s[0].size() - 1) * 10;

		total = 0;
		for (int k : s[1])
			total += len[k];
		MP += abs(total - B) + (s[1].size() - 1) * 10;

		total = 0;
		for (int k : s[2])
			total += len[k];
		MP += abs(total - C) + (s[2].size() - 1) * 10;

		ans = min(ans, MP);

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[20];
    scanf("%s",s);
    int k=0,l,i,j=0,c=0;
    l=strlen(s);
    if(s[0]=='A') k++;
    for(i=2;i<l-1;i++)
    {
        if(s[i]=='C') j++;
        if(s[i]>='a') c++;
    }
    //printf("%d\n",k);
    if(j==1) k++;
    //printf("%d\n",k);
    if(s[1]>='a'&&s[l-1]>='a') c+=2;
    if(c==l-2) k++;
    //printf("%d\n",k);
    if(k==3) printf("AC\n");
    else printf("WA\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N;
    cin>>N;
    

    auto v={0,0,0};
    map<ll,ll> ans;
    for(ll i=1;i<100;i++){
        for(ll j=1;j<100;j++){
            for(ll k=1;k<100;k++){
                ll t=i*i+j*j+k*k+i*j+j*k+k*i;
                ans[t]++;
            }
        }
    }
    
    REP1(i,N){
        cout<<ans[i]<<endl;
    }
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 5884
#include<stdio.h>
int main()
{
	char s[10];
	int n,k,i;
	scanf("%d",&n);
	scanf("%s",&s);
	scanf("%d",&k);
	for(i=0;i<n;i++)
	{
		if(s[i]!=s[k-1])
			s[i]='*';
	}
	printf("%s\n",s);
	return 0;
}




Measured memory_bytes: 128
//****author RKN
//DATE 5/2/2020 5.15 AM
 
 
// ***************DREAM IS NOT THAT YOU SEE WHILE SLEEPING BUT IT IS WHAT DONT LET YOU SLEEP************//
 
 
///////////////////////    machayenge......sala hoga apne se bhi ek din    ///////////////////////////////////////////////////////////
 
#include<bits/stdc++.h>
#include <utility> 
using namespace std;
 
/////////////////////////////   %   variable  %   //////////////////////////////////////////////////////////////
 
#define ll long long
#define pb push_back 
#define pof pop_front
#define f1 first
#define s2 second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pr pair<ll,ll>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define loop(start,end,inc) for(int i=start;i<=end;i+=inc)
typedef std::vector<std::vector<int>> vec2d;
#define pr1 pair<ll,pair<ll,ll>>
//#define prm pair<ll,map<ll,ll>>
int dir1[8]={1,-1,0,0,-1,1,-1,1};
int dir2[8]={0,0,-1,1,-1,1,1,-1};
#define en "\n"

//void rtime(){time_p=clock()-time_p;cerr<<"******************\nTime taken : "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";}

ll MAX=1000000007;
//ll MAX=13;
vector<ll>prime(1000001);
vector<ll>getprm;
ll power(ll a,ll b)
{
       if(b == 0)
       return 1;
       auto q= (power( a, (b/2) ));
       q=q%MAX;
       q = (q * q) % MAX;
       if ( b%2 == 0)
       return q%MAX;
       else
       return ((q%MAX)*(a%MAX)) % MAX;
}

ll modinv ( ll val )
{
       return power ( val, MAX-2 );
}
 
void primecalc()
{
       fill(all(prime),1);
       prime[0]=0;prime[1]=0;
       for(int i=2;i<=sqrt(1000001);i++)
       {
              if(prime[i])
              {
                     //cout<<i<<" ";
                     getprm.pb(i);
                     for(int j=i+i;j<=1000000;j+=i)
                     prime[j]=0;
              }
       }
}

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

vector<ll>mp(100001);
ll n;
vector<ll>v;
ll dfs(ll val,ll prev)
{
    if(val>n){return 100005;}
   if(val==n)
   {return abs(v[val]-v[prev]);}
   if(mp[val]!=100005)
   return mp[val]+abs(v[prev]-v[val]);
  ll val1=dfs(val+2,val);
  ll val2=dfs(val+1,val);
  mp[val]=min(val1,val2);
  return mp[val]+abs(v[val]-v[prev]);
}

int main()
{
    fast;
    fill(all(mp),100005);
    ll a;
    cin>>n;
    v.pb(0);
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.pb(a);
    }
    ll res=dfs(1,1);
    cout<<res;
    return 0;
}


Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  string T;
  cin >> T;
  vector<char> S(T.size());
  if (T[0] == '?') {
    if (T[1] == 'P') {
      S[0] = 'D';
    } else {
      S[0] = 'P';
    }
  } else {
    S[0] = T[0];
  }
  for (int i = 1; i < T.size() - 1; i++) {
    if (T[i] != '?') {
      S[i] = T[i];
      continue;
    }
    if(S[i-1]=='P'){
      S[i] = 'D';
      continue;
    }
    if (T[i + 1] == 'D' || T[i + 1] == '?') {
      S[i] = 'P';
    } else {
      S[i] = 'D';
    }
  }
  if (T[T.size()-1] == '?') {
    S[T.size() - 1] = 'D';
  } else {
    S[T.size() - 1] = T[T.size() - 1];
  }
  REP(i, S.size()) cout << S[i];
  cout << endl;
}

Measured memory_bytes: 3924
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m,p,q,r,x,y,t;
	vector<int>::iterator itx,ity,it;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
		vector<int> v1,v2;
		v1.push_back(0);
		v1.push_back(r);
		
		for(;m--;v2.clear()){
			cin>>x>>y;
			itx=upper_bound(v1.begin(),v1.end(),x);
			ity=upper_bound(v1.begin(),v1.end(),y);
			
			if( ity-v1.begin()+1 & 1 )v2.push_back(0);
			v2.push_back(0);
			for(it=ity;it!=v1.end();++it)
				v2.push_back(*it - y);
			
			if(v1.end()-itx & 1)v2.push_back(n-y);
			for(it=itx;it!=ity;++it)
				v2.push_back(*it-x+n-y);
			
			it = v1.begin();
			if(ity-v1.begin() & 1)++it;
			if(!it[1])it+=2;	//d¡r
			if(*it+n-x==v2.back()){++it;v2.pop_back();}	//d¡r
			for(;it!=itx;++it)
				v2.push_back(*it+n-x);
			
			v1.swap(v2);
		}
		v1.insert( upper_bound(v1.begin(),v1.end(),p-1), 2, p-1);
		v1.insert( lower_bound(v1.begin(),v1.end(),q), q );
		v1.push_back(n);
		it = upper_bound(v1.begin(),v1.end(),p-1);
		if(it-v1.begin() & 1) --it;
		for(x=0;*it<q;++it){
			m=*it;
			++it;
			x+=*it-m;
		}
	}
}

Measured memory_bytes: 0
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, K := nextInt(), nextInt()
	var ans int
	for i := 0; i < N; i++ {
		if nextInt() >= K {
			ans++
		}
	}
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>

int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s;
	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,i,ans;
    int value[a],cost[a];
    scanf("%d",&a);
    for(i=0;i<a;i++){
    scanf("%d",&value[i]);
    }
    for(i=0;i<a;i++){
    scanf("%d",&cost[i]);
    }
    ans = 0;
    for(i=0;i<a;i++){
          if(value[i] > cost[i]) {
            ans += value[i] - cost[i];
          }
    }
 printf("%d",ans);
 return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    int a, b;
    char op;
    int result;

    while (1){
        scanf("%d %c %d", &a, &op, &b);
        if (op == '+'){
            result = a + b;
        }else if (op == '-'){
            result = a - b;
        }else if (op == '*'){
            result = a * b;
        }else if (op == '/'){
            result = a / b;
        }else if (op == '?'){
            break;
        }else{
            printf("ERROR!\n");
        }

        printf("%d\n", result);
    }

    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a, b, c, n, k, x;
    string s, t;
    ll ans = 0;
    double dans = 0;
    string sans = "YES";



    cin  >> a ;
    ll co = 0;

    rep(i, a){
        ll tmp;
        cin >> tmp;
        if(i+1 != tmp) co++;

        if(co > 2) {
            sans = "NO";
            break;
        }
    }



    // std::cout << ans << endl; 
    std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n,w[200001],v[200001],ans,tmp;
map<ll,ll> m;

int main()
{Tie
	m[0]=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>w[i];
	for(int i=0;i<n;i++)
		cin>>v[i];
	for(int i=0;i<n;i++)
	{
		auto p=m.upper_bound(w[i]);
		p--;
		ans=max(ans,m[w[i]]=p->S+v[i]);
		tmp=p->S+v[i],p++,p++;
		while(p!=m.end()&&p->S<=tmp)
		{
			auto tmp=p++;
			m.erase(tmp);
		}
	}
	cout << ans<<'\n';
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)

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

	bool A[10000], B[10000];
	rep(i, a, b) A[i] = true;
	rep(i, c, d) B[i] = true;
	int ans = 0;
	rep(i, 0, 10000) if (A[i] && B[i]) ans++;

	cout << ans << endl;

	return 0;
}

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

int n, a, b, c, ar[1000005];
int main () {
	ios_base::sync_with_stdio (0);
  	cin.tie (0);
  	cin >> n;
  	for (int i = 1; i <= n; i++) cin >> ar[i];
  	a = 0;
  	b = c = abs (ar[2] - ar[1]);
    for (int i = 3; i <= n; i++) {
    	c = min (a + abs (ar[i - 2] - ar[i]), b + abs (ar[i - 1] - ar[i]));
      	a = b;
      	b = c;
    }
  	cout << c << '\n';
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n+x-1)/x * t << endl;
}
/*



*/

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long answer = 0;
    long n = sc.nextLong();
    long i = 0;
    while(i < n){
      i++;
      if(i % 3 == 0 || i % 5 == 0) continue;
      answer += i;
    }
    System.out.println(answer);
  }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i = (n); i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(1e6+5);

void pre() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int x;  cin>>x;
  if(x >= 1800) cout<<1;
  else if(x >= 1600)  cout<<2;
  else if(x >= 1400)  cout<<3;
  else if(x >= 1200)  cout<<4;
  else if(x >= 1000)  cout<<5;
  else if(x >= 800) cout<<6;
  else if(x >= 600) cout<<7;
  else  cout<<8;
}

int main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  pre();
  int t = 1;
  //cin>>t;
  rep(i,t)  {
    //cout<<"Case #"<<(i+1)<<": ";
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

//Orthogonal
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double[][] p = new double[4][2];
			for(int i=0;i<4;i++){
				p[i][0] = sc.nextDouble();
				p[i][1] = sc.nextDouble();
			}
			double vx1 = p[1][0]-p[0][0];
			double vy1 = p[1][1]-p[0][1];
			double vx2 = p[3][0]-p[2][0];
			double vy2 = p[3][1]-p[2][1];
			System.out.println((vx1*vx2+vy1*vy2)==0?"YES":"NO");
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MN = 100100;
ll w[MN],x[MN];
int main() {
	ios::sync_with_stdio(0);
	memset(x,0,sizeof(x));
	int n;cin >> n;
	for(int i=0;i<=n;i++) {
		cin >> w[i];
	}
	for(int i=0;i<n;i++) {
		cin >> x[i];
	}
	ll tot = 0;
	for(int i=n-1;i>=0;i--) {
		ll b = min(w[i+1],x[i]);
		w[i+1] -= b;
		x[i] -= b;
		tot += b;
		b = min(w[i],x[i]);
		w[i] -= b;
		x[i] -= b;
		tot += b;
	}
	cout << tot << '\n';
}


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

int main(){
    string s;
    cin >> s;
    string ans = "Yes";
    rep(i,s.size()){
        if(i%2==0 && s.at(i) == 'L'){
            ans ="No";
            break;
        }
        else if(i%2==1 && s.at(i) == 'R'){
            ans ="No";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    ans = [0] * N
    all_xor = 0
    for i in A:
        all_xor ^= i
    for i in range(N):
        ans[i] = all_xor ^ A[i]
    print(*ans)

main()

Measured memory_bytes: 31596
#include <stdio.h>
#include <stdlib.h>

int sortfnc(const void *a,const void *b){
	if(*(int *)a > *(int *)b){return 1;}
	if(*(int *)a == *(int *)b){return 0;}
	return -1;
}

int main(void) {
	int n,c[16],field,turn,i;
	char s[128];
	while(scanf("%d",&n) , n != 0){
		scanf("%s",s);
		for(i = 0;i < 16;i++){c[i] = 0;}
		field = 0;
		for(i = 0;i < 100;i++){
			turn = i % n;
			if(s[i] == 'M'){c[turn]++;}
			if(s[i] == 'S'){c[turn]++;field+=c[turn];c[turn] = 0;}
			if(s[i] == 'L'){c[turn]++;c[turn]+=field;field = 0;}
		}
		qsort(c,n,sizeof(int),sortfnc);
		for(i = 0;i < n;i++){printf("%d ",c[i]);}
		printf("%d\n",field);
	}
	return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
int main()
{
   int n, reverse = 0, t;
   scanf("%d", &n);
   t = n;
   while (t != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + t%10;
      t = t/10;
   }
   if (n == reverse)
      printf("Yes");
   else
      printf("No");

   return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

int n[12];
int N;

int kotae;


void dfs(int a,int b,int c){
	if(a==10){
		kotae = 1;
		return;
	}
	int now = n[a];
	if(now > b)dfs(a+1,now,c);
	if(now > c)dfs(a+1,b,now);
	return;
}
	


int main(){
	cin >> N;
	for(int ii=0;ii <N;ii++){
		for(int i=0;i<10;i++){
			cin >> n[i];
		}
		dfs(0,0,0);
		if(kotae == 1){
			cout << "YES" << endl;
		}
		else cout << "NO" << endl;
		kotae = 0;
	} 
	return 0;
}	
	

Measured memory_bytes: 2996
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n,m;
string a[100];
string b[100];
int flag;
int ff;
int main()
{
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	rep(i,n-m+1)
	{
		rep(j,n-m+1)
		{
			ff=1;
			rep(k,m)
			{
				rep(l,m)
				{
					if(a[i+k][j+l]!=b[k][l])
					{
						ff=0;
					}
				}
			}
			if(ff)flag=1;
		}
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int M{ 100000 };
    int N;
    cin >> N;
    REP( i, N )
    {
        M = (int)( M * 1.05 + 999 ) / 1000 * 1000;
    }
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 3072
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
I=0
while I<=K:
    if not A[I]%10==0:
        A.append(A[I]%10+10*A[I]-1)
    A.append(A[I]%10+10*A[I])
    if not A[I]%10==9:
        A.append(A[I]%10+10*A[I]+1)
    if len(A)>=K:
      break
    I+=1
print(A[K-1])

Measured memory_bytes: 7216
#include <iostream>
#include <algorithm>
#include <cmath>
#include<string>
#include <array>
#include <vector>
using namespace std;

int main() {
	long long A, B, N;
	int i, j=0,k=0;
	string S;
	cin >> N >> A >> B;
	cin >> S;

	for (i = 1; i <= N; i++) {
		if (S[i-1] == 'c') {
			cout << "No" << endl;
		}
		else if (S[i-1] == 'a') {
			if (j < A + B) {
				cout << "Yes" << endl;
				j++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			k++;
			if (j < A + B&&k <= B) {
				cout << "Yes" << endl;
				j++;
			}
			else {
				cout << "No" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll n;
  cin>>n;
  string s="";
  while(n>0)
  {
    ll p=n%26;
    n=n/26;
    if(p==0)
      n--;
    p=(p+25)%26;
    s=s+(char)(p+'a');
  }
  reverse(s.begin(),s.end());
  cout<<s;
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin>>N;
    vector<int> a(N+2,0);
    REP(i,N) cin>>a[i+1];
    int all=0;
    N+=2;
    REP(i,N-1) {
        all+=abs(a[i+1]-a[i]);
    }
    REPF(i,1,N-1) {
        int ans=all;
        ans-=abs(a[i]-a[i-1]);
        ans-=abs(a[i+1]-a[i]);
        ans+=abs(a[i+1]-a[i-1]);
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d) {
    cout << "Yes" << endl;
  }
  else {
    if(abs(a-b)<=d&&abs(b-c)<=d) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    
    for i in range(1, h+1):
        for j in range(1, w+1):
            if (i+j)%2 == 0:
                if j == w:
                    print("#")
                else:
                    print("#", end = "")
            else:
                if j == w:
                    print(".")
                else:
                    print(".", end = "")
    print()


Measured memory_bytes: 7036
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  string S;
  cin >> S;
  int A[4];
  rep(i,4) A[i]=S[i]-'0';
  char op[3];
  rep(bit,8){
    int num=A[0];
    rep(i,3){
      if(bit&(1<<i)){
        num+=A[i+1];
        op[i]='+';
      }
      else{
        num-=A[i+1];
        op[i]='-';
      }
    }
    if(num==7){
      cout << A[0] << op[0] << A[1] << op[1] << A[2] << op[2] << A[3] << "=7" << endl;
      return 0;
    }
  }

  return 0;
}


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

int main(){
  int n, x, a;
  while(1){
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    a = 0;
    for (int i = 1; i <= n; i++) {
       for (int j = 1; j <= n; j++) {
         for (int k = 1; k <= n; k++) {
           if (i < j && j < k && i + j + k == x) a++;
         }
       }
    }

    cout << a << endl;

  }

return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#include <limits.h>
#include <stack>
#include <queue>
#include<cstdlib>
#define maxn 10000000
#define pi acos(-1)
using namespace std;
struct node{
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){//在双向链表中搜索元素；
	node *cur = nil->next;//从头节点后面的元素开始访问；
	while (cur!=nil&&cur->key!=key) {
		cur=cur->next;
	}
	return cur;
}

void init(){//初始化双向链表；
	nil =(node*) malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	NodePointer cur = nil->next;
	int isf = 0;
	while(1){
		if ( cur == nil ) break;
		if ( isf++ > 0)  printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

//从双向链表中删除元素；
void deleteNode(NodePointer t){
	if(t==nil)return;//t为结头时不做处理
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){//删除搜索到的结点；
	deleteNode(listSearch(key));
}



void insert(int key){//往双向链表中插入元素；
	NodePointer x;
	x = (node*)malloc(sizeof(struct node));
	x->key = key;
	//在头结点后添加元素；
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;

}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for ( i = 0; i < n; i++ ){
		scanf("%s%d", com, &key);
		if ( com[0] == 'i' ) {insert(key); np++; size++;}
		else if ( com[0] == 'd' ) {
			if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
			} else {
	deleteKey(key); nd++; 
			}
			size--;
		}
	}
	printList();
	return 0;
}


Measured memory_bytes: 34464
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = sum(A)

for i in range(N):
  if B[i] > A[i]:
    if A[i+1] - (B[i] - A[i]) <=0:
      A[i+1] = 0
    else:
      A[i+1] -= B[i]-A[i]
    A[i] = 0
  else:
    A[i] = A[i] - B[i]

ans -= sum(A)

print(ans)


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

int main() {
    int h, w, a[26], b[4];
    cin >> h >> w;
    fill(a, a+26, 0);
    fill(b, b+4, 0);
    for(int i=0;i<h;i++){
        string s;
        cin >> s;
        for(int j=0;j<w;j++){
            a[s[j] - 'a']++;
        }
    }
    for(int i=0;i<26;i++){
        b[a[i]%4]++;
    }
    if(h%2 + w%2 == 0){
        if(b[1] + b[2] + b[3] > 0)puts("No");
        else puts("Yes");
    }else if(h%2 + w%2 == 1){
        int ev = h;
        if(h%2 == 1)ev = w;
        if(b[1]>0 || b[3]>0 || b[2]*2>ev)puts("No");
        else puts("Yes");
    }else{
        if(b[3] > 0){
            b[3]--;
            b[1]++;
            b[2]++;
        }
        if(b[1]>1 || b[3]>0 || b[2]>h/2+w/2)puts("No");
        else puts("Yes");
    }
	return 0;
}


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

using namespace std;

string ng = "Impossible";

double minCost[30][256]; 

void solve(int n, int m, int p, int a, int b){
    vector<int> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }

    vector<vector<pair<int, int>>> E(m);
    int x, y, z;
    for(int i = 0; i < p; i++){
        cin >> x >> y >> z;
        E[x - 1].push_back(make_pair(y - 1, z));
        E[y - 1].push_back(make_pair(x - 1, z));
    }

    int com = (1 << n);
    for(int i = 0; i < m; i++){
        for(int j = 0; j < com; j++){
            minCost[i][j] = 10000000.0;
        }
    }

    minCost[a][0] = 0.0;

    vector<int> comVec(n, 0);
    for(int i = 0; i < n; i++){
        comVec[n - i - 1] = 1;
        do{
            int index = 0;
            for(int j = 0; j < n; j++){
                if(comVec[j] == 1){
                    index += (1 << j);
                }
            }

            for(int j = 0; j < m; j++){
                double temp = 10000000.0;

                for(auto e: E[j]){
                    int before = e.first;
                    int cost = e.second;

                    for(int k = 0; k < n; k++){
                        if(comVec[k] == 1){
                            int tempIndex = index - (1 << k);
                            temp = min(temp, minCost[before][tempIndex] + (double)cost / t[k]);
                        }
                    }
                }

                minCost[j][index] = temp;
            }

        }while(next_permutation(comVec.begin(), comVec.end()));
    }

    double ansCost = 10000000.0;
    for(int i = 0; i < com; i++){
        double cost = minCost[b][i];
        if(cost < 10000.0){
            ansCost = min(ansCost, cost);
        }
    }

    if(ansCost > 10000.0){
        cout << ng << endl;
    }
    else{
        cout << fixed << setprecision(9) << ansCost << endl;
    }
}

int main(){

    while(1){
        int n, m, p, a, b;
        cin >> n >> m >> p >> a >> b;
        if(n == 0){
            break;
        }

        solve(n, m, p, a - 1, b - 1);
    }

    return 0;
}


Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main() {
  string str;
  cin >> str;
  if(str == "ABC"){co("ARC");}
  else{co("ABC");}
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
char a[200010];
vector<int>w,r;
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",a);
	for(int i=0;i<n;i++){
		if(a[i]=='W')w.push_back(i);
		else r.push_back(i);
	}
	int l=0,s=0;
	for(int i=r.size()-1;i>=0;i--){
		if(l<w.size()&&r[i]>w[l])l++,s++;
	}
	printf("%d",s);
} 

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

const int INF = 1001001001;

int ck(int a)
{
    if (a == 1)
    {
        return 0;
    }
    for (int i = 2; i * i <= a; i++)
    {
        if (a % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

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

    vector<int> l(q), r(q);
    rep(i, q) cin >> l[i] >> r[i];
    int r_max = -INF;
    rep(i, q) r_max = max(r_max, r[i]);

    vector<int> tmp(100000 + 10, 0), s(100000 + 10, 0);
    rep(num, r_max + 1)
    {
        if (num % 2 == 0)
            continue;
        if (ck(num) && ck((num + 1) / 2))
        {
            tmp[num]++;
        }
    }
    // rep(i, tmp.size())
    // {
    //     if (0 <= i && i <= r_max)
    //     {
    //         cout << tmp[i] << ' ';
    //     }
    // }
    // cout << endl;

    rep(i, s.size())
    {
        s[i + 1] = s[i] + tmp[i];
    }

    // rep(i, s.size())
    // {
    //     if (0 <= i && i <= r_max)
    //     {
    //         cout << s[i] << ' ';
    //     }
    // }
    // cout << endl;

    rep(i, q)
    {
        cout << s[r[i] + 1] - s[l[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
N = int(input())
A = list(map(int, input().split()))
start = [0]*N
ans = 0
for i in range(N):
    if i+A[i]+1 < N:
        start[i+A[i]+1] += 1

for i in range(N):
    if i-A[i]+1 < 0:
        continue
    if i-A[i]+1 >= N:
        continue
    ans += start[i-A[i]+1]

print(ans)


Measured memory_bytes: 32176
N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    # tupleじゃなくて array だとどれぐらい遅くなる？
    DeadlineCost.append([d, c])

DeadlineCost.sort(reverse=True)
#print(DeadlineCost)


t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 36588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
 
  // ここにプログラムを追記
  for (int i = 1; i <= N; i++) {
    int x;
    cin >> x;
    if (x < K - x) {
       sum += x * 2;
    } else {
      sum += (K - x) * 2; 
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256