akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  string c;
  cin >> c;
  int num_r = 0;
  int num_w = 0;
  rep(i, c.size()) {
    if (c[i] == 'R') num_r++;
    else if (c[i] == 'W') num_w++;
  }

  int ans = 0;
  rep(i, num_r) {
    if (c[i] == 'W') ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>

using namespace std;
int n;
int H,W,T;
string str;
bool used[26],flg;

int A[26],B[26],C[26],D[26];

char t[50][50];

char tmp;

void input();
void init();

bool check(char ch){
  int z= ch-'A';
  for(int i=A[z];i<=C[z];i++){
    for(int j=D[z];j<=B[z];j++){
      if(t[i][j]!='.'&&used[t[i][j]-'A']==false)continue;
      if(t[i][j]!=ch)return false;
    }
  }
  return true;
}



int main(){
  cin>>T;
  while(T--){
    init();
    input();

    while(1){
 
      flg=false;

      for(int i=0;i<26;i++){
	if(used[i]==false)continue;
	if(check(i+'A')==true){
	  flg=true;
	  used[i]=false;
	  break;
	}
      }
      if(flg==false)break;
    }

    flg=false;
    for(int i=0;i<26;i++)flg|=used[i];
    cout<<(flg?"SUSPICIOUS":"SAFE")<<endl;
  }
  return 0;
}

void input(){
  int X;
  cin>>H>>W;
  for(int i=0;i<H;i++){
    cin>>str;
    for(int j=0;j<W;j++){
      t[i][j]=str[j];
      if(t[i][j]=='.')continue;
      X=t[i][j]-'A';
      used[X]=true;
      A[X]=min(A[X],i);
      B[X]=max(B[X],j);
      C[X]=max(C[X],i);
      D[X]=min(D[X],j);
    }
  }
}

void init(){
  for(int i=0;i<26;i++){
    A[i]=50;
    B[i]=0;
    C[i]=0;
    D[i]=50;
    used[i]=false;
  }
}

Measured memory_bytes: 1196
N,W=list(map(int,input().split()))
weights=[]
value=[]
for i in range(N):
    w,v=list(map(int,input().split()))
    weights.append(w)
    value.append(v)

dp=[[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if(j>=weights[i-1]):
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-weights[i-1]]+value[i-1])
        else:
            dp[i][j]=dp[i-1][j]
# print(dp[2][3])
print(dp[N][W])

Measured memory_bytes: 147656
n = int(input())
sum = 0
for i in range(1,n+1):
    if i % 15 == 0: 
        #print('FizzBuzz')
        pass
    elif i % 3 == 0: 
        #print('Fizz')
        pass
    elif i % 5 == 0: 
        #print('Buzz')
        pass
    else:
        #print(i)
        sum += i
print(sum)

Measured memory_bytes: 8936
//abc156_d.cpp
//Sat Feb 22 20:51:56 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
const int MOD = 1000000007;

//繰り返し二乗法
//高速にべき乗を求める。xのn乗をmodで割った余りを求める。
ll mod_pow(ll x, ll n, ll mod){
	ll res = 1;
	while (n>0){
		if (n&1){
			res = res * x % mod;
		}
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}

long long mod(long long val, long long m) {
	long long res = val % m;
	if (res < 0) res += m;
	return res;
}


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

	ll ans = mod_pow(2,n,MOD);
	ans--;

	ll x=1;
	for (int i=0;i<a;i++){
		x = x*(n-i)%MOD;
		x = x*mod_pow(i+1,MOD-2,MOD)%MOD;
	}
	ans = mod(ans-x,MOD);

	ll y=1;
	for (int i=0;i<b;i++){
		y = y*(n-i)%MOD;
		y = y*mod_pow(i+1,MOD-2,MOD)%MOD;
	}
	ans = mod(ans-y,MOD);

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

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

void Solve(){
	int m,n;
	cin >> m >> n;
	vector<int> p(m),c(n),e(n);
	rep(i,0,m) cin >> p[i];
	rep(i,0,n) cin >> c[i] >> e[i];

	sort(p.rbegin(),p.rend());
	vector<int> sum(m+1);
	rep(i,0,m) sum[i+1]=sum[i]+p[i];

	vector<int> dp(10001,-INF);
	dp[0]=0;
	int ans=0;
	rep(i,0,n){
		for(int j=m; j>=0; --j){
			dp[j]=max(dp[j],dp[max(0,j-c[i])]-e[i]);
			ans=max(ans,sum[j]+dp[j]);
		}
	}

	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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

int main() {
    string ans;
    int N;
    string S;
    cin >> N >> S;
    if(N % 2 == 1)
        ans = "No";
    else {
        if(S.substr(0, N / 2) == S.substr(N / 2, N - 1))
            ans = "Yes";
        else
            ans = "No";
    }
    cout << ans << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

struct Sieve {
    i64 n;
    vector<i64> f, primes;
    using P = pair<i64, i64>;

    Sieve(i64 n = 1) : n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (i64 i = 2; i <= n; i++) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (i64 j = i * i; j <= n; j += i) {
                if (f[j] == 0) f[j] = i;
            }
        }
    }

    bool is_prime(i64 x) {
        return f[x] == x;
    }

    vector<i64> factor_list(i64 x) {
        vector<i64> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }

    vector<P> factor(i64 x) {
        vector<i64> fl = factor_list(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (i64 p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

#define MAX_P 55'555

int main() {
    i64 N; cin >> N;
    vector<i64> ans(N);

    Sieve sieve(MAX_P);
    i64 cnt = 0;
    for (i64 p : sieve.primes) {
        if (cnt == N) break;
        if (p == 2) continue;
        if (((p - 1) / 2) % 5 == 0) {
            ans[cnt] = p;
            cnt++;
        }
    }

    REP(i, N) {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mn(a, b) (a < b ? a : b)
#define mx(a, b) (a > b ? a : b)
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
#define base 331

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int const MAXn = 1e3 + 2, MOD = 1e9 + 7;

ll dp[MAXn][MAXn];

int main(){

    //freopen(".in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            char x;
            cin>>x;
            if(i == 1 && j == 1){
                dp[i][j] = 1;
                continue;
            }
            if(x == '.')
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }
    cout<<dp[n][m];
    return 0;
}


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

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    rep(i,n) cout << s[i] << t[i];
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
def card_game():
    T = 0
    H = 0

    n = int(input())

    for _ in range(n):
        param = input()
        param = param.split(" ")
        c1 = param[0]
        c2 = param[1]

        if c1 > c2 :
            T += 3
        elif c1 < c2:
            H += 3
        else:
            T += 1
            H += 1

    print(str(T) + " " + str(H) )

if __name__ == "__main__":
    card_game()



Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, s;
    cin >> n >> k >> s;
    rep (i, k) cout << s << " ";
    rep (i, n - k) cout << (s == 1000000000 ? 1 : s + 1) << " ";
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
double cal(double a, double b , string w){
  if(w=="+")
    return a+b;
  if(w=="-")
    return a-b;
  if(w=="*")
    return a*b;
  if(w=="/")
    return a/b;
}

int main(void){
  string line;
  while(getline(cin,line)){
    if(line=="") break;
    stack<double> stq;
    string word;
    stringstream ss;
    ss<<line;
    while(ss>>word){
      if(word=="+"||word=="-"||word=="*"||word=="/"){
        double a,b;
        b = stq.top();
        stq.pop();
        a = stq.top();
        stq.pop();
        stq.push(cal(a,b,word));
      }else{
        double n = atof(word.c_str());
        stq.push(n);
      }
    }
    printf("%.6lf\n",stq.top());
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define BTC 380000.0

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

    vector<string> x(n); vector<string> u(n);
    double gifts = 0;
    rep(i, n) { 
        int t = 0;
        cin >> x[i] >> u[i];
        gifts += (u[i] == "JPY") ? stoi(x[i]) : 
                                   BTC * stod(x[i]);
        // cout << gifts << endl;
    }

    cout << gifts << endl;
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

int main(){
	int n=read();
	vi t,a;
	REP(i,n)
		t.PB(read());
	REP(i,n)
		a.PB(read());
	const int inf=1145141919;
	vi ans(n,-inf);
	int last=-1;
	REP(i,n){
		if(t[i]!=last)
			ans[i]=t[i];
		last=t[i];
	}
	last=-1;
	for(int i=n-1;i>=0;i--){
		if(a[i]!=last){
			if(ans[i]==-inf||ans[i]==a[i])
				ans[i]=a[i];
			else{
				cout<<0<<endl;
				return 0;
			}
		}
		last=a[i];
	}
	int mx=0;
	REP(i,n){
		chmax(mx,ans[i]);
		if(mx>t[i]){
			cout<<0<<endl;
			return 0;
		}
	}
	mx=0;
	for(int i=n-1;i>=0;i--){
		chmax(mx,ans[i]);
		if(mx>a[i]){
			cout<<0<<endl;
			return 0;
		}
	}
	set<int> s;
	REP(i,n)
		if(ans[i]!=-inf)
			s.insert(i);
	ll w=1;
	REP(i,n)
		if(ans[i]==-inf){
			auto itr=s.upper_bound(i);
			ll k=ans[*itr];
			chmin(k,ans[*(--itr)]);
			w=w*k%1000000007;
		}
	cout<<w<<endl;
}


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

static const int MAX = 2005;
static const int INF = 1e9;

// 隣接リストを用いた幅優先探索 O(|V|+|E|)
vector<int> G[MAX], d(MAX, INF); // 始点sから頂点iまでの最短距離をd[i]に記録
// main関数からこれらを削除すること

void bfs(int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v = 0; v < G[u].size(); v++) {
      if (d[G[u][v]] == INF) {
        d[G[u][v]] = d[u] + 1;
        q.push(G[u][v]);
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  
  // vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  for (int i = 0; i < n - 1; i++) {
    G[i].emplace_back(i + 1);
    G[i + 1].emplace_back(i); // 有向グラフではこの行をコメントアウト
  }
  G[x].emplace_back(y);
  G[y].emplace_back(x);
  
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    d = vector<int>(n, 1e9);
    bfs(i);
    for (int j = 0; j < n; j++) {
      v.at(d[j])++;
    }
  }
  
  for (int i = 1; i <= n - 1; i++) cout << v.at(i) / 2 << '\n';
}

Measured memory_bytes: 384
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e) int i; for(int i=s;i<=e;i++)
#define repd(i,s,e) int i; for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    read(n);
    string s;
    cin >> s;
    // int n =s.length();
    int a=0;
    map<char,int> c;
    loop(i,s.length()){
    	c[s[i]]++;
    	// cout<<s[i]<<" "<<c[s[i]];
    }
    int k=0;
    rep(i,0,n-2){
    	rep(j,i+1,n-1){
    		if(s[i]!=s[j] && 2*j-i<n){
    			if(s[2*j-i]!=s[j] && s[2*j-i]!=s[i]) k++;
    		}
    	}
    }
    // cout<<c['R']<<" "<<c['G']<<" "<<c['B']<<endl; 
    a=c['R']*c['G']*c['B'] - k;
   cout<<a<<endl;
    
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 3628
def candies(N: int, A: list) -> int:
    S = [[0] * (N + 1), [0] * (N + 1)]
    for n in range(N):
        S[0][n + 1] = S[0][n] + A[0][n]
        S[1][N - (n + 1)] = S[1][N - n] + A[1][N - (n + 1)]

    max_candies = 0
    for n in range(N):
        max_candies = max(max_candies, S[0][n+1] + S[1][n])

    return max_candies


if __name__ == "__main__":
    N = int(input())
    A = [[], []]
    for i in range(2):
        A[i] = [int(s) for s in input().split()]

    ans = candies(N, A)
    print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

bool solve(vector<ll> v) {
    const ll n = v.size();
    ll sum = 0, s = 0;
    REP(i, n) {
        sum += v[i];
        s += i+1;
    }
    if (sum % s != 0) return false;
    ll T = sum/s;
    vector<ll> t(n);
    REP(i, n) {
        ll a = v[i];
        ll b = v[(i+1)%n];
        if (a-b+T < 0) return false;
        if ((a-b+T) % n != 0) return false;
        t[i] = (a-b+T)/n;
    }
    // cout << t << endl;
    // cout << T << endl;
    ll d = 0;
    REP(i, n) {
        d += t[i] * (n-i);
    }
    // cout << d << endl;
    REP(i, n) {
        if (v[i] != d) return false;
        d += (T-t[i]) - (n-1)*t[i];
        // cout << d << endl;
        assert(d >= 0);
    }
    return true;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n; cin >> n;
    vector<ll> v(n); cin >> v;
    if (solve(v)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

string s;
signed main() {
    cin >> s;
    int n = s.length();
    if (s[0] == '0' || s[n - 2] == '0' || s[n - 1] == '1') {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 1; i < n - 2; i++) {
        if (s[i] != s[n - 2 - i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout<<"1 2"<<endl<<"2 3"<<endl;
    int pre=2;
    for(int i=1;i<n-2;i++){
        int now=i+3;
        if(s[i]=='1'){
            cout<<now-1<<" "<<now<<endl;
            pre=now-1;
        }else{
            cout<<pre<<" "<<now<<endl;
        }
    }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
int main()
{
ios_base::sync_with_stdio(false);
int n,m;
cin>>n>>m;
ll a[n][3];
for(int i=0;i<n;++i)
cin>>a[i][0]>>a[i][1]>>a[i][2];
ll maxans=0,ans=0;
ll ta[n];
ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=a[i][0]+a[i][1]-a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;
ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=a[i][0]+a[i][1]+a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;
ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=a[i][0]-a[i][1]-a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=a[i][0]-a[i][1]+a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=-1*a[i][0]+a[i][1]-a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=-1*a[i][0]+a[i][1]+a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;
ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=-1*a[i][0]-a[i][1]-a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;
ans=0;
for(int i=0;i<n;++i)
{
    ta[i]=-1*a[i][0]-a[i][1]+a[i][2];
}
sort(ta,ta+n);
for(int i=1;i<=m;++i)
{
    ans+=ta[n-i];
}
if(maxans<ans)
maxans=ans;
cout<<maxans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>

using namespace std;

int main() {

	int hyou[14][14] = {0};

	int a,b,c;
	int counter1 = 0;
	int counter2 = 0;
	char d;

	while (cin >> a >> d >> b >> d >> c) {
		a += 2;
		b += 2;
		if (c == 1) {
			hyou[a][b] += 1;
			hyou[a - 1][b] += 1;
			hyou[a + 1][b] += 1;
			hyou[a][b - 1] += 1;
			hyou[a][b + 1] += 1;
		} else if(c == 2) {
			for (int i = a - 1; i < a + 2; i++) {
				for (int j = b - 1; j < b + 2; j++) {
					hyou[i][j] += 1;
				}
			}
		} else {
			for (int i = a - 1; i < a + 2; i++) {
				for (int j = b - 1; j < b + 2; j++) {
					hyou[i][j] += 1;
				}
			}
			hyou[a - 2][b] += 1;
			hyou[a + 2][b] += 1;
			hyou[a][b - 2] += 1;
			hyou[a][b + 2] += 1;
		}
	}

	for (int i = 2; i < 12; i++) {
		for (int j = 2; j < 12; j++) {
			if (hyou[i][j] == 0) {
				counter1++;
			}
			counter2 = max(counter2,hyou[i][j]);
		}
	}

	cout << counter1 << endl << counter2 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int a[10], n, f[100][10], result = 0, p[100][11];
void compare(int n) {
    bool zero = true;
    for (int i = 0; i < 10; i++)
    {
        if (a[i] == 1) 
        {
            zero = false;
            break;
        }
    }
    if (zero == true) return;
    int s = 0;
    for (int i = 0; i < n; i++)
    {
        int k = 0;
        for (int j = 0; j < 10; j++)
            if (f[i][j] == 1 && a[j] == 1) k++;
        s += p[i][k];
    }
    result = max(result, s);
    return;
}
void back(int pos) {
    if (pos == 10) compare(n);
    else
    {
        for (int i = 0; i < 2; i++)
        {
            a[pos] = i;
            back(pos + 1);
        }
    }
}
int main() {
    cin >> n;
    for (int i = 0; i < 100; i++)
        for (int j = 0; j < 10; j++) f[i][j] = 0;
    for (int i = 0; i < 100; i++)
        for (int j = 0; j < 11; j++) p[i][j] = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 10; j++) cin >> f[i][j];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 11; j++) cin >> p[i][j];
    for (int i = 0; i < n; i++)
    {
        if (f[i][0] == 1) result += p[i][1];
        else result += p[i][0];
    }
    back(0);
    cout << result;
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;

class Program {
  static void Main(string[] args) {
    string str = Console.ReadLine();
    int r_2or3 = 0;
    char bef_c = 'a';
    foreach (char c in str) {
      if (c == 'R') {
        if (bef_c != 'S') {
          r_2or3++;
        }
        else
        {
          r_2or3 = 1;
        }
        bef_c = 'R';
      }
      else
      {
        bef_c = 'S';
      }
    }
    Console.WriteLine(r_2or3);
  }
}

Measured memory_bytes: 25832
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int s,w;
    cin >> s >> w;
    bool osowareru = w >= s;
    cout << (osowareru ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();

		System.out.println(Z + " " + X + " " + Y);
	}

}



Measured memory_bytes: 23764
from collections import deque
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
E = [[] for i in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    E[l].append((r, d))
    E[r].append((l, -d))

pos = {}

def bfs(cur, pre, p):
    stack = deque([(cur, pre, p)])
    while stack:
        cur, pre, p = stack.popleft()
        if cur in pos:
            if p != pos[cur]:
                print('No')
                sys.exit()
        else:
            pos[cur] = p

            for e, d in E[cur]:
                if e != pre:
                    stack.append([e, cur, p + d])

for i in range(n):
    if i in pos:
        continue
    bfs(i, -1, 0)

print('Yes')

Measured memory_bytes: 137612
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll gcd(ll a, ll b) {		// ユークリッドの互除法
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll& x, ll& y) {		// 拡張ユークリッドの互除法
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,X;
	cin>>N>>X;
	vector<ll> x(N);
	REP(i,N) cin>>x[i];
	REP(i,N) x[i]-=X;
	ll g=x[0];
	FOR(i,1,N) g=gcd(g,x[i]);
	cout<<abs(g)<<endl;
	return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

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

	p := make([]float64, n+1)

	for i := 1; i < n+1; i++ {
		fmt.Scan(&p[i])
	}

	dp := make([][]float64, n+5)
	for i := 0; i < n+5; i++ {
		dp[i] = make([]float64, n+5)
	}
	dp[0][0] = 1.0

	for i := 1; i < n+1; i++ {
		for j := 0; j < n+1; j++ {
			if j == 0 {
				dp[i][j] = dp[i-1][j] * (1.0 - p[i])
				continue
			}
			dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1.0-p[i])
		}
	}

	var result float64
	for j := n/2 + 1; j < n+1; j++ {
		result += dp[n][j]
	}
	fmt.Println(result)
}

Measured memory_bytes: 75392
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int A,B,count=0;
	cin >> A >> B;
	
	for(int i=1;i<4;i++)
	{
		if(A*B*i%2==1){count++;}
	}
	
	if(count!=0){cout << "Yes" << endl;}
	else{cout << "No" << endl;}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

s = sum(a)

half = [0,s]
for i in range(n):
    if abs(half[1]-half[0])>abs(half[1]-half[0]-2*a[i]):
        half[0]+=a[i]
        half[1]-=a[i]
    else:
        break
print(abs(half[1]-half[0]))

Measured memory_bytes: 89552
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>
 
int main(void)
{
    int64_t N;
    std::cin >> N;

    int64_t ans = 0;
    for (int64_t i = 0; i < N; ++i) {
        ans += i;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int main(){
	
string s,t;
cin>>s>>t;
for(int i=0;i<t.size()-1;i++){
	if(s[i]!=t[i]){
		cout<<"No\n";
		return 0;
	}
}	
cout<<"Yes\n";
	
	
}

Measured memory_bytes: 3624
s=input()
length=0
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        ans=s[i:j].replace('A','').replace('T','').replace('C','').replace('G','')
        if ans=='' and len(s[i:j])>=length:
            length=len(s[i:j])
print(length)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=2*1e5+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int dp[3007][3007];
char ans[3007];
char s[3007],t[3007];
int main()
{
	io();
	cin>>s+1;getchar();
	cin>>t+1;getchar();
	int n=strlen(s+1),m=strlen(t+1);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			if(s[i]==t[j])
				dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int cnt=dp[n][m];
	if(!cnt)cout<<" "<<endl;
	int i=n,j=m;
	while(dp[i][j]>0){
		if(s[i]==t[j]){
			ans[dp[i][j]--]=s[i];
			i--;j--;
		}
		else{
			if(dp[i-1][j]==dp[i][j])i--;
			else j--;
		}
	}
	for(int i=1;i<=cnt;++i)
		cout<<ans[i];
	cout<<endl;


}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

typedef tuple<string,int,int> T;

int main () {
  int n = in();
  vector<T> t(n);
  rep(i,n) {
    string s;
    int p;
    cin >> s >> p;
    t[i] = T(s,-p,i+1);
  }
  sort(t.begin(), t.end());
  vi ans(n);
  rep(i,n) {
    ans[i] = get<2>(t[i]);
  }
  printv(ans);
  return 0;
}

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

int main() {
	int inu, monkey;
	cin >> inu >> monkey;

	if (abs(inu - monkey) >= 2)
	{
		cout << 0 << endl;
	}
	else
	{
		if (inu == monkey)
		{
			//おんなじ。
			long long output = 2;
			for (int i = inu; i > 0; i--)
			{
				output *= i;
				output = output % 1000000007;
				output *= i;
				output = output % 1000000007;
			}

			cout << output << endl;
		}
		else
		{
			if (monkey > inu)
			{
				int temp = inu;
				inu = monkey;
				monkey = temp;
			}
			long long output = inu;
			inu--;
			for (int i = inu; i > 0; i--)
			{
				output *= i;
				output = output % 1000000007;
				output *= i;
				output = output % 1000000007;
			}
			cout << output << endl;
		}

	}

	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int max=0;
  int ans=0;
  for(int i=0;i<N;i++){
    int H;
    cin >> H;
    if(max<=H){
      ans++;
      max=H;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int64_t a,b,c,k;
  cin >>a >>b >>c >>k;
  if(a>=k){
    cout <<k <<endl;
  }
  else{ //a<k
    if(a+b>k){
      cout <<a <<endl;
    }
    else{ //a<k, a+b<k
      cout <<(a-(c-(a+b+c-k))) <<endl;
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
using namespace std;

ll N, K, R, S, P, ans = 0;
string T;

ll score(char c) {
	if (c == 'r') return P;
  	else if (c == 's') return R;
  	else if (c == 'p') return S;
}
int main()
{  
  cin >> N >> K >> R >> S >> P >> T;
  vector<bool> win(N, false);
  rep(i, 0, K) {
    ans += score(T[i]);
    win[i] = true;
  }
  rep(i, K, N) {
  	if (T[i] != T[i - K] || win[i - K] == false) {
    	ans += score(T[i]);
    	win[i] = true;
    }
  }
  cout << ans << endl;
}

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

tasks=[]
for _ in range(N):
  l=list(map(int,input().split()))
  tasks.append(l)
#print(tasks)

sorted_tasks=sorted(tasks,key = lambda x: (x[1], x[0]))
#print(sorted_tasks)

time=0
for i in range(N):
  time+=sorted_tasks[i][0]
  if time>sorted_tasks[i][1]:
    print('No')
    exit()
print('Yes')
  

Measured memory_bytes: 68452
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n,m;
int U[2010][2010];
int D[2010][2010];
int L[2010][2010];
int R[2010][2010];
char c[2010][2010];
int res=0;
int main()
{
	scanf("%d%d",&n,&m); 
	for (int i=0;i<n;i++) scanf("%s",&c[i]);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (c[i][j]=='#') continue;
			U[i][j]=(i==0 ? 0 : U[i-1][j])+1;
			L[i][j]=(j==0 ? 0 : L[i][j-1])+1;
		}
	}
	for (int i=n-1;i>=0;i--)
	{
		for (int j=m-1;j>=0;j--)
		{
			if (c[i][j]=='#') continue;
			D[i][j]=(i==n-1 ? 0 : D[i+1][j])+1;
			R[i][j]=(j==m-1 ? 0 : R[i][j+1])+1;
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (c[i][j]=='#') continue;
			res=max(res,U[i][j]+D[i][j]+R[i][j]+L[i][j]-3);
		}
	}
	printf("%d",res);
	return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
char s[125252];

int dist[125252];

int dd[125252];
int dp[125252];

int main(){
    scanf("%d%d",&n,&m);
    scanf("%s",s);

    // dist
    {
        fill(dist, dist+n+1, 1<<30);
        dist[0] = 0;
        deque<pii> Q;
        Q.push_back(pii(dist[0],-0));
        FOR(i,1,n+1){
            if(s[i]=='0'){
                dist[i] = Q.front().first + 1;
            }
            if(-Q.front().second == i-m)Q.pop_front();
            pii P(dist[i], -i);
            while(Q.size()>0 && Q.back() > P)Q.pop_back();
            Q.push_back(P);
        }
    }
    if(dist[n] >= (1<<29)){
        puts("-1");
        return 0;
    }
    // REP(i,n+1)printf("%d ",min(99,dist[i])); puts("");
    // DEBUG(dist[n]);

    // reachable
    {
        fill(dp, dp+n+1, -1);
        fill(dd, dd+n+1, 1<<30);
        dd[dist[n]] = n;
        FORR(i,0,n){
            if(s[i]=='1')continue;
            int nxt = dd[dist[i]+1];
            if(nxt-i > m)continue;
            dp[i] = nxt-i;
            dd[dist[i]] = i;
        }
    }

    // output loop
    int cur = 0;
    while(cur != n){
        int dice = dp[cur];
        cur += dice;
        printf("%d%c",dice," \n"[cur==n]);
    }
    return 0;
}


Measured memory_bytes: 1664
#!/usr/bin/env python3

def main():
    N, A, B, C, D = map(int, input().split())
    S = input()
    ans = 'Yes'
    if C <D:
        if '##' in S[B-1:D] or '##' in S[A-1:C]:
            ans = 'No'
    else:
        if '##' in S[A-1:C] or '...' not in S[B-2:D+1]:
            ans = 'No'
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9396
s=str(input())
s=list(s)
if s[0]!="A":
  s.insert(0,"A")
if len(s)>=5:
  if s[4]!="A":
    s.insert(4,"A")
if len(s)>=7:
  if s[6]!="A":
    s.insert(6,"A")
if s[len(s)-1]!="A":
  s.append("A")
if "".join(s)=="AKIHABARA":
  print("YES")
else:
  print("NO")

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

long long gcd(long long a, long long b) {
    if (a%b == 0) return(b);
    else return (gcd(b,a%b));
}

long long lcm (long long a, long long b) {
    long long g = gcd(a,b);
    return a / g * b;
}

int main(void){
    int n;
    cin >> n;
    
    long long ans = 1;
    for(int i = 0; i < n; i++) {
        long long t;
        cin >> t;
        ans = lcm(ans,t);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - Candy Distribution Again
https://atcoder.jp/contests/agc027/tasks/agc027_a

"""
import sys


def solve(N, x, A):
    ans = 0
    for a in A:
        if x >= a:
            ans += 1
            x -= a
    if ans == N and x != 0:
        return ans-1
    return ans


def main(args):
    N, x = map(int, input().split())
    A = sorted([int(a) for a in input().split()])
    ans = solve(N, x, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(a,b) for(long long a = 0;a < b;++a)
pair<int,int> union_find[2000000];
pair<int,int> union_check(int a){
    if(union_find[a].first == a) return make_pair(a,0);
    pair<int,int> hoge = union_check(union_find[a].first);
    union_find[a].second += hoge.second;
    union_find[a].first = hoge.first;
    return union_find[a];
}
pair<int,int> union_merge(int a,int b,int c){
    pair<int,int> next_a = union_check(a);
    pair<int,int> next_b = union_check(b);
    if(next_a.first != next_b.first){
        union_find[next_a.first] = make_pair(b,c - next_a.second);
    }
}
int main(){
    int n,query;
    cin >> n >> query;
    REP(i,n){
        union_find[i] = make_pair(i,0);
    }
    REP(i,query){
        int a;
        cin >> a;
        if(a == 0){
            //relate
            int a,b,c;
            cin >> a >> b >> c;
            union_merge(a,b,c);
        }else{
            //diff
            int a,b;
            cin >> a >> b;
            if(union_check(a).first != union_check(b).first){
                cout << "?" << endl;
            }else{
                cout << union_find[a].second - union_find[b].second << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4500
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    string S;
    cin >> S;

    long long sum = 0;
    for (int bits = 0; bits < (0x1 << (S.size() - 1)); bits++) {
        long long num = S[0] - '0';
        for (int i = 0; i < S.size() - 1; i++) {
            if (bits & (0x1 << i)) {
                // '+' がある
                sum += num;
                num = 0;
            }
            num = num * 10 + S[i + 1] - '0';
        }
        sum += num;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n, cnt = 0 ;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];

    rep(i, n - 1){
        int a1 = p[i];
        int a2 = p[i + 1];
        if (a1 == i + 1){
            p[i] = a2;
            p[i + 1] = a1;
            cnt ++;
        }
    }
    if (p[n - 1] == n) cnt ++;

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
  int N,T[100];
  int M,P[100],X[100];
  int i,j;
  int sum = 0;
  
  scanf("%d",&N);
  for(i = 0;i < N; ++i){
    scanf(" %d",&T[i]);
    sum += T[i];
  }
  scanf(" %d",&M);
  for(j = 0;j < M; ++j)	scanf(" %d %d",&P[j],&X[j]);
  
  for(i = 0;i < M; ++i)  printf("%d\n",sum - (T[P[i] - 1] - X[i]));
  return 0;
}

Measured memory_bytes: 128
s = str(input())
a = []
 
for i in range(len(s)):
    if s[i] == '0':
        a.append('0')
    elif s[i] == '1':
        a.append('1')
    else:
        if len(a) != 0:
            a.pop()
 
print(''.join(a))

Measured memory_bytes: 8800
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[derive(Debug, Clone)]
pub struct Graph2D<T> {
    graph: Vec<Vec<T>>,
    width: isize,
    height: isize
}

impl<T: Eq + Copy> Graph2D<T> {
    pub fn new(graph: Vec<Vec<T>>) -> Self {
        let width = graph[0].len() as isize;
        let height = graph.len() as isize;
        Self { graph, width, height }
    }

    pub fn is_go(&self, x: isize, y: isize, obs: &Option<T>) -> Option<(usize, usize)> {
        if x < 0 || y < 0 || x >= self.width || y >= self.height {
            return None
        }
        match obs {
            Some(obs) => { if self.graph[y as usize][x as usize] == *obs { None } else { Some((x as usize, y as usize))}},
            None => Some((x as usize, y as usize)),
        }
    }

    pub fn width(&self) -> usize {
        self.width as usize
    }

    pub fn height(&self) -> usize {
        self.height as usize
    }

    pub fn index(&self, index: (usize, usize)) -> T {
        self.graph[index.1][index.0]
    }
}

pub fn bfs2d<T: Eq + Copy>(graph: &Graph2D<T>, start: (usize, usize), obs: Option<T>) -> Vec<Vec<isize>> {
    let directions = vec![(0, 1), (1, 0), (0, -1), (-1, 0)];
    let mut dist: Vec<Vec<isize>> = vec![vec![-1; graph.width()]; graph.height()];
    let mut queue: VecDeque<(usize, usize)> = VecDeque::new();

    let (sx, sy): (usize, usize) = start;
    dist[sy][sx] = 0;
    queue.push_back(start);

    while !queue.is_empty() {
        let (cx, cy): (usize, usize) = queue.pop_front().unwrap();

        for direction in directions.iter() {
            let next_x = cx as isize + direction.0;
            let next_y = cy as isize + direction.1;

            match graph.is_go(next_x, next_y, &obs) {
                Some(next) => {
                    if dist[next.1][next.0] == -1 {
                        dist[next.1][next.0] = dist[cy][cx] + 1;
                        queue.push_back(next)
                    }
                },
                None => {continue;}
            }
        }
    }

    dist
}

fn main() {
    input!{
        h: usize, w: usize,
        maze: [Chars; h]
    }

    let graph2d: Graph2D<char> = Graph2D::new(maze.clone());

    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            let start = (j, i);
            if graph2d.index(start) == '#' { continue; }
            let dist = bfs2d(&graph2d, start, Some('#'));

            for y in 0..h {
                for x in 0..w {
                    ans = std::cmp::max(dist[y][x], ans)
                } 
            }
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 2148