akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 220
// 44

using namespace std;

const int MAXD = (int) 2e5;
const int MAXN = 300;

int rad[MAXD + 1];

vector < pair <short, short> > g[MAXN * 2][MAXN * 2][2];
char col[MAXN * 2 + 1][MAXN * 2][2];

void dfs(int l, int c, char t, char id) {
    col[l][c][t] = id;
    //printf("%d %d %d\n" ,l,c,id);
    for(auto it : g[l][c][t]) {
        if(col[it.first][it.second][t] == -1) {
            dfs(it.first, it.second, t, id ^ 1);
        }
    }
}

int n;

inline void calc(int d, char t) {
    for(int a = 0; a < 2 * n && a * a <= d; a++) {
        int b = d - a * a;
        if(rad[b] * rad[b] == b && rad[b] < 2 * n) {
            b = rad[b];
            for(int x = 0; x + a < 2 * n; x++) {
                for(int y = 0; y + b < 2 * n; y++) {
                    g[x][y][t].push_back({x + a, y + b});
                    g[x + a][y + b][t].push_back({x, y});
                    g[x][y + b][t].push_back({x + a, y});
                    g[x + a][y][t].push_back({x, y + b});
                }
            }
        }
    }
    for(int x = 0; x < 2 * n; x++) {
        for(int y = 0; y < 2 * n; y++) {
            col[x][y][t] = -1;
        }
    }
    for(int x = 0; x < 2 * n; x++) {
        for(int y = 0; y < 2 * n; y++) {
            if(col[x][y][t] == -1) {
                dfs(x, y, t, 0);
                //printf("\n");
            }
        }
    }
    //printf("\n\n");
}

int fr[4];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, d1, d2;
    ios::sync_with_stdio(false);
    cin >> n >> d1 >> d2;
    if(d1 > d2) {
        swap(d1, d2);
    }
    for(i = 1; i * i <= d2; i++) {
        rad[i * i] = i;
    }
    for(i = 1; i <= d2; i++) {
        rad[i] = max(rad[i - 1], rad[i]);
    }
    calc(d1, 0);
    calc(d2, 1);
    for(i = 0; i < 2 * n; i++) {
        for(j = 0; j < 2 * n; j++) {
            fr[col[i][j][0] * 2 + col[i][j][1]]++;
            //printf("%d %d %d %d\n" ,i,j,col[i][j][0],col[i][j][1]);
        }
    }
    int mx = 0, id;
    for(i = 0; i < 4; i++) {
        if(fr[i] > mx) {
            mx = fr[i];
            id = i;
        }
    }
    fr[id] = n * n;
    for(i = 0; i < 2 * n; i++) {
        for(j = 0; j < 2 * n; j++) {
            if(col[i][j][0] * 2 + col[i][j][1] == id && fr[id]) {
                cout << i << " " << j << "\n";
                fr[id]--;
            }
        }
    }
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 111872
// AOJ 2108 Aaron and Bruce
// 2018.3.4

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c <= ' ') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int m, lim;
int hi[51], to[51][51];
int dp[51][51][102];

int dfs(int a, int b, int t)
{
	int i, x, ans;

	if (a == b) return t;
	if (t >= lim) return lim;
	if (dp[a][b][t] >= 0) return dp[a][b][t];
	if (t & 1) {
		ans = lim;
		for (i = 0; i < hi[b]; i++) {
			x = dfs(a, to[b][i], t+1);
			if (x < ans) ans = x;
		}
	} else {
		ans = 0;
		for (i = 0; i < hi[a]; i++) {
			x = dfs(to[a][i], b, t+1);
			if (x > ans) ans = x;
		}
	}
	return dp[a][b][t] = ans;
}

int main()
{
	int cno, r, c, a, b, ans;

	cno = in(); while (cno--) {
		m = in(), lim = m << 1;
		for (r = 0; r < m; r++) {
			hi[r] = 1, to[r][0] = r;
			for (c = 0; c < m; c++)	if (in()) to[r][hi[r]++] = c;
		}
		a = in(), b = in();

		memset(dp, -1, sizeof(dp));
		ans = dfs(a, b, 0);
		if (ans >= lim)	puts("infinity");
		else printf("%d\n", ans >> 1);
	}
	return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define rint register int
#define ll long long 
using namespace std;
int N,A[1010010];
ll ans=1e18,X;
multiset<ll> st;
int main(){
	cin>>N>>X;
	for(rint i=1;i<=N;++i) cin>>A[i];
	for(rint i=N+1;i<=2*N;++i) A[i]=A[i-N]; 
	for(rint i=0;i<N;++i) {
		ll sum=1ll*i*X;
		st.clear();
		for(rint j=1;j<=N;++j){
			st.insert(1ll*A[j]);
		}
		int cur=1;
		for(rint j=N+1;j<=N+N;++j){
			while(cur<j-i) st.erase(A[cur]),cur++;
			st.insert(1ll*A[j]);
			sum+=(*st.begin());
		}
		ans=min(ans,sum);
	} 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3736
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int n; cin >> n;
    vi a(n); 
    
    ll tot = 0;
    rep(i, n) {
        cin >> a[i];
        tot += abs(a[i]);
    }
    sort(all(a));
    
    if(a[0] < 0 && a[n-1] > 0){
        cout << tot << endl;
        
        auto it = lower_bound(all(a), 0);
        int pstv = it - a.begin();
        ll now = a[pstv];
        
        if(pstv == n-1){
            rep(i, n-1) {
                cout << now << " " << a[i] << endl;
                now -= a[i];
            }
            return;
        }

        rep3(i, 1, pstv-1){
            cout << now << " " << a[i] << endl;
            now -= a[i];
        }

        cout << a[0] << " " << now << endl;
        now = a[0] - now;
        
        rep3(i, pstv+1, n-2){
            cout << now << " " << a[i] << endl;
            now -= a[i];
        }
        cout << a[n-1] << " " << now << endl;
    }
    else if(a[0] >= 0){
        tot -= 2*a[0];
        cout << tot << endl;
        
        ll now = a[0];
        rep(i, n-2){
            cout << now << " " << a[i+1] << endl;
            now -= a[i+1];
        }
        cout << a[n-1] << " " << now << endl;
    }
    else{
        tot += 2*a[n-1];
        cout << tot << endl;

        ll now = a[n-1];
        rep3rev(i, n-2, 0){
            cout << now << " " << a[i] << endl;
            now -= a[i];
        }
    }
    
    return;

}

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

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string S; cin >> S;
    ll K; cin >> K;
    int cnt = 0, save;
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '1') {
            cnt++;
        }
        else {
            save = i;
            break;
        }
    }
    if (cnt >= K) {
        cout << 1 << endl;
    }
    else {
        cout << S.at(save) << endl;
    }
    return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;

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

int main(){
  ll n; 
  //string s;
  cin >> n;
  
  ll ans = 0;
  rep(a,1,n+1){
    rep(b,1,n+1){
      rep(c,1,n+1){
        ans += gcd(a, gcd(b,c));
      }
    }
  }
  
  cout << ans << endl;
}

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

int main(){
    string S;
    cin>>S;
    bool flag = true;
    if(S=="AAA"){
        flag = false;
    }else if(S=="BBB"){
        flag = false;
    }
    
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <array>

using namespace std;

int main()
{
    array<double, 10> seq;

    while (cin >> seq.at(0)) {
        double sum = seq.at(0);
        for (size_t i = 1; i < 10; i++) {
            seq.at(i) = (i % 2)? (seq.at(i - 1) * 2): (seq.at(i - 1) / 3);
            sum += seq.at(i);
        }

        cout << fixed << setprecision(6) << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n);++i)
using namespace std;
typedef long long ll;

int main(){
    int N;
    int ans = 0;
    cin >> N;
    int B[110];
    int A[110];

    rep(i, N-1) cin >> B[i];

    A[0] = B[0];
    A[N-1] = B[N - 2];
    for (int i = 1; i < N - 1; i++)
    {
        if (B[i-1] < B[i]){
            A[i] = B[i - 1];
        }
        else
        {
        A[i] = B[i];
        }
    }
    rep(i, N) ans += A[i];
    cout << ans << endl;
}


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

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M,0));
    priority_queue<int, vector<int>, greater<int>> cost;
    for(int i = 0; i < N; ++i){
        cin >> C[i];
        for(int j = 0; j < M; ++j){
            cin >> A[i][j];
        }
    }
    for(int k = 0; k < pow(2, N); ++k){
        int cost_buf = 0;
        vector<int> Understand(M, 0);
        for(int i = 0; i < N; ++i){ 
            if((k >> i) & 1){ 
                cost_buf += C[i];
                for(int j = 0; j < M; ++j) Understand[j] += A[i][j]; 
            }
        }
        for(int j = 0; j < M; ++j){
            if(Understand[j] < X) break;
            else if(j == M-1) cost.push(cost_buf);
        }
    }
    if(cost.empty()) cout << -1 << endl;
    else cout << cost.top() << endl;
    return 0;
}

Measured memory_bytes: 4080
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#define  STATE  30
using namespace std;
int dp[STATE][STATE][STATE][STATE];
vector <int> A, B, Y, Z, X;
stack <int> stk;
int n, m, r, state;
inline void init (void)
{
    Y.clear();
    Z.clear();
    X.clear();      
    A.resize(n);
    B.resize(m);
    for (int i=0;i<n;++i) cin>>A[i];
    for (int i=0;i<m;++i) cin>>B[i];
    state = STATE;
}
inline void toChomskyForm (int y)
{
    for (;;)
    {
        Z.push_back(stk.top()); stk.pop();
        Y.push_back(stk.top()); stk.pop();      
        if (stk.empty())
        {
           X.push_back(y);
           return ;
        }
        else
        {
            X.push_back(++state);     
            stk.push(state); 
        }
    }          
}
inline void makeGrammar (void)
{
    int k, y, tmp;
    for (int i=0;i<r;++i)          
    {
        cin>>k;    
        for (int j=0;j<k;++j)
        {
            cin>>tmp;    
            stk.push(tmp);
        }
        cin>>y;
        toChomskyForm (y);
    }   
}
inline vector < vector < set<int> > > CYK ( const vector <int> &A )
{
    int n = A.size();          
    vector < vector< set<int> > > dp(n,vector< set<int> >(n+1));
    for (int i=0;i<n;++i) dp[i][1].insert(A[i]);
    
    for (int len=2;len<=n;++len)
    for (int i=0;i<n;++i)
    for (int j=0;j<X.size();++j)
    for (int k=1;k<len;++k)
    {
        int ii = (i+k)%n;    
        if (dp[i][k].count(Y[j])&&dp[ii][len-k].count(Z[j])) 
           dp[i][len].insert(X[j]);
    }      
    return dp;   
}
inline vector < vector<int> > makeBitset ( const vector < vector < set<int> > > &A )
{
    int n = A.size();
    vector < vector<int> > ans(n,vector<int>(n+1,0));
    for (int i=0;i<n;++i)
    for (int w=0;w<=n;++w)
    for (int k=0;k<=STATE;++k)
        if (A[i][w].count(k)) ans[i][w] |= 1<<k;
    return ans;
}

inline void solve (void)
{
    vector < vector<int> > ai = makeBitset( CYK(A) );
    vector < vector<int> > bi = makeBitset( CYK(B) );
    memset (dp,-1,sizeof(dp));
    for (int i=0;i<n;++i)
    for (int j=0;j<m;++j) dp[i][0][j][0] = 0;
    
    for (int nn=0;nn<n;++nn)
    for (int mm=0;mm<m;++mm)
    for (int i=0;i<n;++i)
    for (int j=0;j<m;++j)
    {
        if (dp[i][nn][j][mm] == -1) continue;    
        for (int p=nn+1;p<=n;++p)
        for (int q=mm+1;q<=m;++q)
        {
            int ii = (i+nn)%n;
            int jj = (j+mm)%m;
            if (ai[ii][p-nn] & bi[jj][q-mm])
               dp[i][p][j][q] = max(dp[i][p][j][q],dp[i][nn][j][mm]+1);
        }
    }
    int ans = -1;
    for (int i=0;i<n;++i)
    for (int j=0;j<m;++j) ans = max(ans,dp[i][n][j][m]);   
    cout<<ans<<endl;
}
int main(void)
{
    while (cin>>n>>m>>r && n && m && r)
    {
          init ();
          makeGrammar ();
          solve ();
    }
    return 0;    
}

Measured memory_bytes: 4584
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) > abs(x - b)) {
        cout << "B\n";
    } else {
        cout << "A\n";
    }
}

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

using namespace std;

int main()
{
  string S,ans;
  cin>>S;
  ans="Good";
  for(int i=0;i<S.size()-1;i++){
    if(S.at(i)==S.at(i+1)){
      ans="Bad";
    }
  }
  cout<<ans<<endl;
}
      


Measured memory_bytes: 256
N,M= list(map(int, input().split()))
X= list(map(int, input().split()))
X.sort()
div=[]
if N>=M:
    print("0")
else:
    for i in range(M-1):
        div.append(X[i+1]-X[i])
    div.sort()
    print(sum(div[:M-N]))

Measured memory_bytes: 13968
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int n = sc.nextInt();
                if(n == 0){break;}
                int[] scores = new int[n];
                for(int i = 0;i < scores.length;i++){
                    scores[i] = sc.nextInt();
                }
                double average = 0, variance = 0;
                for(int i = 0;i < scores.length;i++){
                    average += scores[i];
                }
                average = average/n;
                for(int i = 0;i < scores.length;i++){
                    variance += (scores[i] - average)*(scores[i] - average);
                }
                variance = variance / n;
                System.out.println(Math.sqrt(variance));
            }
        }
    }
}



Measured memory_bytes: 31960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  long long a[55],b[55],c,d,e[55],mn[55];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    mn[i]=1000000000;
  }
  for(int i=0;i<m;i++){
    cin>>c>>d;
    for(int j=0;j<n;j++){
      if(mn[j]>abs(a[j]-c)+abs(b[j]-d)){
	mn[j]=abs(a[j]-c)+abs(b[j]-d);
	e[j]=i+1;
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<e[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = input()
N_i = int(N)
N_s = list(N)


for i in range(0,17):
  if N_i < 10 ** i:
    break
flag = True
for j in range(1,i):
  if N_s[j] != "9":
    flag = False
    break

if flag == True:
  # 最上位を除いたすべての桁が9
   print(int(N_s[0])+9*(len(N_s)-1))
else:
   print(int(N_s[0])+9*(len(N_s)-1)-1)







Measured memory_bytes: 9128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr =new int[] {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		System.out.println(arr[N - 1]);
	}
}

Measured memory_bytes: 35632
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
string a;
cin>>a;
if(a=="SUN") cout<<7<<endl;
else if(a=="MON") cout<<6<<endl;
else if(a=="TUE") cout<<5<<endl;
else if(a=="WED") cout<<4<<endl;
else if(a=="THU") cout<<3<<endl;
else if(a=="FRI") cout<<2<<endl;
else if(a=="SAT") cout<<1<<endl;
return 0;
}

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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;

int dp[3005][3005];
string s1, s2;

int kil(int idx1, int idx2)
{
  if(idx1 == s1.length() || idx2 == s2.length())
    return 0;

  if(dp[idx1][idx2] != -1)
    return dp[idx1][idx2];

  if(s1[idx1] == s2[idx2])
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1+1, idx2+1) + 1);
  else
  {
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1, idx2+1));
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1+1, idx2));
  }
  return dp[idx1][idx2];
}


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

  string res="";

  memset(dp, -1, sizeof dp);
  cin>>s1>>s2;

  // recursive
  // kil(0, 0);

  // iterative
  memset(dp, 0, sizeof dp);

  for(int idx1 = s1.length()-1; idx1>=0; idx1--)
    for(int idx2 = s2.length()-1; idx2>=0; idx2--)
    {
      if(s1[idx1] == s2[idx2])
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1+1][idx2+1] + 1);
      else
      {
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1][idx2+1]);
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1+1][idx2]);
      }
    }



  int idx1=0, idx2=0;

  while(idx1 != s1.length() && idx2 != s2.length())
  {
    if(s1[idx1] == s2[idx2])
    {
      res += s1[idx1];
      idx1 += 1;
      idx2 += 1;
    }
    else
    {
      if(dp[idx1][idx2] == dp[idx1+1][idx2])
        idx1 += 1;
      if(dp[idx1][idx2] == dp[idx1][idx2+1])
        idx2 += 1;
    }
  }

  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int dp[3003][3003][5];
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int r,c;cin>>r>>c;
    int k;cin>>k;
    vv value(r,v(c,0));
    for(int i=0;i<k;i++)
    {
    	int a,b;cin>>a>>b;
    	a--;
    	b--;
    	cin>>value[a][b];
    }
    for(int i=r-1;i>=0;i--)
    {
    	for(int j=c-1;j>=0;j--)
    	{
    		for(int k=0;k<=3;k++)
    		{
    			dp[i][j][k]=max(dp[i+1][j][0],dp[i][j+1][k]);
    			if(k!=3)
    				dp[i][j][k]=max({dp[i+1][j][0]+value[i][j],dp[i][j+1][k+1]+value[i][j],dp[i][j][k]});
    		}
    	}
    }
    ll ans=0;
    for(int i=0;i<4;i++)
    {
        ans=max(ans,dp[0][0][i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 425524
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;


int main() {
	ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;
	bool flag = false;
	for (int i = 0; i <= N - 1; i++) {
		if (i * C - (N - 1 - i) * D <= abs(B - A) && abs(B - A) <= i * D - (N - 1 - i) * C) {
			flag = true;
			break;
		}
	}
	cout << (flag ? "YES" : "NO") << endl;
}


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 200 + 5;

int n;
char cell[maxN][maxN];

int res = 0;
int layer[maxN];

void bfs(int s){
	fill_n(layer + 1, n, -1);
	queue<int> que;
	que.push(s);
	layer[s] = 1;
	
	while(!que.empty()){
		int u = que.front();
		que.pop();

		for(int v = 1; v <= n; v++){
			if(cell[u][v] == '1'){
				if(layer[v] == -1){
					layer[v] = layer[u] + 1;
					que.push(v);
				} else if(layer[u] == layer[v]){
					cout << "-1\n";
					exit(0);
				}
			}
		}
	}

	res = max(res, *max_element(layer + 1, layer + n + 1));
}

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

	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> (cell[i] + 1);
	}

	for(int i = 1; i <= n; i++){
		bfs(i);
	}

	cout << res << '\n';

	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int a,b;
    cin>>a>>b;
    if(a<=9&&b<=9){
        cout<<a*b<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}


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

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int x , t;
	
	cin >> x >> t;
	
	cout << max(0LL , x - t);
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3584
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=0
al=0
for i in range(n):
    al+=a[i]
p=al/(4*m)
for i in range(n):
    if p<=a[i]:
        ans+=1
print("Yes" if m<=ans else "No")

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s, t;
    cin >> s >> t;
    for(int i = 0; i < t.size(); ++i) {
        cout << char(s[i]) << char(t[i]);

    }
    if(s.size() != t.size()) cout << char(s[s.size() - 1]);
    cout << endl;

    return 0;
}



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

int main() {
    ll N;
    cin >> N;
    for (ll i = sqrt(N+1); i > 0; --i) {
        if (N % i == 0) {
            cout << i + N / i - 2 << endl;
            return 0;
        }
    }
}


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

using namespace std;
using ll = long long;

#define ist istream_iterator
#define ost ostream_iterator

ll const inf = 100 * 1000;
int const N = (1 << 17) + 16;


int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  
  vector<int> a(n+1);
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    a[x]++;
    a[y]++;
  }

  copy_n(a.begin()+1, n, ostream_iterator<int>(cout, "\n"));
  cout << flush;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++) {
    int temp=int(s.at(i));
    temp+=n;
    if(temp>90) {
      temp-=26;
    }
    cout << char(temp);
  }
  cout << endl;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    use std::iter::repeat;

    let S = rl();

    println!(
        "{}",
        ["Sunny", "Cloudy", "Rainy"]
            .iter()
            .cycle()
            .skip_while(|&&s| s != S)
            .nth(1)
            .unwrap()
    )
}


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

int main()
{
  char c;
  int N=0, S=0, E=0, W=0;
  while(scanf("%c",&c)){
    
    if(c=='\n') break;
    if(c=='N') N=1;
    if(c=='S') S=1;
    if(c=='E') E=1;
    if(c=='W') W=1;
  }
  if((N+S)%2==0 && (E+W)%2==0) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it
#define size SIZE
using namespace std;

int n;
vector<int> parent;
vector<int> size;

void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
        // size[b] = size[a];
    }
}

signed main()
{
    int n, m, k;
    cin >> n >> m >> k;
    parent.resize(n+1);
    size.resize(n+1);
    vector<int> fr(n+1,0);
    vector<int> en(n+1,0);
    rep(i, 1, n+1)
        make_set(i);
    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        // a--; b--;
        union_sets(a, b);
        fr[a]++;
        fr[b]++;
    }
    rep(i, 1, n+1)
        size[find_set(i)] = max(size[find_set(i)], size[i]);
    rep(i, 1, n+1)
        size[i] = size[find_set(i)];
    
    // rep(i, 0, n)
    //     size[parent[i]] = max(size[parent[i]], size[i]);
    rep(i, 0, k)
    {
        int a, b;
        cin >> a >> b;
        if (find_set(a) == find_set(b))
        {
            en[a]++;
            en[b]++;
        }
    }
    rep(i, 1, n+1)
        cout << size[i] - fr[i] - en[i] - 1 << " ";
    return 0;
}

Measured memory_bytes: 6364
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        int n=ni(),freq[]=new int[100*1000+1];

        for(int i=1;i<=n;i++){
            int x=ni();
            freq[x]++;
        }

        long sum=0l;
        for(int i=1;i<=100*1000;i++)
            sum+=freq[i]*1l*i;

        int q=ni();
        while(q-- > 0){
            int b=ni(),c=ni();
            freq[c]+=freq[b];
            
            sum-=(freq[b]*1l*b);
            sum+=(freq[b]*1l*c);

            freq[b]=0;
            pn(sum);
        }
    }
 
 
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;
 
    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

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

using namespace std;

long long inf=1000000007;

int main(){
	int x,y;
	cin>>x>>y;

	vector<long long> score={300000,200000,100000,0};

	long long ans=0;

	ans+=score.at(min(3,x-1));
	ans+=score.at(min(3,y-1));

	if(x==1 && y==1) ans+=400000;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		boolean a[] = new boolean [31];
		Arrays.fill(a, false);

		for(int i=0; i<28; i++)
		{
			int n = sc.nextInt();
			a[n] = true;
		}
		for(int i=1; i<=30; i++)
			if(!a[i])
				System.out.println(i);

	}

}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100000;
int n;
int h[MAX_N];
ll dp[MAX_N];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) cin >> h[i];

  dp[1] = LLONG_MAX;

  forn (i,n-1) {
    chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
    if (i < n-2) {
      dp[i+2] = dp[i] + abs(h[i]-h[i+2]);
    }
  }

  cout << dp[n-1] << endl;


  return 0;
}


Measured memory_bytes: 1408
def main():
    """"ここに今までのコード"""
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
p=list(map(int,input().split()))
t=0
k=sum(p[0:K])

if N==K:
  print((k+K)/2)
else:
  for i in range(N-K):
    k-=p[i]
    k+=p[i+K]
    if k>t:
      t=k
    
  print((K+t)/2)

if __name__ == '__main__':
    main()      

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

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    vec A(N); readvec(A);

    if(N == 1){
        cout << "YES";
        return 0;
    }

    int s = 0;
    REP(i, N) s += A[i];
    int t = N * (N + 1) / 2;
    if(s % t != 0){
        cout << "NO";
        return 0;
    }

    s /= t;

    REP(i, N){
        int d = A[i] - A[(i + N - 1) % N] - s;
        if(d > 0 || d % N != 0){
            cout << "NO";
            return 0;
        }
    }
    
    cout << "YES";
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 1152
def 解():
    iN = int(input())
    aA = map(int,input().split())
    aA = sorted(map(lambda x,y:x-y,aA,range(1,iN+1)))
    iL = len(aA)
    if iL % 2 :
        iMed = aA[(iL-1)//2]
    else:
        iMed = aA[iL//2]
    iMean = sum(aA) // 2
    iBlim= min(iMed,iMean)
    iUlim= min(iMed,iMean+1)

    print(min(sum(abs(a-i) for a in aA) for i in [iMed,iMean,iMean+1]))

解()


Measured memory_bytes: 25708
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;

int main(){
	char n[3];
	
	cin >> n;

	if (n[0] == n[2]) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a*3+b)/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include <climits>
#include<queue>
#include<functional>
#include<vector>
#include<map>
#include<stack>
using namespace std;

#define INF 1<<30









int main()
{
   int r;
   cin>>r;
   if(r<1200){cout<<"ABC";}
   else if(r>=1200&&r<2800){cout<<"ARC";}
   else{cout<<"AGC";}




	return 0;
}


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

int main(void){
int a,b;
  cin >> a >>b;
  if(a>b){
     for(int i=0;i<a;i++){
        cout << b;
     }
  }else{
      for(int i=0;i<b;i++){
        cout << a;
     }
  }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

ll powll(ll n,ll k){ ll ret=1; while(k){ if(k&1)ret=ret*n; n=n*n; k>>=1; } return ret; }

int main(){
  ll n;
  cin >> n;
  string s;
  for(int i=0; i<15; i++) {
    int tmp = (n%26);
    if(tmp==0) tmp=26;
    s.push_back('a'+tmp-1);
    if(n%26==0) n--;
    n /= 26;
    if(n<=0) break;
  }
  reverse(s.begin(),s.end());
  cout << s << ln;


  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a,b;;

 
 cin>>a>>b;
 if(a==b)
	cout<<"Draw";
	else if(a==1)
	cout<<"Alice";
	else if(b==1)
	cout<<"Bob";
else  if((a>b))
	cout<<"Alice";
else if((a<b))
	cout<<"Bob";;;


 

	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 repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc043_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  string ans = "";
  rep(i, S.size()) {
    if (S[i] == 'B') {
      if (ans.size() > 0) {
        ans = ans.substr(0, ans.size() - 1);
      }
    } else {
      ans.push_back(S[i]);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll;
#pragma GCC optimize("O3")
#define pb push_back
int32_t main()  {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string ans = "" ; 
    for ( int i = 0 ; i < s.size() ; ++i ) {
        if ( s[i]== '?') ans+="D";
        else ans+=s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3896
def main(k, n, A):
    distances = [A[0] + k-A[-1]]

    for i in range(1, n):
        distances.append(A[i] - A[i-1])

    print(k - max(distances))


if __name__ == "__main__":
    k, n = map(int, input().split())
    A = list(map(int, input().split()))

    main(k, n, A)


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

ll N, M;
vector<pair<ll, ll>> drinkshop;

int main() {
    scanf("%Ld %Ld", & N, & M);
    drinkshop.resize(N);
    for (int i = 0; i < N; i++) {
        ll templ, tempr;
        scanf("%Ld %Ld", & templ, & tempr);
        drinkshop[i] = make_pair(templ, tempr);
    }

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

    ll ans = 0;
    for(int i = 0; i < N && M; i++) {
        while(drinkshop[i].second && M) {
            drinkshop[i].second--;
            M--;
            ans += drinkshop[i].first;
        }
    }

    printf("%Ld\n", ans);
    return 0;
}



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

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl


using ll = long long;
using hll = __int128;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}


#ifdef _getchar_nolock
#else
#define _getchar_nolock getchar_unlocked
#endif

template <typename T>
void freadT(T &x) {
    x = 0;
    char ch = _getchar_nolock();
    ll sign = 1;

    while (!isdigit(ch)) {
        if (ch == '-')
            sign *= -1;
        ch = _getchar_nolock();
    }

    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = _getchar_nolock();
    }

    x *= sign;
}


#define solvsh
//#define multi

#ifdef solvsh

//const int MAXN = 1e2 + 2;

#define uint ll

uint ml(uint a, uint b){
    return (a*1ll * b);
}

uint add(uint a, uint b){
    return (a*1ll + b);
}

clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}


void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    for (int i = 0; i < k; ++ i){
        if (c <= b) c *= 2;
        else if (b <= a) b *= 2;
    }
    if (a < b && b < c) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

#else

void solve() {

}


#endif


void multisolve() {
//    prec();
    int t;
    cin >> t;

//    scanf("%d", &t);

    int i = 1;
    while (t--) {
        cout << "Case #" << (i++) << ":\n";
        solve();
//        cout << "\n";
    }
}

#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

}

Measured memory_bytes: 3652
import sys


xx = 500000
f = [0, 1] * xx

i = 3
while i * i <= 2 * xx:
    if f[i] == 1:
        j = i * i
        while j <= 2 * xx:
            f[j] = 0
            j += i + i
    i += 2

f.pop(0)
f.pop(1)

for n in sys.stdin:
    i = int(n)
    if i < 2:
        print(0)
    else:
        print(sum(f[:i - 1]))

Measured memory_bytes: 24204
#include <iostream>
#include <algorithm>
using namespace std;
int a[16][16],mata[16][16];
int x,y,x1,x2,y1,y2,N,p;
void init() {
	for(int l=0; l<16; ++l) {
		for(int m=0; m<16; ++m) mata[l][m] = a[l][m] = 0;
	}
}

int main() {
	cin >> N;
	for(int i=0; i<N; ++i) {
		cin >> x >> y;
		cin >> p;
		init();
		for(int k=0; k<p; ++k) {
			cin >> x1 >> y1 >> x2 >> y2;
			if(x1 == x2) mata[x1][min(y1,y2)] += 1;
			else mata[min(x1,x2)][y1] += 10;
		}
		for(int l=0; l<y+1; ++l) {
			for(int m=0; m<x+1; ++m) {
				if(m==0 && l==0) a[m][l]=1;
				if(m != 0 && mata[m-1][l]/10 == 0) a[m][l] += a[m-1][l];
				if(l != 0 && mata[m][l-1]%10 == 0) a[m][l] += a[m][l-1];
			}
		}
		if(a[x][y] == 0) cout << "Miserable Hokusai!" << endl;
		else cout << a[x][y] << endl;
	}
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, yen;
    cin >> n >> yen;
    rep(x, n+1) rep(y, n+1) {
        int z = n - x - y;
        if ((z >= 0 && z <= 2000) && yen == 10000 * x + 5000 * y + 1000 * z) {
            printf("%d %d %d\n", x, y, z);
            return 0;
        }
    }
    puts("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


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

    int64_t ans = 0;
    for(int i=1; i<=N; i++) {
        for(int j=1; i*j<=N; j++) {
            ans += i*j;
        }
    }

    cout << ans << endl;

    // int64_t ans = 0;
    // for(int i=1; i<=N; i++) {
    //     int64_t tmp = 1;
    //     for(auto [key, val]: prime_factor(i)) {
    //         tmp *= val+1;
    //     }
    //     // cerr << tmp << endl;
    //     ans += i*tmp;
    // }

    // cout << ans << endl;
    // vector<int64_t> v(N+1, 1);
    // v[0] = v[1] = 0;
    // for(int i=1; i<=N; i++) {
    //     if(v[i] > 1) continue;
    //     for(int j=1; i*j<=N; j++) {
    //         v[i*j] = i;
    //     }
    // }

    // vector<int64_t> dp(N+1);
    // iota(dp.begin(), dp.end(), 0);
    // for(int i=N; i>1; i--) {
    //     dp[i/v[i]] += dp[i];
    //     // if(v[i] = 1) {
    //     //     dp[1] += dp[i];
    //     // } else if(v[i]) {
    //     //     dp[i/v[i]] += dp[i];
    //     // } else {
    //     //     dp[0] += dp[i];

    //     for(auto e: dp) {
    //         cerr << e << ' ';
    //     }
    //     cerr << endl;
    //     // }
    // }

    // cout << accumulate(dp.begin(), dp.end(), 0L) << endl;
    // // cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 3628