akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;
const ll MOD=1e9+7;

int N, T;
vector<P> ev;
void input(){
	cin>>N>>T;
  rep(_,N){
    int t;
    cin>>t;
    ev.pb(mp(t,1));
    ev.pb(mp(t+T,-1));
  }
  sort(all(ev));
}

int ans;
void solve(){
  int tt=0;
  int tmp=0;
  rep(i,sz(ev)){
    P p=ev[i];
    int nt=p.fi;
    int ch=p.se;
    if(tmp>0)ans+=nt-tt;
    tmp+=ch;
    tt=nt;
  }
  cout<<ans<<endl;
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 6384
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "begin", long, "end");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    double w, h, x, y;
    scan(w, h, x, y);
    writefln("%s %s", w * h / 2, (x == w / 2) && (y == h / 2) ? 1 : 0);
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <map>
using namespace std;

int main()
{
    int n,num;
    map<int,int> m;
    map<int,int>::iterator iter;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&num);
        iter = m.find(num);
        if(iter!=m.end())
            m.erase(num);
        else
            m[num]=1;
    }
    printf("%d\n",m.size());
    return 0;
}


Measured memory_bytes: 4864
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define FASTNIBBA   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define lbnd        lower_bound
#define ubnd        upper_bound
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
#define endl        '\n'
ll dp[100005][105];
void solve()
{
   int n,w; cin>>n>>w;
   int wt[n],v[n];
   rep(i,0,n) cin>>wt[i]>>v[i];
   ll ans=0;
   rep(i,0,100005) rep(j,0,n+1) dp[i][j]=1e18;
   dp[0][0]=0;
   rep(i,0,100005)
   {
     rep(j,0,n+1)
     {
        if(j==0) continue;
        else{
        if(i>=v[j-1]) dp[i][j]=min(dp[i-v[j-1]][j-1]+wt[j-1],dp[i][j-1]);
        else dp[i][j]=min(dp[i][j-1],dp[i][j]);
      }
     }
   }
   rep(i,0,100005)
   {
    rep(j,0,n+1) if(dp[i][j]<=w) ans=max((ll)i,ans);
   }
   cout<<ans;
}
int main()
{
    FASTNIBBA;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

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

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

int w,h,xs,ys,xg,yg,n,cc;
int field[100][100];
bool flag;

void dfs(int x,int y,int c){
	if(flag) return;
	if(x == xg && y == yg) {
		flag = true;
		return;
	}
	for(int i = 0;i < 4;i++){
		int nx = x + dx[i],ny = y + dy[i];
		if(nx >= 0 && nx < w && ny >= 0 && ny < h && field[nx][ny] == c){
			field[nx][ny] = 0;
			dfs(nx,ny,c);
		}
	}
}

int main(){
	while(1){
		flag = false;
		cin >> w >> h;
		if(!w) break;
		for(int i = 0;i < w;i++){
			for(int j = 0;j < h;j++) field[i][j] = 0;
		}
		cin >> xs >> ys >> xg >> yg >> n; xs--;ys--;xg--;yg--;
		for(int i = 0;i < n;i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			if(d == 1){
				for(int k = 0;k < 2;k++){
					for(int j = 0;j < 4;j++) field[x + k - 1][y + j - 1] = c;
				}
			}else{
				for(int k = 0;k < 4;k++){
					for(int j = 0;j < 2;j++) field[x + k - 1][y + j - 1] = c;
				}
			}
		}
		if(field[xs][ys] == 0){
			cout << "NG" << endl;
			continue;
		}
		cc = field[xs][ys];
		field[xs][ys] = 0;
		dfs(xs,ys,cc);
		if(flag) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;++i) cin >> h[i];
    for(int i=n-1;i>0;--i)
        if(h[i]>=h[i-1]) continue; 
        else if(h[i-1]-h[i]==1) --h[i-1];
        else{
            cout << "No" << endl;
            return 0;
        }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
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>;

int power(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
int mx[1000005];
int fr[1000005];
int mod=1e9+7;
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
   {
      cin>>a[i];
   }   
   for(int i=0;i<n;i++)
   {
      int kk=a[i];
      map<int,int>mm;
      for(int j=2;j*j<=kk;j++)
      {
         while(kk%j==0)
         {
            mm[j]++;
            kk/=j;
         }
      }
      if(kk!=1)
         mm[kk]++;
      for(auto j:mm)
      {
         mx[j.first]=max(mx[j.first],j.second);
      }
   }
   int aa=1;
   for(int i=2;i<=1e6;i++)
   {
      if(mx[i])
      {
         int zz=power(i,mx[i],mod);
         aa=(aa*zz)%mod;
      }
   }
   // cout<<aa<<'\n';
   int tt=0;
   for(int i=0;i<n;i++)
   {
      int zz=power(a[i],mod-2,mod);
      tt=(tt+zz)%mod;
   }
   cout<<(aa*tt)%mod;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int countinv(vector<ll> arr){
   int n=arr.size();
   int cc=0;
   for(int i=0;i<n;i++){
   for(int j=i+1;j<n;j++){
      if(arr[j]<arr[i])cc++;
   }
  } 
  return cc;
}

ll fastexp(ll a,ll n){
   ll ans=1;
   while(n){
      if(n&1)
      ans*=a;
      ans%=mod;
      a*=a;
      a%=mod;
      n>>=1;
   }
   return ans;
}

ll inv(ll a){
   return fastexp(a,mod-2);
}


int main() {
  // FILE;
  SPEED;
  ll n,k;
  cin>>n>>k;

  vector<ll> arr(n);

  fain(arr);

  ll a1 = countinv(arr);
  // bugv(a1);
  sort(all(arr));
  ll pp=0;
  for(int i=0;i<n;i++){
     auto ix = lower_bound(all(arr),arr[i]);
     pp+=ix-arr.begin();
  }
  ll hj  = (((((pp*(k-1))%mod)*k)%mod)*inv(2))%mod;
  a1 = ((a1%mod)*(k%mod))%mod;
  hj = (hj%mod+a1%mod)%mod;

  cout<<hj;



}

Measured memory_bytes: 256
# DP(貰うDP)
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i))
print(dp[N - 1])


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

#define endl            "\n"
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vll             vector<ll>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define vpll            vector<pair<ll,ll>>
#define mpll            map<pair<ll,ll>,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define fr(a,b,c)       for(auto a=b;a<c;a++)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define pb(x)           push_back(x)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100005
template<typename T>
void output_vector(const vector<T> &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}


void solve(){
    int n;cin>>n;int a[n+1];
    fr(i,1,n+1)cin>>a[i];
    int dp[n+1]={0};
    dp[n-1]=abs(a[n-1]-a[n]);
    for(int i=n-2;i>=1;i--){
        int x1=abs(a[i]-a[i+1])+dp[i+1];
        int x2=abs(a[i]-a[i+2])+dp[i+2];
        dp[i]=min(x1,x2);
    }
    out1(dp[1]);
}

int main()
{   
    // #ifndef ONLINE_JUDGE 
    //     freopen("input.txt", "r", stdin); 
    //     freopen("output.txt", "w", stdout); 
    // #endif 
    // FIO;
    // ll test;cin>>test;
    // while(test--)
    solve();
    return 0;
}


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

using namespace std;
using ll = long long;

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

    ll a;
    string b;

    cin >> a >> b;

    int b100 = 10 * (int) (b.at(b.size() - 2) - '0') + (int) (b.at(b.size() - 1) - '0');
    b.pop_back();
    b.pop_back();
    b.pop_back();
    b100 += atoi(b.c_str()) * 100;

    printf("%lld\n", static_cast<ll>(a * b100) / 100);

    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3);
    for(int i = 0; i < 3; i++)
    cin >> a[i];
    int cnt = 0;
    if(a[0] == a[1] && a[1] == a[2]){
        cout << 0 << endl;
        return 0;
    }
    while(a[0] != a[1] || a[0] != a[2] || a[1] != a[2]){
        int odd = 0, even = 0;
        if(a[0] % 2 != a[1] % 2 || a[1] % 2 != a[2] % 2){
        for(int i = 0; i < 3; i++){
            a[i] % 2 == 0 ? even++: odd++;
        }
        if(even > odd){
            for(int i = 0; i < 3; i++){
                if(a[i] % 2 == 0)
                   a[i]++;
            }
        }
        else
        {
            for(int i = 0; i < 3; i++){
                if(a[i] % 2 != 0)
                a[i]++;
            }
        }
        
        cnt++;
    }
    if(a[0] % 2 == a[1] % 2 && a[1] % 2 == a[2] % 2){
        sort(a.begin(), a.end());
        cnt += (a[2] - a[1]) / 2 + (a[2] - a[0]) / 2;
        cout << cnt << endl;
        return 0;
    }
    }

}

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;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define mod 1000000007
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

signed main()
{
    fast

    int n;
    cin>>n;

    cout<<(1000-(n%1000))%1000;
}

Measured memory_bytes: 3652
from collections import deque
o = deque(input())
e = deque(input())

output = []

while len(o) >0 and len(e) >0:
  output.append(o.popleft())
  output.append(e.popleft())

if len(o) !=0:
  output.append(o.popleft())
elif len(e) !=0:
  output.append(e.popleft())
else:
  pass

print("".join(output))




Measured memory_bytes: 3316
table={}
def memorize(f):
    global table
    def func(*args):
        if not args in table:
            table[args]=f(*args)
        return table[args]
    return func
@memorize
def dfs(i,step,remain):
    if remain<0 or step<0 or i<-1:return 0
    if remain==0 and step==0:return 1
    return dfs(i-1,step-1,remain-i)+dfs(i-1,step,remain)
while True:
    n,s=map(int,raw_input().split())
    if(n==0 and s==0):break
    print dfs(9,n,s)
    

Measured memory_bytes: 5736
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 200001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};
vector<int> divisor(int n){
    vector<int> res;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i) res.push_back(n/i);
        }
    }
    return res;
}
int prime[N];bool isprime[N];
int sieve(int n){
    int p=0;
    for(int i=0;i<=n;i++){
        isprime[i]=true;
    }
    isprime[0]=isprime[1]=false;
    rep2(i,2,n){
        if(isprime[i]){
            prime[p++]=i;
            for(int j=i*2;j<=n;j+=i)isprime[j]=false;
        }
    }
    return p;
}
main(){
    int n=in();
    sieve(100);
    vec d;
    rep(i,25){
        d.pb(prime[i]);
    }
    sort(ALL(d));
    int m[200]={};
    rep(i,d.size()){
        int res=0;
        rep2(j,1,n){
            int t=j;
            while(t){
                if(t%d[i]==0){
                    res++;
                }
                else break;
                t/=d[i];
            }
        }
        m[i]=res;
    }
    int ans=0;
    rep(i,d.size()){
        rep(j,d.size()){
            rep(k,d.size()){
                if(i==j||j==k||i==k){
                    continue;
                }
                if(m[i]>=2&&m[j]>=4&&m[k]>=4)ans++;
            }
        }
    }
    ans/=2;
    rep(i,d.size()){
        rep2(j,i+1,d.size()-1){
                if(m[i]>=14&&m[j]>=4)ans++;
                if(m[i]>=2&&m[j]>=24)ans++;
                if(m[i]>=4&&m[j]>=14)ans++;
                if(m[i]>=24&&m[j]>=2)ans++;
        }
    }
    rep(i,d.size()){
                if(m[i]>=74)ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T = char, typename U = string>
vector<pair<T, int> > rle(const U &s) {
  int n = s.size();
  vector<pair<T, int> > res;
  T now = s[0];
  int cnt = 1;
  FOR(i, 1, n) {
    if (s[i] != now) {
      res.emplace_back(now, cnt);
      cnt = 0;
    }
    now = s[i];
    ++cnt;
  }
  res.emplace_back(now, cnt);
  return res;
}

int main() {
  string s; cin >> s;
  cout << rle<>(s).size() - 1 << '\n';
  return 0;
}


Measured memory_bytes: 1480
import math

N, D = list(map(int, input().split(' ')))
#print(N, D)

X = []
for i in range(N):
    X.append(list(map(int, input().split(' '))))
#print(X)

count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        norm = 0
        for k in range(D):
            norm += (X[i][k] - X[j][k]) ** 2
        norm = math.sqrt(norm)

        if norm == int(norm):
            count += 1
print(count)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>
#include <set>
#include <boost/lexical_cast.hpp>

using namespace std;


using ULL = decltype(0ull);
constexpr auto DIV = 1000000007ull;
constexpr auto MAX = numeric_limits<ULL>::max();

int dp[1000000 + 5];

int main() {
  string str;
  ULL p = 0, g = 1;
  cin >> str;
  if (str.front() == 'g') {
    dp[0] = 0;
  }
  else {
    dp[1] = -1;
  }
  for (int i = 1; i < str.size(); ++i) {
    if (p == g) {
      if (str[i] == 'p') {
        dp[i] = dp[i - 1] - 1;
      }
      else {
        dp[i] = dp[i - 1];
      }
      ++g;
    }
    else {
      if (str[i] == 'g') {
        dp[i] = dp[i - 1] + 1;
      }
      else {
        dp[i] = dp[i - 1];
      }
      ++p;
    }
  }
  cout << dp[str.size() - 1] << endl;
  return 0;
}


Measured memory_bytes: 896
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = str(input())
f = [0] * n
point = []
 
for i in range(n):
    if t[i] == "r":
        point.append(p)
    elif t[i] == "s":
        point.append(r)
    else:
        point.append(s)
 
for i in range(k, n):
    if t[i-k] == t[i] and f[i-k] == 0:
        point[i] = 0
        f[i] = 1
 
print(sum(point))

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  long long int A, B, C, K, M;
  
  M = 0;
  
  cin >> A >> B >> C >> K;
  
  if(A <= K){
    K -= A;
    
    M += A;
    
    if(B <= K){
      K -= B;
      
      if(C == K){
        M -= C;
      }else{
        M -= K;
      }
    }
  }else{
    M += K;
  }
  
  cout << M << endl;
  
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
    string s;
    cin >> s;
    if(s.size()%2){
        cout << "No" << endl;
        return 0;
    }
    fr(i,s.size()){
        if(s[i] == 'h'){
            if(s[++i] == 'i'){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 998244353;
const int N = 100000 + 7;

int main()
{
    vector<string>w={"Cloudy", "Rainy", "Sunny"};
    string s;
    cin>>s;
    for(int i=0;i<100;i++)
    {
        if(s==w[i%3])
        {
            cout<<w[(i+1)%3]<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"reflect"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	sorted := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}
	copy(sorted, p)
	sort.Sort(sort.IntSlice(sorted))
	ans := false
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i > j {
				continue
			}
			t := make([]int, n)
			copy(t, p)
			sort.IntSlice(t).Swap(i, j)
			if reflect.DeepEqual(sorted, t) {
				ans = true
				break
			}
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
//debug
#define vecprint(v) rep(i,v.size())cout << v[i] << " ";cout << endl;
#define setprint(s) for(auto i=s.begin();i!=s.end();i++)cout << *i << " ";cout << endl;
#define mappairprint(s) for(auto i=s.begin();i!=s.end();i++)cout << i->first << " " << i->second << endl;cout << endl;
//variable definition
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
//loop
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define all(c) c.begin(),c.end()
//term
#define elif else if
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
using namespace std;
using ll = long long;
//const
constexpr double PI = 3.141592653589793238462643383279;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};


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

  //process
  ll e,f,g,h;
  e = a * c;
  f = a * d;
  g = b * c;
  h = b * d;
  
  ll max = e;
  if (max < f) max = f;
  if (max < g) max = g;
  if (max < h) max = h;
  
  //output
  cout << max << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n;
    cin>>n;
    ll cnt=0;
    while(cnt*1000<n) cnt++;
    cout<<(cnt*1000)-n<<endl;
    return 0;
}


Measured memory_bytes: 3640
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord




r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main :: IO ()
main = do
    [h,w] <- r'

    hori <- replicateM h C.getLine :: IO [C.ByteString]
    let vert = C.transpose hori :: [C.ByteString]

    let numH = map transform hori :: [U.Vector Int]
    let numV = transposeV $ map transform vert

    let sumSq = zipWith (U.zipWith (+)) numH numV

    print $ pred $ maximum $ map U.maximum sumSq

transform :: C.ByteString -> U.Vector Int
transform = U.concat . map transformG . C.group

transformG bs = case C.head bs of '.' -> U.replicate (C.length bs) (C.length bs)
                                  '#' -> U.replicate (C.length bs) 0


transposeV :: U.Unbox a => [U.Vector a] -> [U.Vector a]
transposeV xs = (U.fromList (map U.head xs)) :(transposeV (map U.tail xs))



Measured memory_bytes: 87420
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n = in();
    int m = in();
    if (n == 0 && m == 0) break;
    auto h = in(vector<int>(n));
    auto w = in(vector<int>(m));
    vector<int> l1(1500 * 1000 + 1), l2(1500 * 1000 + 1);
    rep(i, n) {
      int s = 0;
      loop(j, i, n) {
        s += h[j];
        l1[s]++;
      }
    }
    rep(i, m) {
      int s = 0;
      loop(j, i, m) {
        s += w[j];
        l2[s]++;
      }
    }
    int c = 0;
    for (int i = 1; i <= n * 1000; i++) c += l1[i] * l2[i];
    cout << c << endl;
  }
}



Measured memory_bytes: 26276
#include<iostream>
#include<queue>
#include<cstdio>

using namespace std;

const int MAX = 1000001;
int S[MAX];

struct data{
  int num,score;
  data(){}
  data(int n, int s):num(n),score(s){}
  bool operator < (const data& d) const {
    if(score != d.score) return score < d.score;
    return num > d.num;
  }
};

int main(){

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

  priority_queue<data> Q;
  Q.push(data(0,0));

  while(m--){
    int a,b;
    scanf("%d %d",&a,&b);
    S[a] += b;
    
    Q.push(data(a,S[a]));

    while(1){
      data now = Q.top();
      if(now.score == S[now.num]){
	cout << now.num << " " << now.score << endl;
	break;
      } 
      Q.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 6020
n, m = [int(i) for i in input().split(" ")]

pre_res = [0 for i in range(m)]

for i in range(n):
    sel = [int(i)-1 for i in input().split(" ")][1:]
    for s in sel:
        pre_res[s] += 1

res = 0
for i in range(m):
    if pre_res[i] == n:
        res += 1

print(res)


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    int n; cin >> n;
    V<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll ans = 0;
    for(int i = 1; i < n; i++){
        if(a[i - 1] > a[i]) {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << ans << endl;


    return 0;
}


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


using namespace std;

main(){

    set < int > st;
    for(int i = 0 ; i < 3 ; i ++){
        int x;
        scanf("%d" , &x);
        st.insert(x);
    }

    printf("%d\n" , st.size());

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, dead_code, non_snake_case)]

use std::io::*;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::str::FromStr;

const MOD: i32 = 1_000_000_007;

macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);
    let mut v = Vec::new();
    let mut sum = 0;
    for _ in 0..N {
        let tmp = get!(usize);
        v.push(tmp);
        sum += tmp;
    }
    v.sort();
    if sum % 10 == 0 {
        for i in 0..v.len() {
            if (sum - v[i]) % 10 == 0 {
                continue;
            }
            println!("{}", sum - v[i]);
            return;
        }
    } else {
        println!("{}", sum);
        return;
    }
    println!("{}", 0);
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long K = p[0];
            long X = p[1];
            long left = X - (K - 1);
            long right = X + (K - 1);

            long ans = left;
            while (ans <= right)
            {
                Console.Write($"{ans} ");
                ans++;
            }

            Console.Out.Flush();
        }
    }



    public class Calculation
    {
        
    }

    public class Graph
    {
        
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
#include<type_traits>
#include<numeric>
#include<array>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}

int main(){

    string s;cin >> s;

    int count = 0;
    REP(i,s.size()) {
        if(s[i]=='x') count++;
    }

    YES(count <= 7)

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ((a + b) > (c + d)) cout << "Left";
  else if ((a + b) == (c + d)) cout << "Balanced";
  else cout << "Right" << endl;
}

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

int boal[10];

bool dfs(int b,int c, int time)
{
	if(time >= 10)
		return true;
	
	if(boal[time] > b && dfs(boal[time], c, time + 1))
		return true;
	
	if(boal[time] > c && dfs(b, boal[time], time + 1))
		return true;
	
	return false;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	while(n > 0){
		for(int i = 0; i != 10; ++i)
			cin >> boal[i];
		
		if(dfs(0, 0, 0))
			cout << "YES";
		else
			cout << "NO";
		cout << endl;
		
		n--;
	}
	return 0;
}

Measured memory_bytes: 1184
#素因数分解、計算量はO(√N)
from collections import defaultdict
def factorize(n):
  b = 2
  dic = defaultdict(lambda: 0)
  while b * b <= n:
    while n % b == 0:
      n //= b
      dic[b] += 1
    b = b + 1
  if n > 1:
    dic[n] += 1
  return dic

def extgcd(a, b):
  if b:
    d, y, x = extgcd(b, a%b)
    y -= (a//b)*x
    return d, x, y
  else:
    return a, 1, 0
N = int(input())
fct = factorize(2*N)
lis = []
for k,v in fct.items():
  lis.append(pow(k,v))
ans = 10**18
from itertools import groupby, accumulate, product, permutations, combinations
for pro in product([0,1],repeat=len(lis)):
  prod1 = 1
  for i,p in enumerate(pro):
    if p==1:
      prod1 *= lis[i]
  prod2 = (N*2)//prod1
  if min(prod1,prod2)==1:
    ans = min(ans, max(prod1,prod2)-1)
  else:
    d,a1,a2 = extgcd(prod1,prod2)
    ans = min(ans, min(abs(a1*prod1),abs(a2*prod2)))
print(ans)


Measured memory_bytes: 71064
#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;
typedef pair<ll, ll> P;

const ll INF = 1LL << 60;

ll N, M;

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

    vector<ll> v[M];
    rep(i, N) {
        ll A, B;
        cin >> A >> B;
        if (A > M) continue; 

        // 何日めまでにやらないといけないか
        v[M - A].push_back(B);
    }

    priority_queue<ll> que;

    ll ans = 0;

    // 何日めか
    for (int i = M - 1; i >= 0; i--) {
        for (auto b : v[i]) {
            que.push(b);
        }

        if (!que.empty()) {
            ll s = que.top();
            que.pop();

            ans += s;
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 8840
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)

const long double PI = acos(-1);
const int INF = 1 << 60;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}

int N,M; vector<vector<int>> G;
int dp[100010];
int rec(int v){
    if(dp[v] != -1) return dp[v];
    int res = 0;
    for(auto nv : G[v]){
        chmax(res,rec(nv)+1);
    }
    return dp[v] = res;
}

int main(){
    cin >> N >> M;
    G.assign(N,vector<int>());
    for(int i = 0; i < M; i++){
        int x,y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }

    for(int v = 0; v < N; v++) dp[v] = -1;
    int res = 0;
    for(int v = 0; v < N; v++) chmax(res,rec(v));
    cout << res << endl;
}




Measured memory_bytes: 8192
#include<stdio.h>

int main(void)
{
  long long min=10000;
  long long l,r;
  scanf("%lld %lld",&l,&r);


  for(long long i=l;i<r;i++){
    for(long long j=l+1;j<=r;j++){

      if((i*j)%2019<min&&i<j){
        min=(i*j)%2019;
        if(min==0){
          puts("0");
          return 0;
        }
      }
    }
  }

  printf("%lld\n",min);
  return 0;
}


Measured memory_bytes: 128
n,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

rev=[None]*(n+1)
norm=[None]*(n+1)
revmax=[None]*(n+1)

rev[0]=(0,0)
revmax[0]=(0,0)
norm[0]=(0,0)
ans=0

# normal rotation
for i in range(1,n+1):
    x,v=l[i-1]
    norm[i]=(x,v+norm[i-1][1])

# reverse rotation
for i in range(1,n+1):
    x,v=l[-i]
    rev[-i]=(c-x,v+rev[-i+1][1])

for i in range(1,n+1):
    revmax[-i]=(max(revmax[-i+1][0],rev[-i][1]-2*rev[-i][0]),max(revmax[-i+1][1],rev[-i][1]-rev[-i][0]))

for i in range(n+1):
    v1=norm[i][1]-norm[i][0]+revmax[i-n][0]
    v2=norm[i][1]-2*norm[i][0]+revmax[i-n][1]
    ans=max(ans,v1,v2)

print(ans)

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

int main(){
    long long N;
    cin >> N;
    long long ans=0;
    for(long long i=1;i<=N;i++){
        ans+=((N/i)*(2*i+(N/i-1)*i))/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;
using static System.Console;

class P
{
    static void Main()
    {
        while (true)
        {
            var a = ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToList();
            if (a[0] == 0 && a[1] == 0) break;
            WriteLine(string.Join(" ", a));
        }
    }
}


Measured memory_bytes: 16504
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
typedef long long LL;
const int N=2e5+10;
struct node{
	int cnt0,cnt1,id;
	inline bool operator <(node x)const{
		return 1ll*cnt0*x.cnt1<1ll*cnt1*x.cnt0;
	}
};
__gnu_pbds::priority_queue <node> q;
__gnu_pbds::priority_queue <node>::point_iterator it[N];
int n,p[N],v[N],fa[N],a[N],b[N];
inline int getf(int u){return fa[u]==u?u:fa[u]=getf(fa[u]);}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)fa[i]=i;
	for(int i=2; i<=n; ++i)scanf("%d",&p[i]);
	for(int i=1; i<=n; ++i)scanf("%d",&v[i]),a[i]=!v[i],b[i]=v[i],it[i]=q.push(node{!v[i],v[i],i});
	LL ans=0;
	while(!q.empty()){
		node x=q.top(); q.pop();
		int u=x.id; fa[u]=getf(p[u]);
		ans+=1ll*b[fa[u]]*a[u]; a[fa[u]]+=a[u]; b[fa[u]]+=b[u];
		if(fa[u])q.modify(it[fa[u]],{a[fa[u]],b[fa[u]],fa[u]});
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 15104
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<string> tmp(1000);
    int t=0;
    for(char c='0';c<='9';c++){
        for(char c1='0';c1<='9';c1++){
        for(char c2='0';c2<='9';c2++){
                  string tp;
                  tp+=c;
                  tp+=c1;
                  tp+=c2;
                  tmp[t++]=tp;
            }
        }
    }
    ll ans=0;
    for(int i=0;i<1000;i++){
        int cnt=0;
        for(int j=0;j<n+3;j++){
            if(s[j]==tmp[i][cnt])cnt++;
            if(cnt==3){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <limits>

int main()
{
	int N, K;
	std::cin >> N >> K;

	int num = 0;
	for (int i = 0; i < N; ++i)
	{
		int h;
		std::cin >> h;

		if (h >= K)
		{
			num++;
		}
	}

	std::cout << num;
	
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N, M; cin >> N >> M;
    int A[N], B[M];
    F0R(i, N) {
        cin >> A[i];
    }
    F0R(i, M) {
        cin >> B[i];
    }

    ll ans = 0;
    ll dp[N][M];
    ll pref[M+1];
    F0R(i, N) {
        F0R(j, M) {
            dp[i][j] = 0;
            pref[j] = 1;
        }
    }
    pref[M] =1;
    F0R(i, N) {
        F0Rd(j, M) {
            if (A[i] == B[j]) {
                dp[i][j] += pref[j];
                dp[i][j] = dp[i][j] % MOD;
            }
        }
        ll prefSum = 0;
        F0R(j, M+1) {
            pref[j] += prefSum;
            pref[j] = pref[j] % MOD;
            if (j < M) prefSum += dp[i][j];
            prefSum = prefSum % MOD;
        }
    }

    cout << pref[M];


    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

using namespace std;

int main()
{
    int n, m;

    cin >> n >> m;

    vector <int> h(n+1, 0);

    for (int i = 1; i <= n; i++)
        cin >> h[i];

    vector <int> mx(n+1, 0);

    for (int i = 1; i <= m; i++)
    {
        int a, b;

        cin >> a >> b;

        mx[a] = max(mx[a], h[b]);
        mx[b] = max(mx[b], h[a]);
    }

    int ans = 0;

    for (int i = 1; i <= n; i++)
    {
        if (h[i] > mx[i])
            ans++;
    }

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

Measured memory_bytes: 4052
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    buf.pop();
    let K = i64::from_str(&buf).unwrap();
    buf.clear();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let (A, B) = (it.next().unwrap(), it.next().unwrap());
    for i in A..(B+1) {
        if i % K == 0 {
            println!("OK");
            return ();
        }
    }
    println!("NG");
}


Measured memory_bytes: 2088
n = int(input())
min_b = float('inf')
sa = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a - b > 0:
        min_b = min(min_b, b)
    sa += a
if min_b == float('inf'):
    print(0)
else:
    print(sa - min_b)


Measured memory_bytes: 3060
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
const double PI=3.141592;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int mod = N % 10;
  if (mod == 3) {
    cout << "bon" << endl;
  } else if (mod == 0 || mod == 1 || mod == 6 || mod == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;

}


Measured memory_bytes: 3652