akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 1e6 +9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9+7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;

ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
ll val[N];
ll adj[N][2];
ll ans = 0;
multiset<ll> l,r;
map<ll,bool> cnbf;
map<ll,int> ct;
void dfs(ll v){
     if(adj[v][0]!=-1){
          l.insert(val[v]);
          dfs(adj[v][0]);
          auto e = l.find(val[v]);
          l.erase(e);
     }
     if(adj[v][1]!=-1){
          r.insert(val[v]);
          dfs(adj[v][1]);
          auto e = r.find(val[v]);
          r.erase(e);
     }
     ll ul = inf;
     ll ll = 0;
     if(l.size() ){
          ul = *l.begin();
         
     }
     if(r.size()){
          ll = *r.rbegin();
          // cout<<ll<<'\n';
     }
          // cout<<v<<" "<<ul<<" "<<ll<<'\n';

     if(val[v]>=ll && val[v]<=ul){
          cnbf[val[v]] = 1;
     }


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

     ll q = 1;
     // cin>>q;
     while(q--){
          ll n,k;cin>>n>>k;
          ll h[n];
          ll dp[n];
          for(int i = 0;i<n;i++){
               cin>>h[i];
          }
          dp[0] = 0;
          for(int i = 1;i<n;i++){
               dp[i] = inf;
               for(int j = max(0ll,i-k);j<i;j++){
                    dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
               }
               // cout<<dp[i]<<" "<<'\n';
          }
          cout<<dp[n-1]<<'\n';
     }
}         

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;



long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}

int popcount(int A) {
	int count = 0;
	while (1) {
		if (A == 0) {
			break;
		}
		if (A % 2 == 1) {
			count++;
		}
		A = A / 2;
	}
	return count;
}

int main() {

	int N;
	int X;
	string ans;

	cin >> N;

	ans = "No";

	if (N >= 30) {
		ans = "Yes";
	}


	cout <<ans <<endl;

	cin >> N;

	return 0;


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0;
    cin >> n;
    int p[n];
    for(int i=0;i<n;i++) cin >> p[i];
    for(int i=0;i<n;i++){
        if(i==n-1&&i+1==p[i]){
            swap(p[n-1],p[n-2]);
            cnt++;
        }
        if(i+1==p[i]) {
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0)
char a[1 << 20];
char b[1 << 20];
int phi1[1 << 20];
int phi2[1 << 20];
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>(a+1);
    n = strlen(a+1);
    int ok = 1;
    for (int i = 1;i <= n;++i)
        ok &= a[i] == a[1];
    if (ok) return fo << n << '\n' << 1 << '\n',0;
    for (int i = 1;i <= n;++i) b[i] = a[n - i + 1];
    for (int i = 2,k = 0;i <= n;++i)
    {
        while (k && a[k+1] != a[i]) k = phi1[k];
        k += a[k+1] == a[i];
        phi1[i] = k;
    }
    for (int i = 2,k = 0;i <= n;++i)
    {
        while (k && b[k+1] != b[i]) k = phi2[k];
        k += b[k+1] == b[i];
        phi2[i] = k;
    }
    int ans = 0;
    int len = n - phi1[n];
    if (len == n || n % len) return puts("1\n1") * 0;
    for (int i = 1;i < n;++i)
    {
        int len1 = i - phi1[i];
        int len2 = n - i - phi2[n - i];
        ans += (len1 == i || i % len1) && (len2 == n - i || (n - i) % len2);
    }
    fo << "2\n" << ans << '\n';
    return 0;
}




Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int bfs(vector<string>& s, int sy, int sx) {
	if (s[sy][sx] == '#')return 0;
	int h = s.size();
	int w = s[0].size();
	queue<P> q;
	int dy[] = { 0,0,-1,1 };
	int dx[] = { -1,1,0,0 };
	vector<vector<int>> d(h, vector<int>(w, INT_MAX));
	q.push(P(sy, sx));
	d[sy][sx] = 0;
	while (!q.empty()) {
		P p = q.front();
		q.pop();
		REP(i, 4) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx]=='.') {
				int nd = d[p.first][p.second] + 1;
				if (d[ny][nx] > nd) {
					d[ny][nx] = nd;
					q.push(P(ny, nx));
				}
			}
		}
	}
	int res = 0;
	REP(i, h) {
		REP(j, w) {
			if (d[i][j] != INT_MAX) {
				chmax(res, d[i][j]);
			}
		}
	}
	return res;
}

int main() {
	IOS;
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	REP(i, h) {
		cin >> s[i];
	}
	int res = 0;
	REP(i, h) {
		REP(j, w) {
			chmax(res, bfs(s, i, j));
		}
	}
	put(res);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
using namespace std;
typedef pair<int,int> pii;
const int N = 1e4+10;

string dp[N], val[15];
string num = "123456789";
int c[] = {2,5,5,4,5,6,3,7,6}, cs[200], n, m;
string a[15];

void update (string &x, string y, string z)
{
    if (x.size() > y.size() + 1) return;
    if (z[0] > y[0]) z += y, swap(y, z);
    else y += z;
    if (x.size() < y.size()) x = y;
    else
    {
        for (int i=0; i<x.size(); i++)
        {
            if (x[i] > y[i]) return;
            else if (x[i] < y[i])
            {
                x = y;
                break;
            }
        }
    }
}

signed main()
{
    XinAi
    for (int i=0; i<9; i++) cs[num[i]] = c[i];
    cin >> n >> m;
    for (int i=0; i<m; i++) cin >> a[i];
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
        {
            if (i!=0 && dp[i]=="") continue;
            update(dp[i+cs[a[j][0]]], dp[i], a[j]);
        }
    cout << dp[n] << '\n';
}


Measured memory_bytes: 53404
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
 
using namespace std;

const char nl = '\n';

void solve() {
	string s,t;
	cin >> s >> t;
	int n = (int) s.size();
	int m = (int) t.size();
	int ans=INT_MAX;
	for(int i = 0; i < n-m; i++) {
		string g = s.substr(i,m);
		if (g==t) {
			ans = 0;
			break;
		}
		else {
			int ch=0;
			for(int j = 0; j < m; j++) {
				if(t[j]!=g[j]) ch++;
			}
			ans = min(ans,ch);
		}
	}
	if(ans == INT_MAX) {
		ans = 0;
		for(int i = 0; i < n; i++) {
			if(s[i]!=t[i]) ans++;
		}
	}
	cout << ans << nl;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}


Measured memory_bytes: 3616
#include<stdio.h>
#define N 100

int main(void){
  int i,n,c;
  int yf[N],yl[N],y;

  for(i=0;;i++){
    scanf("%d%d",&yf[i],&yl[i]);
    if(yf[i]==0 && yl[i]==0)
      break;
  }
  n=i;
  for(i=0;i<n;i++){
    c=0;
    for(y=yf[i];y<=yl[i];y++)
      if(y%4==0 && (y%100!=0 || y%400==0)){
        printf("%d\n",y);
        c++;
      }
    if(c==0)
      printf("NA\n");
    if(i<n-1)
      printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
s = int(input())
i = 1

if s == 4:
    ans = 4
elif s == 2:
    ans = 4
elif s == 1:
    ans = 4
else:
    while s != 4:
        if s % 2 == 0:
            s = s // 2
        else:
            s = 3 * s + 1
        i += 1
    ans = i + 3

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

main(){
  int S[10000],T[10000],i,n,q,j,c=0;


  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]) {
	c++;
	break;
      }
    }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

#define N_MAX 5050
int n;

int dp[N_MAX][N_MAX];

int main()
{
    int n;
    string s;
    cin >> n >> s;
    
    int ans = 0;
    rep(i, n)rep(j, n){
        if(s[i] == s[j]){
            if (abs(i-j) > dp[i][j]) dp[i+1][j+1] = dp[i][j] + 1; 
        }
        ans = max(dp[i+1][j+1], ans);
    }
    // rep(i, n+1){
    //     rep(j, n+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << ans << endl;
}



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

bitset<55> e[55][55], d[1 << 21];
int c[1 << 21];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            if(i != j)
                e[i][j] = ~e[i][j];
    for(int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        e[a][b] = e[b][a] = 0;
        e[a][b][i] = e[b][a][i] = 1;
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            for(int k = 1; k <= n; k++) {
                auto x = e[j][i] | e[i][k];
                if(x.count() < e[j][k].count())
                    e[j][k] = x;
            }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        d[1 << i] = e[u][v];
    }
    for(int i = 1; i < 1 << m; i++)
        d[i] = d[i & i - 1] | d[i & -i], c[i] = c[i & i - 1] + 1;
    long r = 0;
    for(int i = 0; i < 1 << m; i++)
        r += (c[i] & 1 ? -1 : 1) * (1l << n - 1 - d[i].count());
    cout << abs(r) << endl;
    return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

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

    bool odd = true;
    bool even = true;

    rep (i, S.size()) {
        if ((i + 1) % 2 == 1) {
            if (S[i] == 'L') {
                odd = false;
            }
        } else {
            if (S[i] == 'R') {
                even = false;
            }
        }
    }

    cout << ((odd && even) ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
  int N,L,sum_x;
  cin >> N >> L;
  std::vector<int> x(N);
  std::vector<int> b(N);
  for (int i = 0;i < N;i++) {
    x.at(i) = L + i;
    sum_x += x.at(i);
  }
  for (int i = 0;i < N;i++) {
    b.at(i) = abs(x.at(i));
  }
  std::vector<int>::iterator minIt = std::min_element(b.begin(), b.end());
  int minIndex = std::distance(b.begin(), minIt);
  cout << sum_x - x.at(minIndex) << endl;
}



Measured memory_bytes: 256
#ABC124 D
N, K = list(map(int, input().split()))
S = list(input())
ones = [0]
zeros = []
flag = '1'
for s in S:
    if s == '1':
        if flag == '1':
            ones[-1] += 1
        else:
            ones.append(1)
    else:
        if flag == '1':
            zeros.append(1)
        else:
            zeros[-1] += 1
    flag = s
ones.append(0)

tmp = sum(ones[0:K+1]) + sum(zeros[0:K])
ans = tmp
for i in range(len(zeros) - (K + 1) + 1):
    tmp = tmp + ones[i + K + 1] + zeros[i + K] - ones[i] -zeros[i]
    ans = max(ans,tmp)
print(ans)

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

#ifdef DEBUG
#include "debug.h"
#endif

using namespace std;

#define mp make_pair
#define mt make_tuple
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define sz(a) ((int)(a).size())
#define make_unique(a) (a).resize(unique(all((x))) - (x).begin())

typedef long long ll;

template<typename T> inline bool mmin(T& a, const T &b) { return b < a ? (a = b, true) : false; }
template<typename T> inline bool mmax(T& a, const T &b) { return b > a ? (a = b, true) : false; }

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    int w;
    cin >> s >> w;
    for (int i = 0; i < sz(s); i += w) {
        cout << s[i];
    }
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll long long
#define vi vector <int >
#define vll vector <ll >
#define pii pair <int, int>
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define a first
#define b second
	
   
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    
    string ax, s1, s2;
    int x, z;
    cin >> s1 >> s2;
    cin >> x >> z;
    cin >> ax;
    if(ax == s1){
        cout << x - 1 << " " << z << endl;
    }else{
        cout << x << " " << z - 1 << endl;
    }
    
    
    return 0;
}

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

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

int S[1000];
int top = 0;

// push, popを実装する
void push(int x) {
  top++;
  S[top] = x;
}

int pop() {
  top--;
  return S[top + 1];
}

int main() {
  int a, b;
  char s[100];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else
      push(atoi(s));
  }

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



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


int main() {
    long long N;
    cin >> N;
    string a;
    while(N>0) {
        int x=N%26;
        char c;
        if (x==0) c='z';
        else c='a'+x-1;
        a+=c;
        N/=26;
        if (x==0) N--;
    }
    reverse(a.begin(),a.end());
    cout << a << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#define ERA_MAX 246913
#define ROOT_MAX 496

using namespace std;

bool Eratos[ERA_MAX];

int main()
{
	for (int i = 0; i < ERA_MAX; i++) {
		if (i >= 2)
			Eratos[i] = true;
		else
			Eratos[i] = false;
	}
	for (int i = 0; i < ROOT_MAX; i++) {
		if (Eratos[i])
			for (int j = 2 * i; j < ERA_MAX; j += i)
				Eratos[j] = false;
	}
	int n,res;
	while (cin >> n, n) {
		res = 0;
		for (int i = n + 1; i <= 2 * n; i++)
			if (Eratos[i])
				res++;
		cout << res << endl;
	}
	return 0;
}

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

int main() {
  ll n, k; cin >> n >> k;
  vec a(n);
  vec f(n, -1);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }

  int c = 0;
  int b = 0;
  while (f[b] < 0) {
    f[b] = c;
    c++;
    b = a[b];
  }
  int e = c - f[b];

  int d = 0;
  if (k <= f[b]) {
    rep(i,k) {
      d = a[d];
    }
  } else {
    while(d != b) {
      d = a[d];
      k--;
    }
    rep(i,k%e) {
      d = a[d];
    }
  }


  cout << d + 1 << endl;
}


Measured memory_bytes: 4840
#include<iostream>
    #include<vector>
    #include<numeric>
    #define REP(m,n) for(int i=m;i<n;i++)
    using namespace std;
    int main(){
    int M,N,i;
    long long int P,X,total;
    cin>>N;
    vector<int> T(N);
    REP(0,N) cin>>T[i];
    total = accumulate(T.begin(),T.end(),0);
    cin>>M;
    vector<int> sum(M);
    REP(0,M){
    cin>>P>>X;
    sum[i] = total -T[P-1] + X;
     }
    REP(0,M) cout<<sum[i]<<endl;
    return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N;
int main(){
        cin>>N;
        LL sum=0;
        LL last=0;
	REP(i,N+1){
	    if(i==0)continue;
	    sum+=i;
	    if(sum>=N){
	       last=i;
	       break;
	    }
	}
	REP(i,last+1){
	    if(i==0)continue;
	    if((sum-i)==N)continue;
	    cout<<i<<endl;
	}
	return 0;
}

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

int main(){
    char b;
    cin >> b ;
    if (b == 'A'){
        cout << 'T' << endl;
    }
    if (b == 'C'){
        cout << 'G' << endl;
    }
    if (b == 'T'){
        cout << 'A' << endl;
    }
    if (b == 'G'){
        cout << 'C' << endl;
    }
}

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

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FORN(i, a, n, b) for (int i = a; i < n; i += b)
#define FRON(i, a, n, b) for (int i = a; i > n; i -= b)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FRO(i, a) for (int i = a; i > 0; i--)
#define MP make_pair
#define PB push_back
#define INF 1000000010
#define MOD 1000000007 // 998244353
#define PI 3.141592653589793238462643383279502884197169399375105820974945
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef vector<string> VS;
typedef vector<VI> VII;

//debugging
#define n_l '\n'
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void debugm(){;} template<typename Heads, typename... Tails> void debugm(Heads H, Tails... T){ cout << to_string(H) << " | "; debugm(T...); } 
#define debugm(...) cout << "[" << #__VA_ARGS__ << "]: "; debugm(__VA_ARGS__); cout << endl







int main() {
    FASTIO;
    int r; cin >> r;
    printf("%.4f\n", 2*PI*r);
}



Measured memory_bytes: 3720
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = int(1e9) + 7;

using PrimeFactors = unordered_map<int,int>;

void getPrimeFactor(int n, PrimeFactors &pf) {
  for (int i = 2; i*i <= n; ++i) {
    while(n % i == 0) {
      pf[i] += 1;
      n /= i;
    }
  }
  if (n > 1) pf[n] += 1;

  return;
}

PrimeFactors getPrimeFactor(int n) {
  PrimeFactors tmp;
  getPrimeFactor(n, tmp);
  return std::move(tmp);
}

vector<i64> getFactorials(int n) {
  vector<i64> f(n+1);
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    f[i] = f[i-1] * i % MOD;
  }
  return std::move(f);
}

i64 modPow(i64 n, i64 p) {
  i64 ret = 1;
  while(p > 0) {
    if (p & 1) ret = ret * n % MOD;
    n = n * n % MOD;
    p >>= 1;
  }
  return ret;
}

i64 modInv(i64 n) {
  return modPow(n, MOD - 2);
}

i64 modDiv(i64 a, i64 b) {
  return a * modInv(b) % MOD;
}

signed main()
{
  int N, M;
  cin >> N >> M;

  PrimeFactors pf = getPrimeFactor(M);

  const auto f = getFactorials(N + 64);

  i64 ans = 1;
  for (const auto e : pf) {
    const int cnt = e.second;
    ans = ans * modDiv(f[cnt + N - 1], f[N-1] * f[cnt] % MOD) % MOD;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void){
        char s[2][101],check[101];
        int len[2],i,j,ch=0;
        scanf("%s",s[0]);
        scanf("%s",s[1]);
        len[0] = strlen(s[0]);
        len[1] = strlen(s[1]);
        for(i=0;i<len[0];i++){
                if(s[1][0]==s[0][i]){
                        for(j=0;j<len[1];j++)
                                check[j]=s[0][(i+j)%len[0]];
                        check[len[1]]='\0';
                        if(strcmp(s[1],check)==0)
                                ch=1;
                }
        }
        if(ch)
                puts("Yes");
        else
                puts("No");
        return 0;
}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c==17 && a*b*c==175)
    	cout<<"YES"<<endl;
    else
    	cout<<"NO"<<endl;
    return 0;
}

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

int main() {
    int H, W;
    for(int i=0; ; i++){
    cin >> H >> W;
    if(H==0 && W==0) break;
    for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
       cout << "#";
    }
    cout << endl;
    }
    cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3076
import java.io.PrintWriter

data class Edge(val v: Int, val c: Int)

fun main(args: Array<String>) = with(PrintWriter(System.out)) {
    val n = readLine()!!.toInt()
    val edge = (0 until n).map {
        val tmp = readLine()!!.split(' ')
//            .drop(2)
            .map { it.toInt() }
//            .zipWithNext { v, c -> Edge(v, c) }
        (1..tmp[1]).map { i ->
            Edge(tmp[2*i], tmp[2*i+1])
        }
    }

    val d = IntArray(n) { Int.MAX_VALUE }
    val explored = mutableSetOf<Int>()
    val frontier = mutableSetOf<Int>()

    d[0] = 0
    frontier.add(0)
    while (frontier.isNotEmpty()) {
        val minV = frontier.minBy { d[it] }!!
        explored.add(minV)
        frontier.remove(minV)
        edge[minV].forEach {
            if (!explored.contains(it.v)) {
                if (d[it.v] > d[minV] + it.c) {
                    d[it.v] = d[minV] + it.c
                    frontier.add(it.v)
                }
            }
        }
    }

    d.forEachIndexed { index, i ->
        println("$index $i")
    }

    flush()
}



Measured memory_bytes: 36384
n=int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    return arr
l=factorization(n)
ans=0
for p,i in l:
  cnt=1
  while i>=cnt:
    ans+=1
    i-=cnt
    cnt+=1
print(ans)


Measured memory_bytes: 9472
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    vector<ll> mitasu; mitasu.reserve(100000);
    RANGE(m0, 2, 100000) {
        ll yakusu_num = 1;
        ll m = m0;
        for (ll f = 2; f * f <= m0; f++) {
            ll term = 1;
            while (m % f == 0) {
                m /= f;
                term++;
            }
            yakusu_num *= term;
            if (yakusu_num >= 5) break;
        }
        if (m > 1) yakusu_num *= 2;
        if (yakusu_num >= 5) {
            mitasu.push_back(m0);
        }
    }
    
    ll q; cin >> q;
    REP(i, q) {

        ll n; cin >> n;

        auto ub = upper_bound(ALL_OF(mitasu), n);
        cout << ub - mitasu.begin() << endl;

    }
    
}


Measured memory_bytes: 3176
def solve(S,K):
    if all(S[0]==c for c in S):
        return (len(S)*K)//2

    if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

    t = 0
    k = 0
    last = S[0]
    for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
    t += k//2
    res += t*K
    return res

S = input()
K = int(input())
print(solve(S,K))

Measured memory_bytes: 61608
s = list(input())
l = len(s)

s1 = s[:int(l/2)]
s2 = s[-int(l/2):]
s2.reverse()

dif = 0
for i in range(int(l/2)):
  if s1[i] != s2[i]:
    dif += 1

print(dif)

Measured memory_bytes: 3060
M=998244353
def extended_euclid_algorithm(a,b)
  d0,x0,y0,d1,x1,y1=a,1,0,b,0,1
  until d1==0
    q=d0/d1
    d0,x0,y0,d1,x1,y1=d1,x1,y1,d0-q*d1,x0-q*x1,y0-q*y1
  end
  [d0,x0,y0]
end

def inverse(a,p)
  d,x,y=extended_euclid_algorithm(a,p)
  x%p
end

def num(comb,a,b)
  (comb[a]*comb[b])%M
end

n,a,b,k=gets.split.map(&:to_i)
comb=[1]
1.upto(n){|i|
  comb << (comb.last*(n-i+1)*inverse(i,M))%M
}

ans=0
(n+1).times{|i|
  d=k-a*i
  break if d<0
  if d%b==0
    j=d/b
    next if j>n
    ans+=num(comb,i,j)
  end
}

puts ans%M

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

using namespace std;

int A, B, C, X, Y;

int main(){
    cin >> A >> B >> C >> X >> Y;

    int ans = 0;
    if( C * 2 < A + B ){
        int res = min(X, Y);
        ans = C * 2 * res;
        X -= res;
        Y -= res;
    }

    

    if( X != 0 ){
        if( C * 2 < A ) ans += C * 2 * X;
        else            ans += A * X;
    }
    if( Y != 0 ){
        if( C * 2 < B ) ans += C * 2 * Y;
        else            ans += B * Y;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

const int N = 1e5 + 5;
LL n, x, B[N], L[N], U[N];
LL Gain[N], margin = 0;
vector<int> I;
vector<LL> S;

bool check(LL budget) {
  LL r = budget % x, q = budget / x;
  if (r == 0) return S[q] >= margin;
  LL ans = 0;
  FI(i, 1, n) {
    LL gain;
    if (r <= B[I[i]]) {
      gain = 1LL * L[I[i]] * r;
    } else {
      gain = 1LL * U[I[i]] * (r - B[I[i]]) + 1LL * L[I[i]] * B[I[i]];
    }
    gain += S[min(i - 1, (int)q)];
    if (q + 1 > i) gain += S[q + 1] - S[i];
    ans = max(ans, gain);
  }
  return ans >= margin;
}

int main() {
  cin >> n >> x;
  FI(i, 1, n) scanf("%lld%lld%lld", &B[i], &L[i], &U[i]);
  FI(i, 1, n) margin += 1LL * L[i] * B[i];
  FI(i, 1, n) Gain[i] = 1LL * U[i] * (x - B[i]) + 1LL * L[i] * B[i];
  I.resize(n + 1), S.resize(n + 1);
  iota(I.begin(), I.end(), 0);
  sort(I.begin() + 1, I.end(), [&](int i, int j) { return Gain[i] > Gain[j]; });
  FI(i, 1, n) S[i] = S[i - 1] + Gain[I[i]];
  LL l = -1, r = 1LL * x * n;
  while (l + 1 < r) {
    LL m = (l + r + 1) / 2;
    if (check(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod = M) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P, ll Mod = M) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod = M) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod = M) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

int main(void) {
  int X; cin >> X;
  if (X < 4){
    cout << 1 << endl;
    return 0;
  }
  int ans = 0;
  int Xp = 2;
  for (int i = X; i > 0; i--){
    for (int j = 2; j < X; j++){
      Xp = j*j;
      while (Xp <= X){
        if (ans < Xp){
          ans = Xp;
        }
        Xp *= j;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin >> n;
    map<ll,ll> mp;
    ll num;
    ll l1=0,l2=0;
    rep(i,n){ 
        cin >> num;
        mp[num]++;
    }

    for(auto &e: mp){
        //cout << e.first << "," << e.second << endl;
        if(e.second > 1){
            if(e.second>=4){
                l2 = l1 = e.first;
            }else
            if(l1 < e.first){
                l2 = l1;
                l1 = e.first;
            }
        }
    }
    //cout << l1 << "," << l2 << endl;
    ll ans = l1*l2;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 6528
import sys
import math
import bisect

def main():
    a, b, c, d = map(int, input().split())
    if abs(a - c) <= d:
        print('Yes')
    elif abs(a - b) <= d and abs(b - c) <= d:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
(let* ((n (read))
       (s (read-line))
       (ans 400000)
       (w (make-array (+ n 2) :element-type 'integer
                              :initial-element 0
                              :fill-pointer 0)))
  (loop for i from 1 upto n
        if (equal (char s (- i 1)) #\W) do (setf (aref w i) (1+ (aref w (- i 1))))
        if (equal (char s (- i 1)) #\E) do (setf (aref w i) (aref w (- i 1))))
  (setf ans (min (- (+ n (aref w 1)) (aref w n) 1) (aref w (- n 1))))
  (loop for i from 2 below n
        do (setf ans (min ans (- (+ n (aref w (- i 1)) (aref w i)) (aref w n) i))))
  (format t "~A~%" ans))


Measured memory_bytes: 16356
#include<stdio.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] inputArr = sc.nextLine().split(" ");
		long a = Long.parseLong(inputArr[0]);
		long b = Long.parseLong(inputArr[1]);
		sc.close();
		
		ArrayDeque<Long> divisorAList = new ArrayDeque<>();
		ArrayDeque<Long> divisorBList = new ArrayDeque<>();
		
		
		long dividedValue = a;
		for(long i = 2L; i*i <= a; i++) {
			if(dividedValue % i == 0L) {
				divisorAList.add(new Long(i));
				while(dividedValue % i == 0L) {
					dividedValue /= i;
				}
			}
		}
		if(dividedValue > 1L) {
			divisorAList.add(new Long(dividedValue));
		}
		
		dividedValue = b;
		for(long i = 2L; i*i <= b; i++) {
			if(dividedValue % i == 0L) {
				divisorBList.add(new Long(i));
				while(dividedValue % i == 0L) {
					dividedValue /= i;
				}
			}
		}
		if(dividedValue > 1L) {
			divisorBList.add(new Long(dividedValue));
		}
		
		int count = 1;// 1は絶対含む
		ArrayDeque<Long> smallQueue = null;
		ArrayDeque<Long> bigQueue = null;
		if(divisorAList.size() < divisorBList.size()) {
			smallQueue = divisorAList;
			bigQueue = divisorBList;
		}else {
			smallQueue = divisorBList;
			bigQueue = divisorAList;
		}
		
		while(!smallQueue.isEmpty() && !bigQueue.isEmpty()) {
			long smallQueueTop = smallQueue.pop();
			while(!bigQueue.isEmpty()) {
				if(smallQueueTop < bigQueue.peek()) {
					break;
				}
				long bigQueueTop = bigQueue.pop();
				if(smallQueueTop == bigQueueTop) {
					count++;
					break;
				}
			}
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define mx *max_element
#define mi *min_element
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
#define pi acos(-1)
int ar[N];
int tree[2*N];
int dp[N];
int bit[N];
signed main(){
 	// #ifndef ONLINE_JUDGE
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// #endif
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		string s;
		cin >> s;
		int n = s.size();
		vector<int>v(n+1,0);
		for(int i = 0; i <n;i++){
			if(s[i]=='<')v[i+1] = max(v[i+1],v[i]+1);
		}
		for(int i = n-1; i >=0;i--){
			if(s[i]=='>')v[i] = max(v[i], v[i+1]+1);
		}
		int ans=0;
		for(int i =0 ;i <=n;i++){
			ans+=v[i];
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4892
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=200000+10;
char s[maxn];
int n;
long long ans,cnt;
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;++i){
        if(s[i]=='A')++cnt;
        else if(s[i]=='B'&&s[i+1]=='C')ans+=cnt,++i;
        else cnt=0;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

  vector<ll> x(N + 1, 0), v(N + 1, 0), rwv(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    cin >> x[i] >> v[i];
  }

  // 累積和
  for (int i = 0; i < N; i++) {
    rwv[i + 1] = rwv[i] + v[i + 1];
  }

  vector<ll> r(N + 1, 0);
  for (int i = 0; i < N; i++) {
    r[i + 1] = max(r[i], rwv[i + 1] - x[i + 1]);
  }

  vector<ll> l(N + 1, 0);
  l[N] = rwv[N] - rwv[N - 1] - (C - x[N]);
  for (int i = N - 1; i >= 1; i--) {
    l[i] = max(l[i + 1], rwv[N] - rwv[i - 1] - (C - x[i]));
  }

  ll ans = 0;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, rwv[i] - x[i]);
    if (i < N) {
      ans = max(ans, rwv[i] - 2 * x[i] + l[i + 1]);
    }
  }

  for (int i = N - 1; i >= 0; i--) {
    ans = max(ans, rwv[N] - rwv[i] - (C - x[i + 1]));
    if (i > 0) {
      ans = max(ans, rwv[N] - rwv[i] - 2 * (C - x[i + 1]) + r[i]);
    }
  }
  cout << ans << endl;

  return 0;
}

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

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int[] A=new int[N];
        
	    for (int i=0; i<N;i++) {
	    	A[i]=gi();
	    }
	    
	    Arrays.parallelSort(A);
	    
	    if(N%2==0) {
	    	for (int i=0; i<N;i++) {
		    	if (A[i]!=Math.floorDiv(i+2, 2)*2-1) {
		    		System.out.println(0);
		    		return;
		    	}
		    }
	    } else {
	    	for (int i=0; i<N;i++) {
		    	if (A[i]!=Math.floorDiv(i+1, 2)*2) {
		    		System.out.println(0);
		    		return;
		    	}
		    }
	    }
	    
	    long a=1;
	    long nn=Math.floorDiv(N,2);
	    while(nn>0) {
	    	a*=2;
	    	a=a%1000000007;
	    	nn--;
	    }
	    System.out.println(a);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 59356
# 累積和

N, K = map(int, input().split())
p = list(map(int, input().split()))

e = []
for i in range(len(p)):
    e.append((p[i] + 1) / 2)

cum = [0]
for i in range(len(e)):
    cum.append(e[i] + cum[i])

ans = 0
for j in range(K, N+1):
    ans = max(ans, cum[j] - cum[j-K])
print(ans)


Measured memory_bytes: 24700
N = int(input())
D, X = map(int, input().split())
a = []
for i in range(N):
    a.append(int(input()))
    
sum = 0

for j in a:
    cnt = 0
    b = 0
    while b*j+1 <= D:
        cnt += 1
        b += 1
    sum += cnt

print(X + sum)

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

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

#define pb push_back
#define mp make_pair

inline int g(int a, int b, int c) {
    return __gcd(a, __gcd(b, c));
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    ll sum = 0;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            for (int k=1; k<=n; k++) {
                sum += g(i, j, k);
            }
        }
    }
    cout << sum << endl;

    return 0;
}




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

int main(){
  int X, Y, Z, K;cin >> X >> Y >> Z >> K;
  vll A, B, C;
  for (int i=0;i<X;++i){
    ll a;cin>>a;
    A.push_back(a);
  }

  for (int i=0;i<Y;++i){
    ll b;cin>>b;
    B.push_back(b);
  }

  for (int i=0;i<Z;++i){
    ll c;cin>>c;
    C.push_back(c);
  }

  vll AB_sum;
  for (int i=0;i<X;++i){
    for (int j=0;j<Y;++j){
      AB_sum.push_back(A[i]+B[j]);
    }
  }

  sort(AB_sum.begin(), AB_sum.end(), greater<ll>());

  int L=AB_sum.size();

  int K_=min(K, L);

  vll ans_list;

  for (int i=0;i<K_;i++){
    for (int j=0;j<Z;++j){
      ans_list.push_back(AB_sum[i]+C[j]);
    }
  }

  sort(ans_list.begin(), ans_list.end(), greater<ll>());

  for (int i=0;i<K;++i){
    cout << ans_list[i] << endl;
  }

  return 0; 
}

Measured memory_bytes: 43256
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define	       MEM(a,b)         memset(a,(b),sizeof(a))
#define	       CLR(p)           memset(p,0,sizeof(p))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
#define	       ff               first
#define	       sc              second
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define precision(a) fixed << setprecision(a)

#define mod 1000000007


ll ar[MAX];
int main()
{
 //O_O ;
   ll n;
  cin>>n;
  for(ll i=1;i<=n;i++)
    cin>>ar[i];
    ll ans=0;
    ll    ma=ar[1];
   for(ll i=2;i<=n;i++)
      {

          ma=max(ma,ar[i]);
         // cout<<"MA"<<ma<<ss;
       //   cout<<ar[i]<<nn;
     //     ll temp=ma-ar[i];cout<<"ar"<<temp<<nn;
          if((ar[i])-ma<0)
          {
             // cout<<"ma"<<ma<<nn;
              ans+=abs(ma-ar[i]);
          }



      }
      cout<<ans<<nn;

    return 0;
}



Measured memory_bytes: 5124
import itertools
N=50000+1
p=[True]*N
p[0],p[1]=False,False
for i in xrange(2,int(N**0.5)+1):
    if p[i]==True:
        for j in xrange(i**2,N,i):
            p[j]=False
plist=[i for i in xrange(N) if p[i]]
c=[0]*N*2
for i,j in itertools.combinations(plist,2):
    c[i+j]+=1
for i in xrange(N):
    if p[i]:c[i+i]+=1
while True:
    n=input()
    if n==0:break
    print c[n]

Measured memory_bytes: 6308
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long

long long MOD = 1000000007;

int main(){
    int N; cin >> N;
    ll ans=0, min_=MOD;
    int flag=1;
    for(int i=0; i<N; i++){
        ll A, B;
        cin >> A >> B;
        ans+=A;
        if(A>B){
            min_=min(min_, B);
        }
        if(A!=B){
            flag=0;
        }
    }
    if(flag==1){
        cout << 0 << endl;
        return 0;
    }
    cout << ans-min_ << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <map>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll N, M;
  cin >> N >> M;
  ll A[M];
  for(int i=0;i<M;i++){
    cin >> A[i];
  }
  
  ll sum = 0;
  for(int i=0;i<M;i++){
    sum += A[i];
  }
  ll ans = N-sum;
  if(ans < 0){
    ans = -1;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3716
from statistics import median

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

X_sorted = sorted(X)
X_med = median(X)
for i in range(N):
  if X[i] < X_med:
    res = X_sorted[N // 2]
  elif X_med < X[i]:
    res = X_sorted[N // 2 - 1]
  else:
    res = X[i]

  print(res)

Measured memory_bytes: 27244