akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300005;

/* ...o(^-^)o... */

int main(){
    int n; cin>>n;
    vector<int> who(n*n);
    vector<vector<int> > when(n, vector<int>(n));
    
    rep(k, n*n){
        int p; cin>>p; p--;
        who[k] = p;
        when[p/n][p%n] = k;
    }

    vector<vector<int> > dist(n, vector<int>(n));
    rep(i, n) rep(j, n) dist[i][j] = min({i,j,n-i-1,n-j-1});

    int dx[4] = {0,0,1,-1};
    int dy[4] = {1,-1,0,0};
    int res = 0;
    rep(k,n*n){
        queue<int> que; que.push(who[k]);
        res += dist[who[k]/n][who[k]%n];
        while(!que.empty()){
            int q = que.front(); que.pop();
            int i = q/n, j = q%n;
            rep(l,4){
                int ii = i+dx[l], jj = j+dy[l];
                if(ii<0||ii>=n||jj<0||jj>=n) continue;
                int obs = (when[i][j] > k);
                if(dist[i][j]+obs < dist[ii][jj]){
                    dist[ii][jj] = dist[i][j]+obs;
                    que.push(ii*n+jj);
                }
            }
        }
    }
    out(res);
}

Measured memory_bytes: 6080
#include<stdio.h>

void trace(int A[],int N){
	int i;
	for(i=0;i<N;i++){
		if(i>0)
			printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}

void insertionSort(int A[],int N){
	int i,j,v;
	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0 && A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		trace(A,N);
	}
}

int main(){
	int i,j,N,A[100];
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);

	trace(A,N);
	insertionSort(A,N);

	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<cmath>
using namespace std;
bool EQ(double a,double b){
  return abs(a-b)<0.000000000001;
  //  return a-0.0000001<b&&b<a+0.0000001;
}
int main(){
  int n;
  double x[4],y[4];
  cin>>n;
  while(n--){
    for(int j=0;j<4;j++) cin>>x[j]>>y[j];
    if(EQ((y[3]-y[2])*(x[1]-x[0]),(y[1]-y[0])*(x[3]-x[2])))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...) 
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    map<pair<int, int>, ll> mp;
    for (int i = 0; i < n; i++) {
        double x;
        cin >> x;
        ll y = llround(x * 1e9);
        int cnt2 = 0, cnt5 = 0;
        while (y % 2 == 0)
            cnt2++, y /= 2;
        while (y % 5 == 0)
            cnt5++, y /= 5;
        for (const auto& p : mp)
            if (p.first.first + cnt2 >= 18 && p.first.second + cnt5 >= 18)
                ans += p.second;
        mp[{cnt2, cnt5}]++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3720
/*
      author  : nishi5451
      created : 15.08.2020 00:28:35
*/

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


int main(){
    int n;
    cin >> n;
    int ans = 0;
    int now = 0;
    rep(i,n){
        int h;
        cin >> h;
        if(h >= now) ans++;
        now = max(now,h);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3528
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
#define noop

int main() {

    get(n);

    vector<ll> A = {100,101,102,103,104,105};
    vector<char> dp(n+1,0);

    dp[0] = 1;
    rep2(i,1,7) {
        rep(j,n+1) {
            if(j-A[i-1]>=0)
                dp[j] = dp[j] | dp[j-A[i-1]];
        }
    }

    printf("%lld\n", dp[n] ? (ll)1 : (ll)0);


    return 0;  
}



Measured memory_bytes: 384
from collections import defaultdict as ddic, deque, Counter
from itertools import permutations, combinations, product
import bisect, heapq

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())
MOD = 10**9 + 7

def binom(n, k):
    numer = 1
    for i in xrange(1, n+1):
        numer *= i
        numer %= MOD
    denom = 1
    for i in xrange(1, k+1):
        denom *= i
        denom %= MOD
    denom2 = 1
    for i in xrange(1, n-k+1):
        denom2 *= i
        denom2 %= MOD
    ans = numer * pow(denom, MOD-2, MOD) % MOD
    ans *= pow(denom2, MOD-2, MOD)
    ans %= MOD
    return ans

def sumToN(N):
    return N*(N+1)/2

def flat(R, C):
    if C > R: R,C = C,R
    # R >= C
    # 0 1 2 3 4 5 6 7 8 [C=9]
    # 3 2 1 0 1 2 3 4 5
    ans = 0
    for c in xrange(C):
        left = c
        right = C - 1 - c
        base = sumToN(left) + sumToN(right)
        for r in xrange(R):
            up, down = r, R-1-r
            base2 = sumToN(up) + sumToN(down)
            ans += base * R + base2 * C
    ans /= 2
    return ans % MOD


def solve(R, C, K):
    N = R * C
    return flat(R, C) * binom(N - 2, K - 2) % MOD

print solve(*rrm())


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

typedef long long int ll;
typedef unsigned long long int ull;

#define REP(i, n) for (ll i = 0; i < n; i++)

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> b(n);
  REP(i, n)
  {
    cin >> b[i];
  }

  vector<int> ans(n);
  int j, m = n;
  REP(i, n)
  {
    j = m;
    while (true)
    {
      // cout << j << endl;

      if (j == 0)
      {
        cout << -1 << endl;
        return 0;
      }
      if (b[j - 1] == j)
      {
        b.erase(b.begin() + j - 1);
        m--;
        ans[i] = j;
        break;
      }
      j--;
    }
  }

  REP(i, n)
  {
    cout << ans[n - i - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
if b <= c or d <= a:
    print(0)
elif  a <= c:
    if b <= d:
        print(b - c)
    else:
        print(d - c)
else:
    if b <= d:
        print(b - a)
    else:
        print(d - a)

Measured memory_bytes: 9028
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
ll a[100005];

ll kilk(int l,int r)
{
          ll s1=0;
          for(int i=l;i<=r;i++)
                    s1+=a[i];
          return s1/2;
}

int main()
{
          cin>>n;
          for(int i=1;i<=n;i++)
                    cin>>a[i];
          a[n+1]=0;
          int pos1=1,pos2=1;
          ll s=0;
          for(int i=1;i<=n+1;i++)
          {
                    if(a[i]==0)
                    {
                              s+=kilk(pos1,pos2);
                              pos1=-1;
                              pos2=-1;
                              continue;
                    }
                    if(pos1==-1)
                    {
                              pos1=i;
                              pos2=i;
                    }
                    else
                    {
                              pos2++;
                    }
          }
          cout<<s;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            rui = new long[N + 1];
            for (var i = 0; i < N; ++i)
                rui[i + 1] = Ai[i] + rui[i];
            var min = long.MaxValue;
            for (var l = 2; l < N - 1; ++l)
                min = Min(min, Calc1(l,N));
            WriteLine(min);
        }
        static long[] rui;
        //[0,l)と[l,N)にわける
        static long Calc1(long l,long N)
        {
            var ll = binarysearch(0, l);
            var rr = binarysearch(l, N);

            var m1 = rui[ll + 1];
            var m2 = rui[l] - rui[ll + 1];
            var m4 = rui[ll + 2];
            var m3 = rui[l] - rui[ll + 2];
            var l1 = m3;
            var l2 = m4;
            if (Abs(m1 - m2) < Abs(m3 - m4))
            {
                l1 = m1;
                l2 = m2;
            }

            var m5 = rui[rr + 1] - rui[l];
            var m6 = rui[N] - rui[rr + 1];
            var m7 = rui[rr + 2] - rui[l];
            var m8 = rui[N] - rui[rr + 2];
            var r1 = m7;
            var r2 = m8;
            if (Abs(m5 - m6) < Abs(m7 - m8))
            {
                r1 = m5;
                r2 = m6;
            }
            var max = Max(Max(r1, r2), Max(l1, l2));
            var min = Min(Min(r1, r2), Min(l1, l2));

            return Abs(max - min);
        }
        //[l,r)間で<sum/2となるところを探す
        static long binarysearch(long l, long r)
        {
            var s = l;
            var J = (rui[r] - rui[s]) / 2;
            while (1 < r - l)
            {
                var mid = l + (r - l) / 2;
                if (rui[mid + 1] - rui[s] < J)
                    l = mid;
                else
                    r = mid;
            }
            return l;
        }
    }
}

Measured memory_bytes: 45428
#include<cstdio>
#include<algorithm>
using namespace std;
int n, L, cnt, CK[301000], Res = 1e9, Sum[301000];
long long S;
struct point {
	int x, t;
}w[301000];
int Get(int c1) {
	int s = 0, c = 0, i;
	c = 0;
	for (i = 1; i <= n; i++) {
		int ck = CK[i];
		if (ck==3) {
			if (c1)c1--, ck = 1;
			else ck = 2;
		}
		if (ck != 2) {
			c += 2;
			s += 2;
		}
		if (ck != 1) {
			if (c >= 3) {
				c -= 2;
				s--;
			}
			else if (c) {
				c--;
			}
			else {
				s++;
			}
		}
	}
	while (c >= 3) {
		c -= 2;
		s--;
	}
	return s;
}
int main() {
	int i, j, c = 0;
	scanf("%d%d", &n, &L);
	for (i = 1; i <= n; i++) scanf("%d", &w[i].x);
	for (i = 1; i <= n; i++) scanf("%d", &w[i].t);
	for (i = 1; i <= n; i++) {
		int tt = (w[i].t-1) / (2 * L) * (2 * L);
		S += tt;
		w[i].t -= tt;
		int ck = 0;
		if (w[i].t <= w[i].x * 2)ck |= 1;
		if (w[i].t <= (L - w[i].x) * 2)ck |= 2;
		CK[i] = ck;
		if (CK[i] == 3)cnt++;
	}
	int b = 0, e = cnt-1, r = 0, mid;
	while (b <= e) {
		mid = (b + e) >> 1;
		if (Get(mid) > Get(mid + 1)) {
			r = mid + 1;
			b = mid + 1;
		}
		else e = mid - 1;
	}
	printf("%lld\n", Get(r) * 2ll * L + S);
}

Measured memory_bytes: 4864
#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 fac[1000005];
int mod=1e9+7;
int ncr(int n,int r)
{
   int z=fac[n];
   z=(z*power(fac[r],mod-2,mod))%mod;
   z=(z*power(fac[n-r],mod-2,mod))%mod;
   return z;
}
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif

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

   fac[0]=1;
   for(int i=1;i<=1000000;i++)
      fac[i]=(fac[i-1]*i)%mod;
   
   int n,k;
   cin>>n>>k;
   if(k==1)
   {
      cout<<(n*(n-1))%mod;
   }
   else if(n>k)
   {
      int ans=0;
      for(int i=k;i>=0;i--)
      {
         ans=(ans+((ncr(n,k))*(ncr(n-1,k)))%mod)%mod;
         k--;
      }
      cout<<ans;
   }
   else
   {
      int ans=(ncr(2*n-1,n-1))%mod;
      cout<<ans;
   }
   

// -------------------------------------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: 8064
# ABC167d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    pos = [-1] * n
    pos[0] = 0

    nex = a[0] - 1
    now = 0
    turn = 0

    mode = False

    while True:
        if not mode and pos[nex] == -1:
            if turn == k:
                print(now+1)
                exit(0)
            pos[nex] = pos[now] + 1
            now = nex
            nex = a[nex] - 1
            turn += 1
            continue
        if mode:
            if turn == k:
                print(now+1)
                exit(0)
            pos[nex] = pos[now] + 1
            now = nex
            nex = a[nex] - 1
            turn += 1
            continue
        circle = turn - pos[nex] + 1
        turn += (k-turn) // circle * circle
        mode = True

    # print(pos)


if __name__ == '__main__':
    main()


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

using namespace std;

long long attacks(long long H) {
	long long m = 1;
	while (H) {
		H /= 2;
		m *= 2;
	}
	return m - 1;
}

int main() {
	long long H;
	cin >> H;
	cout << attacks(H);
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(N - 1 + M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)


def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)

    for i in range(len(g)):
        if i not in visited:
            dfs(i)

    return topological_list[::-1]


topological_order = topological_sort(G)


# 根からの最長経路を計算
dist = [-float('inf')] * N
dist[topological_order[0]] = 0
for n in topological_order:
    for to in G[n]:
        dist[to] = max(dist[to], dist[n] + 1)


node_depth = sorted(list(enumerate(dist)), key=lambda x: x[1])
ans = [[node_depth[0][0], -1]]
for n, depth in node_depth:
    for to in G[n]:
        if dist[to] == depth + 1:
            ans.append([to, n])

ans.sort()
for i, p in ans:
    print(p + 1)


Measured memory_bytes: 90800
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;

#define MOD 1000000007

ll N;
vector<vector<ll> > dsts;

vll bfs(ll sv) {
  vll dist(N + 1, -1), pre(N + 1);

  queue<ll> que;
  que.push(sv);
  // dist[sv] = 0;
  ll mind = 2000, mind_u = -1;
  while (!que.empty()) {
    ll vtmp = que.front();
    que.pop();
    for (auto u : dsts[vtmp]) {
      if (u == sv) {
        mind = min(mind, dist[vtmp]);
        mind_u = vtmp;
        continue;
      }
      if (dist[u] != -1) continue;
      pre[u] = vtmp;
      dist[u] = dist[vtmp] + 1;
      que.push(u);
    }  // u
  }    // while

  if (mind_u == -1) return vll(N + 1);
  vll ans;
  ll vtmp_ans = mind_u;
  while (vtmp_ans != sv) {
    ans.push_back(vtmp_ans);
    vtmp_ans = pre[vtmp_ans];
  }
  ans.push_back(sv);
  return ans;
}

int main() {
  ll M;

  cin >> N >> M;

  dsts.assign(N + 1, vll(0));

  for (int i = 0; i < M; i++) {
    ll src, dst;
    cin >> src >> dst;
    dsts[src].emplace_back(dst);
  }

  vll ans(N+1);
  for (int i = 1; i <= N; i++) {
    vll tmp = bfs(i);
    if (tmp.size() <= (unsigned long long)N) {
      if(tmp.size() <= ans.size()){
        ans = tmp;
      }
    }
  }  // i


  if(ans.size() != (size_t)N+1){
      cout << ans.size() << endl;
      for (size_t i = 0; i < ans.size(); i++) {
        cout << ans[ans.size()-1-i] << endl;
      }  // v
      return 0;  
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	if (n == 1){
		printf("Hello World\n");
		return 0;
	}
	else {
		scanf("%d %d", &x, &y);
		ans = x + y;
		printf("%d\n", ans);
		return 0;
	}


	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
main()
{
	int a,b,sum;
	scanf("%d %d",&a,&b);
	sum = a+b;
	if(sum>=10)
	{
		printf("error\n");
	}
	else 
	{
		printf("%d\n",sum);
	}
	return 0;
}

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

int main() {
  int a,b;cin>>a>>b;
  if(a < 9 && b < 9) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Applicative
import           Text.Printf

main :: IO ()
main = solve 1

solve :: Int -> IO ()
solve count = do
  x :: Int <- readLn
  if x == 0
    then pure ()
    else do
    printf "Case %d: %d\n" count x
    solve (count+1)




Measured memory_bytes: 4184
N, K = map(int, input().split())

MOD = 10 ** 9 + 7

cache = {}
def f(k, n):
    if k == 1:
        return 1
    if k in cache:
        return cache[k]
    result = pow(k, n, MOD)
    for i in range(2, k + 1):
        result -= f(k // i, n)
        result %= MOD
    cache[k] = result
    return result

result = 0
for i in range(2, K + 1):
    result += f(K // i, N) * i
result += f(K, N)
result %= MOD
print(result)


Measured memory_bytes: 9220
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

int a[100010];

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

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

    ll cnt=0;
    for (int i = 0; i < n-1; i++) {
        int sum=a[i]+a[i+1];
        if(sum>x){
            int need=sum-x;
            if(a[i+1]<need){
                cnt+=(ll)need;
                a[i]-=need-a[i+1];
                a[i+1]=0;
            }else {
                cnt+=(ll)need;
                a[i+1]-=need;
            }
        }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int32_t main()
{
	BOOST
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
	cout << "OUTPUT \n";
#endif
	int t; //cin >> t;
	t = 1;
	while (t--)
	{
		string s;
		cin >> s;
		int n = s.length();
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			sum += (s[i] - '0');
		}
		if (sum % 9 == 0)
		{
			cout << "Yes" << "\n";
		}
		else
		{
			cout << "No" << "\n";
		}
	}
	return 0;

}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef pair<ll, ll> P;

struct edge{
    ll to, cost;
    edge(){}
    edge(ll to, ll cost) : to(to), cost(cost) {};
};
using Graph = vector<vector<edge>>;

// 使われる辺の集合
set<pair<int,int>> use;

vector<ll> dijkstra(const Graph &G, int s) {
    int N = G.size();
    vector<ll> dist(N, INF);
    // prev[v] : = vから復元できる辺
    vector<vector<int>> prev((int)G.size());
    // 「仮の最短距離, 頂点」が小さい順に並ぶ 
    priority_queue<P, vector<P>, greater<P>> pq;  
    dist[s] = 0LL;
    pq.emplace(dist[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        ll v = p.second;
        // 最短距離でなければ対象外
        if (dist[v] < p.first) { 
            continue;
        }
        for (auto &e : G[v]) {
            // 最短距離候補なら priority_queue に追加
            if (dist[e.to] > dist[v] + e.cost) {  
                dist[e.to] = dist[v] + e.cost;
                pq.emplace(dist[e.to], e.to);

                // 復元用
                prev[e.to].clear();
                prev[e.to].push_back(v);
            }
            else if (dist[e.to] == dist[v] + e.cost){
                prev[e.to].push_back(v);
            }
        }
    }

    for(int v = 0; v < G.size(); v++){
        for( auto u : prev[v]){
            // pair.firstに頂点番号の小さな方、secondに大きな方を格納
            use.insert(make_pair(min(u,v), max(u,v)));
        }
    }
    return dist;
}


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

    Graph G(N);
    rep(i,M){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
    }
    // 全頂点でダイクストラを実施
    rep(i,N) dijkstra(G, i);

    cout << M - (int)use.size() << endl;
}

Measured memory_bytes: 3664
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def primeFactorization(n):
    ans = []
    temp = n
    while temp%2 == 0:
        ans.append(2)
        temp //= 2
    for i in range(3, int(n**0.5)+1, 2):
        while temp%i == 0:
            ans.append(i)
            temp //= i
    if temp > 1:
        ans.append(temp)
    return collections.Counter(ans)

def combMod(n, r, p):
    numer = 1
    denom = 1
    for i in range(1, r+1):
        numer = numer * (n-r+i) % p
        denom = denom * i % p
    return numer * pow(denom, p-2, p) % p

def resolve():
    N, M = LI()

    pf = primeFactorization(M)
    # 素因数ごとに、N個のグループにどう振り分けるかを計算する
    ans = 1
    for i in pf.values():
        ans *= combMod(i + N - 1, i, MOD)        
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10280
#include<bits/stdc++.h>
using namespace std;
const int maxN = 100200;
int mem[maxN];
int nums[maxN];
int solve(int i,int n,int k){
	if(i == n - 1){
		return 0;
	}
	if(mem[i] != -1){
		return mem[i];
	}
	int res = 2000000000;
	for(int j = i + 1; j <= i + k; j++){
		if(j < n){
			res = min(res,abs(nums[i] - nums[j]) + solve(j,n,k));
		}
	}
	return mem[i] = res;
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    for(int i = 0;i < n ;i++){
		cin >> nums[i];
	}
	memset(mem,-1,sizeof(mem));
    cout << solve(0,n,k) << "\n";
}


Measured memory_bytes: 12192
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>

using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100000 + 7;
typedef unsigned long long ull;

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
}

/*                What if i lose? only losers think like that. But the answer is you will lose rate.                */

int x;

int main() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
    fast();

    cin>>x;
    cout<<x+x*x+x*x*x<<endl;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
void _fast () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); }
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return 1; } return 0; }

int main() { _fast();
	int x, y;
	cin >> x >> y;
	bool ok = false;
	for (int a = 0; a <= x; a++) {
		int val = a * 2 + (x - a) * 4;
		ok |= (val == y);
	}
	
	cout << (ok ? "Yes" : "No") << '\n';
	
	return 0;
}

Measured memory_bytes: 3636
s = input()
correct_list = ["A","C","G","T"]
x_list = [-1]

for i, c in enumerate(s):
    if c not in correct_list:
        x_list.append(i)
x_list.append(len(s))
diff_list = []
for i in range(len(x_list)-1):
    diff_list.append(x_list[i+1]-x_list[i])
print(max(diff_list)-1)


Measured memory_bytes: 3060
#include <iostream>
#include <stack>
#include <sstream>
#include <cstdlib>
using namespace std;

int main() {
  stack<double> st;
  string line,str;
  double num1,num2;
  while(getline(cin,line)) {
    stringstream ss(line);
    while(ss >> str) {
      if(str == "+") {
        num2 = st.top();
        st.pop();
        num1 = st.top();
        st.pop();
        st.push(num1+num2);
      }
      else if(str == "-") {
        num2 = st.top();
        st.pop();
        num1 = st.top();
        st.pop();
        st.push(num1-num2);
      }
      else if(str == "*") {
        num2 = st.top();
        st.pop();
        num1 = st.top();
        st.pop();
        st.push(num1*num2);
      }
      else if(str == "/") {
        num2 = st.top();
        st.pop();
        num1 = st.top();
        st.pop();
        st.push(num1/num2);
      }
      else {
        st.push(atoi(str.c_str()));
      }
    }
    printf("%.6lf\n",st.top());
  }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var S = Console.ReadLine();

        if (S.First() == 'W' || S.Last() == 'W')
        {
            Console.WriteLine(0);
            return;
        }

        var isLeft = new bool[S.Length];
        isLeft[0] = true;
        for (int i = 1; i < S.Length; i++)
        {
            if (S[i] == S[i - 1])
            {
                isLeft[i] = !isLeft[i - 1];
            }
            else
            {
                isLeft[i] = isLeft[i - 1];
            }
        }

        if (isLeft.Count(b => b) != N)
        {
            Console.WriteLine(0);
            return;
        }

        ModInt count = 1;
        var leftCount = 0;
        var rightCount = 0;
        foreach (var left in isLeft)
        {
            if (left)
            {
                leftCount++;
            }
            else
            {
                count *= leftCount - rightCount;
                rightCount++;
            }
        }

        for (int i = 2; i <= N; i++)
        {
            count *= i;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  int N;
  string S;
  cin >> N >> S;
  if(N-1){
    FOR(i,0,N-1){
      if(S[i] == S[i+1] && S[i] == 'x'){
        cout << i+1 << endl;
        return 0;
      }
    }
    cout << N << endl;
  }
  else{
    cout << 1 << endl;
  }
}



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

void insertionSort(vector<int>& vec) {
	int num;
	for (int i = 1; i < vec.size(); i++) {
		num = vec[i];
		int j = i - 1;
		while (j >= 0 && vec[j] > num) {
			vec[j + 1] = vec[j];
			j--;
		}
		vec[j + 1] = num;
	}
}

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

	vector<int> vec{ a, b, c };
	insertionSort(vec);

	auto it = vec.begin();
	auto end = vec.end();
	while (it != (end - 1)) cout << *it++ << ' ';
	cout << *it++ << endl;
}

Measured memory_bytes: 3088
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    if a + b >= 24 {
        println!("{}", a + b - 24);
    } else {
        println!("{}", a + b);
    }
}


Measured memory_bytes: 4352
x = int(input())

if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9188
H, W, K = map(int, input().split())
c = [input() for i in range(H)]

ans = 0
for h in range(2**H):
  for w in range(2**W):
    cnt = 0
    for i in range(H):
      for j in range(W):
        if (h >> i) & 1:
          continue
        if (w >> j) & 1:
          continue
        if c[i][j] == '#':
          cnt +=1
    if cnt == K:
      ans +=1
print(ans) 

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;

int main() {
    // input, ready
    ll A,B,C,K;
    cin >> A >> B >> C >> K;

    // resolve
    if (K<=A) {
        cout << K << endl;
        return 0;
    } else if (K<=A+B) {
        cout << A << endl;
        return 0;        
    } else {
        cout << A-(K-A-B) << endl;
        return 0;
    }

    // output

    // cout << fixed << setprecision(10) << middle << endl;

    return 0;
}


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

using namespace std;

const int N = 100010;

int a[N];

int main(){
	if(fopen("1.inp", "r")){
		freopen("1.inp", "r", stdin);
	}

	map < int, int > x;

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

	for(int i = 1; i <= n; ++i){
		scanf("%d", a + i);
		++x[a[i]];
	}

	int ans = 0;
	for(int i = 1; i <= n; ++i){
		ans = max(ans, x[a[i]] + x[a[i] - 1] + x[a[i] + 1]);
	}

	cout << ans;

	return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    ll sum = 0LL;
    for (int i =1; i <= n; i++){
      if (i % 3 && i % 5) sum += (ll)i;
    }

    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
using namespace std;
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

int main()
{
    int a,b;
    cin>>a;
    call(a);
    return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        if (Character.isUpperCase(a.charAt(0))) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    cout<<6/a/b<<endl;
    return 0;
}


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

int main() {
    list<long long int> L;
    int q;
    cin >> q;
    list<long long int>::iterator cur = L.begin();
    for(int i = 0; i < q; i++) {
        int command;
        cin >> command;
        if(command == 0) {
            int x;
            cin >> x;
            cur = L.insert(cur, x);
        } else if(command == 1) {
            int d;
            cin >> d;
            advance(cur, d);
        } else {
            cur = L.erase(cur);
        }
    }
    for(auto itr = L.begin(); itr != L.end(); itr++) {
        cout << *itr << endl;
    }
    return 0;
}


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

using namespace std;

int main(void){
    long long H, W;
    cin >> H >> W;
    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    cout << (H / 2) * (W / 2) + ((H + 1) / 2) * ((W + 1) / 2) << endl;
    return 0;
}


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

#define check(val) std::cout << "\033[31m" << #val << ": " << val << "\033[m" << std::endl
#define check_v(vec)                                                    \
  std::cout << "\033[31m" << #vec << ": [ ";                            \
  for(auto it=vec.begin(); it!=vec.end(); it++){cout << *it << " ";}    \
  cout << "]"<< "\033[m" << endl;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
    if(a[i] %2==0) {
      if(a[i] %3==0 || a[i] %5 == 0) {
        continue;
      }
      else {
        cout <<"DENIED" << endl;
        return 0;
      }
    }
    continue;
  }
  cout <<"APPROVED" << endl;
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> used(1000001);

	int m = 1;
	while (used[N] == 0) {
		used[N] = m;
		if (N % 2 == 0) {
			N /= 2;
		} else {
			N = N * 3 + 1;
		}
		m++;
	}

	cout << m << endl;
	
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  int ans=700;
  rep(i,3){
    if(s[i]=='o'){
      ans+=100;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {

  long N;
  string S;
  cin>>N>>S;
  vector<long> r(N);
  vector<long> g(N);
  vector<long> b(N);

  if(S[0]=='R'){
    r[0]=1;
  }
  if(S[0]=='G'){
    g[0]=1;
  }
  if(S[0]=='B'){
    b[0]=1;
  }

  for(int i=0;i<N-1;i++){
    if(S[i+1]=='R'){
      r[i+1]=r[i]+1;
      g[i+1]=g[i];
      b[i+1]=b[i];
    }
    if(S[i+1]=='G'){
      g[i+1]=g[i]+1;
      r[i+1]=r[i];
      b[i+1]=b[i];
    }
    if(S[i+1]=='B'){
      b[i+1]=b[i]+1;
      g[i+1]=g[i];
      r[i+1]=r[i];
    }
  }

  //cout<<r[N-1]<<endl;
  //cout<<g[N-1]<<endl;
  //cout<<b[N-1]<<endl;

  long ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      char s1=S[i];
      char s2=S[j];
      if(s1=='R'&&s2=='G'){
        ans+=b[N-1]-b[j];
        if(2*j-i<N) if(S[2*j-i]=='B') ans--;
        //cout<<i<<j<<2*j-i<<endl;
      }
      if(s1=='R'&&s2=='B'){
        ans+=g[N-1]-g[j];
        if(2*j-i<N) if(S[2*j-i]=='G') ans--;
      }
      if(s1=='G'&&s2=='B'){
        ans+=r[N-1]-r[j];
        if(2*j-i<N) if(S[2*j-i]=='R') ans--;
      }
      if(s1=='G'&&s2=='R'){
        ans+=b[N-1]-b[j];
        if(2*j-i<N) if(S[2*j-i]=='B') ans--;
      }
      if(s1=='B'&&s2=='R'){
        ans+=g[N-1]-g[j];
        if(2*j-i<N) if(S[2*j-i]=='G') ans--;
      }
      if(s1=='B'&&s2=='G'){
        ans+=r[N-1]-r[j];
        if(2*j-i<N) if(S[2*j-i]=='R') ans--;
      }

    }
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 3704
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        String[] a = new String[h];

        for (int i = 0; i < h; i++) {
            a[i] = sc.next();
        }
        sc.close();

        int cnt = 0;

        for (int i = 0; i < h + 2; i++) {
            if (!(i == 0 || i == h + 1)) {
                System.out.print("#");
                System.out.print(a[cnt]);
                System.out.print("#");
                cnt++;
            } else {
                for (int j = 0; j < w + 2; j++) {
                    System.out.print("#");
                }
            }
            System.out.println("");
        }
    }

}

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


int main(){
  int a,b,k;
  //cout << '1' << endl;
  cin >> a >> b >> k;
  map<int,int> mp;
  for(int i=a;i<a+k;++i){
    mp[i]++;
    //cout << i << endl;
  }
  for(int i=b;i>b-k;--i){
    mp[i]++;
  }
  for(auto p : mp){
    if(p.first>=a && p.first<=b){
      cout << p.first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; } 
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){
}
void jury(){
}
void solve(){
    int n = scan!int;

    long[] us, vs;
    foreach(i; 0 .. n){
        long x = scan!long, y = scan!long;
        us ~= x - y, vs ~= x + y;
    }

    us.sort();
    vs.sort();

    long ans = max(us[$ - 1] - us[0], vs[$ - 1] - vs[0]);

    ans.print;
}



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

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int t;
	t = a;
	a = b;
	b = t;
	t = c;
	c = a;
	a = t;
	printf("%d %d %d",a,b,c);
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int[][] card = new int[3][3];

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                card[i][j] = sc.nextInt();
            }
        }

        boolean[][] open = new boolean[3][3];
        int N = sc.nextInt();

        for (int i = 0; i < N; i++) {
            int call = sc.nextInt();

            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (card[j][k] == call) {
                        open[j][k] = true;
                    }
                }
            }
        }
        sc.close();
        
        System.out.println(isBingo(open) ? "Yes" : "No");

    }

    static boolean isBingo(boolean[][] card) {

        //たて
        loop: for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (card[i][j]) {
                    continue;
                } else {
                    continue loop;
                }
            }
            return true;
        }

        //よこ
        loop: for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (card[j][i]) {
                    continue;
                } else {
                    continue loop;
                }
            }
            return true;
        }
        
        // ななめ
        if(card[0][0]&&card[1][1]&&card[2][2]) {
            return true;
        }
        if(card[0][2]&&card[1][1]&&card[2][0]) {
            return true;
        }
        
        return false;

    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

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

  int ans = K; N--;
  
  Rep(i, N) ans *= K - 1;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256