akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

map<pii, int> f(string s) {
    static const int C = 31, C2 = 29, P = 1000000007, P2 = 1000000009;
    map<pii, int> res;
    int n = sz(s);
    rep(S, 1 << n) {
        ll h = 0, h2 = 0;
        rep(i, n) {
            if (S >> i & 1) {
                h = (h*C + s[i]) % P;
            } else {
                h2 = (h2*C2 + s[i]) % P;
            }
        }
        res[mp((int)h, (int)h2)]++;
    }
    return res;
}

void solve() {
    int N;
    string S;
    cin >> N >> S;
    string L = S.substr(0, N), R = S.substr(N, N);
    reverse(all(R));

    auto X = f(L);
    auto Y = f(R);
    ll ans = 0;
    each(x, X) {
        ans += (ll)x.second * Y[x.first];
    }
    cout << ans << endl;
}

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

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

int main(void){
    ll H;
    cin>>H;
    vector <ll> v;
    ll ans=1;
    rep(i, 41){
        v.emplace_back(ans);
        ans*=2;
    }
    ll num=0;
    rep(i, 41){
        if(v[i]>H){
            break;
        }
        else{
            num+=v[i];
        }
    }
    
    cout<<num<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,x;
	cin>>n;
	vector<int>a(100006,0);
	for(int i=0;i<n;i++){
		cin>>x;
		a[x]++;
		a[x+1]++;
		a[x+2]++;
	}
	cout<<*max_element(a.begin(),a.end());

	return 0;
}


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

using namespace std;
#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
const double pi=acos(-1);
const int mod=1e9+7;

//int a[maxn],sum;
//int d[maxn];
//int c;
//int dfs(int v,int k)
//{
//    if(k==s)
//    {
//
//    }
//    for(int i=v+1;i<sum;i++)
//    {
//        if(a[v]+c<a[i])
//        {
//            b[i]=1;
//            dfs(a[i],k+1);
//            b[i]=0;
//        }
//
//    }
//}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    string s,t;
    cin >> s >> t;
    //置換対応表
    char s_to_t[26]={};
    char t_to_s[26]={};
    int ch[26]={};
    bool yn=true;
    for(int i=0; i<s.size(); i++){
        if(s_to_t[s[i]-'a']){
            if(s_to_t[s[i]-'a'] != t[i]){
                yn = false;
            }
        }
        if(t_to_s[t[i]-'a']){
            if(t_to_s[t[i]-'a'] != s[i]){
                yn = false;
            }
        }
        s_to_t[s[i]-'a'] = t[i];
        t_to_s[t[i]-'a'] = s[i];
    }
    if(yn){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 904
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,s[500101],maxn=-1,z;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>z;
        s[z]++;
        s[z-1]++;
        s[z+1]++;
    }for(int i=0;i<=432434;i++){
        maxn=max(maxn,s[i]);
    }cout<<maxn<<endl;
    return 0;
}

Measured memory_bytes: 640
def main():
    s = input()
    k = int(input())
    s_ = []
    f = False
    for i in range(len(s)):
        if not s_:
            s_.append(s[i])
        elif not s_[-1][0] == s[i]:
            s_.append(s[i])
        else:
            s_[-1] += s[i]
    if s_[0][0] == s_[-1][0]:
        if len(s_) > 1:
            if len(s_[0])%2 == 1 and len(s_[-1])%2==1:
                f = True
            s_[0] = s_[0] + s_[-1]
            s_ = s_[:-1] 
    ans = 0
    if len(s_) == 1 and len(s_[0])%2==1:
        l = len(s_[0])
        if k%2==0:
            ans = l*k//2
        else:
            ans = l*(k-1)//2+l//2
        print(ans)
    else:
        for i in s_:
            ans += len(i)//2
        ans *= k
        if f == True and not len(s_) == 1:
          ans -= 1
        print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=100007;
const int inf=1000000007;
int n,l[maxn],r[maxn],p,q,ans,ansp,ansq;
int ma[maxn],mb[maxn];
struct data{
	int a,b,id;
}x[maxn];
bool cmp(const data &s,const data &t) {
	if (s.a==t.a) return s.b<t.b;
	return s.a>t.a;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	r[0]=inf;
	for (int i=1; i<=n; i++) {
		cin >> l[i] >> r[i];
		if (l[i]>l[p]) p=i;
		else if (l[i]==l[p] && r[i]<r[p]) p=i;
		if (r[i]<r[q]) q=i;
		else if (r[i]==r[q] && l[i]>r[q]) q=i;   
	}
	for (int i=1; i<=n; i++) {
		if (i==p || i==q) continue;
		ans=max(ans,r[i]-l[i]+1);
	}
	ans+=max(r[q]-l[p]+1,0);
//	cout<<ans<<endl;
	for (int i=1; i<=n; i++) {
		x[i].a=max(0,r[i]-l[p]+1);
		x[i].b=max(0,r[q]-l[i]+1);
		x[i].id=i;
	}
	sort(x+1,x+n+1,cmp);
	//ansp=r[p]-l[p]+1;
	//ansq=r[q]-l[q]+1;
	ma[0]=inf;
	for (int i=1; i<=n; i++) {
		ma[i]=ma[i-1];
		if (x[i].id==q) continue; 
		ma[i]=min(ma[i],x[i].a);
	} 
	mb[n+1]=inf;
	for (int i=n; i>0; i--) {
		mb[i]=mb[i+1];
		if (x[i].id==p) continue;
		mb[i]=min(mb[i],x[i].b);
	}
//	for (int i=1; i<=n; i++) cout<<x[i].a<<" ";
//	cout<<endl;
//	for (int i=1; i<=n; i++) cout<<x[i].b<<" ";
//	cout<<endl;
	for (int i=0; i<=n; i++) {
		ansp=min(r[p]-l[p]+1,ma[i]);
		ansq=min(r[q]-l[q]+1,mb[i+1]);
		//cout<<"i:"<<i<<" "<<ansp<<" "<<ansq<<endl;
		ans=max(ans,ansp+ansq); 
	} 
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    int N, cnt = 0;
    cin >> N;
    int d[100];
    int sum[101] = {0};
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    for(int i = 0; i < N; i++)
        sum[d[i]]++;
    
    for(int i = 0; i < 101; i++){
        if(sum[i] >= 1)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;
LL a[100];
int n;

int main(){
	a[0] = 2LL, a[1] = 1LL;
	for(int i = 2; i <= 86; i++) a[i] = a[i - 1] + a[i - 2];
	scanf("%d", &n);
	printf("%lld\n", a[n]);
	return 0;
}

Measured memory_bytes: 128
import itertools
s = list(input())
n = len(s) - 1
a = 0
for x in list(itertools.product(["+", ""], repeat=n)):
  x = list(x)
  x.append("")
  y = [d+e for d, e in zip(s, x)]
  a += eval("".join(y))
print(a)

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const int SIZE = 1000000000;

int main() {
    int N, A[100];
    int ans;
    double avr = 0;
    double diff;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
        avr += A[i];
    }
    avr /= N;

    diff = avr;
    for (int i = 0; i < N; i++) {
        if (diff > (abs(A[i]-avr))) {
            diff = abs(A[i]-avr);
            ans = i;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  char s[90];
  while (fgets(s, 81, stdin) != 0) {
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < strlen(s); j++) {
	if (isalpha(s[j])) {
	  if (s[j] == 'z') s[j] = 'a';
	  else s[j]++;
	}
      }
      if (strstr(s, "the") != NULL or strstr(s, "this") != NULL or strstr(s, "that") != NULL) break;
    }
    printf("%s", s);
  }
}

Measured memory_bytes: 1120
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)

if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1 or len(odd)==1:#単一の要素からなる場合ex.)1111
        ans = n//2
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1]+odd[0][1])
print(ans)

Measured memory_bytes: 15588
#include <iostream>

using namespace std;

int main()
{
	int k;
	cin >> k;
	long long n = 7;
	for (int i = 1; i <= 1000010; i++) {
		if (n % k == 0) {
			cout << i << endl;
			return 0;
		}
		n = n * 10 + 7;
		n %= k;
	}
	cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3668
<?php
   list($X,$Y) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$ashi=0;
for($a=0;$a<=$X;$a++){
  if($a*2+4*($X-$a)==$Y){
    echo "Yes";
    exit;
  }
}
echo "No";


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

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

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

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

void primeFactor(ll val, map<ll,ll> &primeList){
  cerr<<__FUNCTION__<<":start"<<endl;
  if(val<1){
    return;
  }
  ll cnt=0;
  while(val%2==0){
    cnt++;
    val/=2;
  }
  if(cnt!=0){
    cerr<<"2^"<<cnt<<endl;
    primeList[2]=cnt;
  }

  ll i=1;
  while(val>1){
    i+=2;
    if(i*i>val){
      primeList[val]=1;
      break;
    }
    cnt=0;
    while(val%i==0){
      cnt++;
      val/=i;
    }
    if(cnt==0){
      continue;
    }
    cerr<<i<<"^"<<cnt<<endl;
    primeList[i]=cnt;
  }
  cerr<<__FUNCTION__<<":end"<<endl;

  return;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll n;cin>>n;
  ll ans=0;
  map<ll,ll> pl;
  primeFactor(n,pl);
  for(auto it:pl){
    ll d=it.second;
    ll s=1;
    ll cnt=0;
    while(d>=s){
      d-=s;
      s++;
      cnt++;
    }
    ans+=cnt;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3604
import static java.lang.Integer.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static int D;


	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
		st = new StringTokenizer(br.readLine());
		D = parseInt(st.nextToken());

		int x = 25;
		System.out.print("Christmas");
		for(int i=x;i>D;i--) {
			System.out.print(" Eve");
		}
		System.out.println();

	}

}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    return max([A+B, A-B, A*B])


def main():
    A, B = read_int_n()
    print(slv(A, B))


if __name__ == '__main__':
    main()


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

int main(){
    ll n;cin>>n;
    vector<ll> a(n+1,1);
    for(ll i=2;i<=n;++i){
        for(ll j=1;j*i<=n;++j){
            a[i*j]++;
        }
    }
    for(ll i=2;i<n;++i){
        a[i] = a[i] + a[i-1];
    }
    cout<<a[n-1];
    

}



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

int main() {
  int N;
  cin >> N;
  while(N >= 1000) {
    N -= 1000;
  }
  if (N != 0) {
    N = 1000 - N;
  }
  cout << N << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> P(N);
    rep(i,N)cin >> P[i];
    vector<int> m(N);
    LL mt = INF;
    rep(i,N){
        if(P[i] <= mt){
            m[i] = P[i];
            mt = m[i];
        }
    }

    int ct = 0;
    rep(i,N){
        if(P[i] <= m[i]){
            ct++;
        }
    }
    cout <<  ct << endl;
}


Measured memory_bytes: 1792
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8");
const inputs = input.split("\n");

const N   = Number(inputs[0]);
const arr = inputs[1].split(" ");

const main = (N, arr) => {
    let sorted = arr.concat().sort((a, b) => {return a - b});
    let cnt = 0;
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] != sorted[i]) {
            cnt++;
        }
    }

    if (cnt === 0 || cnt === 2) {
        return "YES";
    } else {
        return "NO";
    }
};
console.log(main(N, arr));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int& x:a){
    cin>>x;
  }
  sort(a.begin(),a.end());
  long long answer = 0;
  for(int i=0;i<n-k;i++){
    answer+=a[i];
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 1024
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5+1;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
            string a,ans;
    cin>>a;
    int w,i=0;
    cin>>w;
    int n=a.size();
    while(i<n)
    {
        ans+=a[i];
        i+=w;
    }
    cout<<ans;

    }
  return 0;
  }



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long a,b,s=0;
	cin>>a>>b;
	if(a>0 && b>0)
	{
		printf("Positive\n");
	}
	if(a<0 && b<0)
	{
		for(int i=a;i<=b;i++)
		{
			s++;
		}
		if(s%2==1)
		{
			printf("Negative\n");
		}
		if(s%2==0)
		{
			printf("Positive\n");
		}
	}
	if(a==0 || b==0 || (a<0 && b>0))		
	printf("Zero\n");
	return 0;
}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	long long n,ka;
	cin>>n>>ka;
	vector<long long> go(n);
	vector<long long> point(n);
	for(long long i=0;i<n;i++){
		long long a;
		cin>>a;
		a--;
		go.at(i)=a;
	}

	long long ans=inf*-1;

	for(long long i=0;i<n;i++) cin>>point.at(i);
	map<long long,long long> done;

	for(long long i=0;i<n;i++){
		if(done.count(i)) continue;
		vector<long long> v;

		queue<long long> que;
		que.push(i);
		while(!que.empty()){
			long long now=que.front();
			done[now]=1;
			que.pop();
			v.push_back(point.at(now));
			if(go.at(now)==i) continue;
			que.push(go.at(now));
		}

		long long sum=0;
		vector<long long> pre=v;
		for(auto a:pre){//cout<<a<<" ";
			v.push_back(a);
			sum+=a;
		}//cout<<endl;

		long long pk=ka;
		long long hoge=0;
		long long cnt=inf*-1;//cout<<"sum= "<<sum<<endl;

		if(sum>0){
			hoge=(ka/(v.size()/2))*sum;
			pk-=(v.size()/2)*(ka/(v.size()/2));
		}else{
			pk=v.size()/2;
		}

		if(pk==0) cnt=0;

		//cout<<i<<" "<<ka/(v.size()/2)<<" "<<pk<<endl;

		for(long long j=1;j<=pk;j++){//cout<<j<<"!"<<endl;
			long long psum=0;
			for(long long k=0;k<j;k++){
				psum+=v.at(k);
			}
			chmax(cnt,psum);

			for(long long k=0;k+j<v.size();k++){
				psum+=v.at(k+j);
				psum-=v.at(k);
				chmax(cnt,psum);
			}
		}//cout<<hoge<<" "<<cnt<<"->"<<hoge+cnt<<endl;

		chmax(ans,hoge+cnt);

		if(sum>0){
			hoge=((ka/(v.size()/2))-1)*sum;
			pk=v.size()/2;

			for(long long j=1;j<=pk;j++){//cout<<j<<"!"<<endl;
				long long psum=0;
				for(long long k=0;k<j;k++){
					psum+=v.at(k);
				}
				chmax(cnt,psum);

				for(long long k=0;k+j<v.size();k++){
					psum+=v.at(k+j);
					psum-=v.at(k);
					chmax(cnt,psum);
				}
			}//cout<<hoge<<" "<<cnt<<"->"<<hoge+cnt<<endl;

			chmax(ans,hoge+cnt);
		}
	}

	cout<<ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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


Measured memory_bytes: 4200
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  map<string, int> m;
  m["SUN"] = 7;
  m["MON"] = 6;
  m["TUE"] = 5;
  m["WED"] = 4;
  m["THU"] = 3;
  m["FRI"] = 2;
  m["SAT"] = 1;
  
  string s;
  while(cin >> s){
    int ans = m[s];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include <vector>

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

using namespace std;


int main(){
	char c[100], s[200];
	stack<int> a;
	int j = 0, k = 0;
	while (scanf("%s", s) == 1){
		int b, c;
		if (strcmp(s, "+") == 0){
			b = a.top();
			a.pop();
			c = a.top();
			a.pop();
			a.push(b + c);
		}
		else if (strcmp(s, "-") == 0){
			b = a.top();
			a.pop();
			c = a.top();
			a.pop();
			a.push(c - b);
		}
		else if (strcmp(s, "*") == 0){
			b = a.top();
			a.pop();
			c = a.top();
			a.pop();
			a.push(b * c);
		}
		else{
			a.push(atoi(s));
		}
		if (strchr(s, '\n') != NULL){
			break;
		}
		j++;
	}
	/*
		REP(i, k){
			int b, c;
			if (s[i] == '+'){
				b = a.top();
				a.pop();
				c = a.top();
				a.pop();
				a.push(b + c);
			}
			else if (s[i] == '-'){
				b = a.top();
				a.pop();
				c = a.top();
				a.pop();
				a.push(c - b);
			}
			else if (s[i] == '*'){
				b = a.top();
				a.pop();
				c = a.top();
				a.pop();
				a.push(b * c);
			}
			else{
				a.push(s[i]-'0');
			}
			printf("%d\n", a.top());
		}
	*/
	printf("%d\n", a.top());

	return 0;
}


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int L[200];
	int i,j,c;
	for (i = 0; i < 2 * n; i++) {
		cin >> L[i];
	}
	//ソート
	for (i = 0; i < 2 * n - 1; i++) {
		for (j = 0; j < 2 * n -1 - i; j++) {
			if (L[j] < L[j + 1]) {
				c = L[j];
				L[j] = L[j + 1];
				L[j + 1] = c;
			}
		}
	}
	c = 0;
	for (i = 1; i < 2 * n; i = i + 2) {
		c = c + L[i];
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 10000000000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

long long a, b, c, d, e, f, g;

signed main() {
	cin >> a >> b >> c >> d >> e >> f >> g;
	if ((a % 2 == 1 && d % 2 == 1 && e % 2 == 1) || (a % 2 == 0 && d % 2 == 0 && e % 2 == 0))cout << a + b + d + e << endl;
	else if (a < 2 && d < 2 && e < 2)cout << b << endl;
	else cout << a + b + d + e - 1 << endl;
	ggr
}

Measured memory_bytes: 256
import Data.Char
import Data.Maybe
import Control.Monad
main = do
  s <- getContents
  let d = foldl1 f2  $ map (f1 . toLower) s
  forM_ ['a'..'z'] $ \k -> do
    putStrLn $ foldl1 (++) [[k], " : ", show $ fromJust $ lookup k d]

f1 c | elem c ['a'..'z'] = [(k, if c==k then 1 else 0) | k<-['a'..'z']]
     | otherwise = [(k,0) | k<-['a'..'z']]
f2 d1 d2 = [(k, (fromJust $ lookup k d1) + (fromJust $ lookup k d2)) | k<-['a'..'z']]


Measured memory_bytes: 11356
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 200000

int asc(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}
int main() {
	int n,k,i;
	long a[MAX];
	long sum;
	sum=0;
	scanf("%d %d",&n, &k);
	for(i=0;i<n;i++){
		scanf("%ld ", &a[i]);
	}
	qsort(a,n,sizeof(long),asc);
	for(i=0;i<n-k;i++) {
		sum+=a[i];
	}
	printf("%ld",sum);
	return 0;
}



Measured memory_bytes: 3324
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int width = in.nextInt();
		int height = in.nextInt();
		int rute = in.nextInt();
		int couse = 0;
		int[] x = new int [rute];
		int[] y = new int [rute];
		x[0] = in.nextInt();
		y[0] = in.nextInt();
		for(int i = 1;i < rute;i++){
			x[i] = in.nextInt();
			y[i] = in.nextInt();
			if(x[i] > width || y[i] > height){
				x[i] = x[i-1];
				y[i] = y[i-1];
			}
			while(x[i] <= width && y[i] <= height){
				if(x[i-1] < x[i] && y[i-1] < y[i]){
					if(x[i]-x[i-1] > y[i]-y[i-1]) couse = couse + x[i]-x[i-1];
					else couse = couse + y[i]-y[i-1];
				}
				else if(x[i-1] > x[i] && y[i-1] > y[i]){
					if(x[i-1]-x[i] > y[i-1]-y[i]) couse = couse + x[i-1]-x[i];
					else couse = couse + y[i-1]-y[i];
				}
				else{
					if(x[i]-x[i-1] >= 0){
						couse = couse + x[i]-x[i-1];
					}
					else{
						couse = couse - x[i]+x[i-1];
					}
					if(y[i]-y[i-1] >= 0){
						couse = couse + y[i]-y[i-1];
					}
					else{
						couse = couse - y[i]+y[i-1];
					}
				}
				break;
			}
		}
		System.out.println(couse);
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    int n, z, w;
    cin >> n >> z >> w;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    if(n == 1){
        ppp(abs(a[0]-w));
    }
    else{
        ppp(max(abs(a[n-1]-a[n-2]), abs(a[n-1]-w)));
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0, max = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I'){
      x++;
      if(x > max){
        max = x;
      }
    }else{
      x--;
    }
  }
  cout << max << endl;
}


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

using namespace std;

#define ll long long
const int mxN=1e9;

int main(){
//#ifndef ONLINE_JUGDE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll d,t,s;
    cin>>d>>t>>s;
    ll dx=t*s;
    if(dx>=d)
    	cout<<"Yes";
    else
    	cout<<"No";

	//d=t*s;
	
    return 0;
}


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

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

    int n,a,b;
    cin>>n;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        v.push_back({a,b});
    }
    bool f=false;
    for(int i=0;i<n-3+1;i++)
    {
        if(v[i].first==v[i].second && v[i+1].first==v[i+1].second && v[i+2].first==v[i+2].second)
        {
            f=true;break;
        }
    }
    if(f)cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}


Measured memory_bytes: 3632
#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__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j : {i + 1, i + 2}) {
            if(j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 4068
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

k,x=map(int,input().split())
if k==x:
    ans=list(range(1,k+x))
else:
    ans=list(range(x-k+1,x+k))
print(*ans)

Measured memory_bytes: 38384
# Tenka1_2017_B_Different_Distribution.py

N = int(input())
I = []*N
for i in range(N):
    a, b = list(map(int, input().split()))
    I.append((a, b))
# print(I)
I.sort()
k = I[0][0]
l = I[-1][0]
m = I[-1][1]
# print(k,l,m)
print((k-1)+(l-k+1)+m)


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

int main(){
  int r, c;
  cin >> r >> c;
  int table[r][c];

  int i, j;
  for(i = 0; i < r; i++) {
    for(j = 0; j < c; j++) {
      cin >> table[i][j];
    }
  }

  int sum = 0,
      sum_All = 0;
  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      cout << table[i][j] << " ";
      sum += table[i][j];
    }
    cout << sum << endl;
    sum_All += sum;
    sum = 0;
  }

  for(i = 0; i < c; i++){
    for(j = 0; j < r; j++){
      sum += table[j][i];
    }
    cout << sum << " ";
    sum_All += sum;
    sum = 0;
  }

  cout << sum_All / 2 << endl;
}



Measured memory_bytes: 3116
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>
#include<map>




using namespace std;


int main() 
{
    int n, m;
    cin >> n >> m;
    long long ans = ((n) * (n - 1)) / 2 + (m) * (m - 1) / 2;
    cout << ans;
}
    



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int num,count=0;
  scanf("%d",&num);
  int i,size[num],log[100];
  for(i=0; i<num; i++)
  {
    scanf("%d",&size[i]);
  }
  for(i=0; i<100; i++)
  {
    log[i]=i+1;
  }
  for(i=0; i<num; i++)
  {
    if(size[i]==log[size[i]-1])
    {
      log[size[i]-1]=0;
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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



int main(){
    int n; cin >> n;
    vector<int> h(n), dp(n, 0);
    REP(i, n) cin >> h[i];
    dp[0] = 0; dp[1] = abs(h[0]-h[1]);
    FOR(i, 2, n)
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    cout << dp[n-1] << "\n";
    return 0;
}


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

const int MAX_N=105;
int n;
int a[MAX_N],d[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=2;i<=n;++i)
		for(int j=2,t=i;t>=j;++j)
			while(t%j==0){
				++a[j];	t/=j;
			}
	for(int i=2;i<=n;++i)
		++d[a[i]+1]; 
	for(int i=1;i<MAX_N;++i)
		d[i]+=d[i-1];
	int ans=0,m=104;
	ans=d[m]-d[74];
	ans+=(d[24]-d[2])*(d[m]-d[24]);
	ans+=(d[m]-d[24])*(d[m]-d[24]-1);
	ans+=(d[m]-d[14])*(d[14]-d[4]);
	ans+=(d[m]-d[14])*(d[m]-d[14]-1);
	ans+=(d[m]-d[4])*(d[m]-d[4]-1)/2*(d[m]-d[2]-2);
	cout<<ans<<endl;
	
	return 0;
}

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

int main(){
  int N; cin >> N;
  int B[200];
  for (int i = 1; i < N; i++) cin >> B[i];
  int ans = B[1] +B[N-1];
  for (int i = 1; i < N-1; i++) {
    ans += min(B[i],B[i+1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const INF = 1000000000001

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var n int
	n = scanInt()

	max := 0 - INF
	min := scanInt()
	for i := 1; i < n; i++ {
		num := scanInt()
		max = Max(max, num-min)
		min = Min(min, num)
	}

	fmt.Println(max)
}



Measured memory_bytes: 4104
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();

    if cv[0] != cv[1] {
        if (cv[0] == cv[2] && cv[1] == cv[3]) || (cv[0] == cv[3] && cv[1] == cv[2]) {
            println!("Yes");
        } else {
            println!("No");
        }
    } else {
        if cv[1] != cv[2] && cv[2] == cv[3] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 4352
N, W = map(int, input().split())

MAX_V = N * (10 ** 3)
w, v = [], []
for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [10**9+7 for _ in range(MAX_V + 1)]
dp[0] = 0

for i in range(N):
    for j in range(MAX_V, -1, -1):
        if j - v[i] >= 0:
            dp[j] = min(dp[j],dp[j - v[i]] + w[i])
        else:
            dp[j] = dp[j]

mv = 0
for i in range(MAX_V + 1):
    if dp[i] <= W:
        mv = i

print(mv)


Measured memory_bytes: 45040
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>

using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))
#define QWERTYR(c) (c == 'y' || c == 'u' || (c >= 'h' && c <= 'p') ?	true : false)
typedef vector<int> Ivec;
typedef pair<int, int> Pos;

int main() {
	int n, m;
	array<bool, 100001> ar = {};
	array<int, 100001> kos;
	ar[0] = true;
	scanf("%d %d", &n, &m);
	for (int i = 0; n > i; i++)kos[i] = 1;
	for (int i = 0; m > i; i++) {
		int a,b;
		scanf("%d %d", &a, &b);
		a--; b--;
		ar[b] = max(ar[b],ar[a]);
		kos[a]--;
		kos[b]++;
		if(!kos[a])ar[a] = false;
	}
	int cou = 0;
	for (int i = 0; n > i; i++) {
		if (ar[i])cou++;
	}
	printf("%d\n", cou);
	return 0;
}

Measured memory_bytes: 768
n=int(input())
a=sorted(list(map(int,input().split())))
if len(a)==2:
  print(*a[::-1])
else:
  m=a[n-1]
  a=a[:n-1]
  h=m/2
  import bisect as bi
  x=bi.bisect_left(a,h)
  print(m,a[x-(a[x]-h>h-a[x-1])])

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

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

  int n, x;
  cin >> n >> x;

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

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

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
from math import ceil

N,K = map(int, input().split())
ans = 0

if( N>=K ):
  ans += (N-K+1)/N

for i in range(20):
  if( K/(2**(i+1)) <= N < K/(2**i) ):
    ans += ( N +1 - ceil( K/(2**(i+1)) ) )/N / (2**(i+1))
  if( N > K/(2**i)):
    ans += ( ceil( K/(2**i) ) - ceil( K/(2**(i+1)) ) )/N / (2**(i+1))

print(ans)

Measured memory_bytes: 3064
n = gets.to_i
pos = Array.new(n){gets.split(" ").map(&:to_i)}
ans = 0.0
pos.permutation.each do |p|
  (n-1).times do |i|
    ans += ((p[i][0] - p[i+1][0])**2 + (p[i][1] - p[i+1][1])**2) ** 0.5
  end
end
fact = [*1..n].inject{|m, i| m *= i}
puts ans / fact

Measured memory_bytes: 2300
"""
ABC076_D AtCoderExpress
まず区間に注目してEditorialみたいなグラフを思い描くことがきつかった。
そのうえで、区間Limitをバグなく実装するのが結構ポイント。
あとはVVあたりがバグってないかをPrintしながら見ていく形。
"""
N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))
TMAX = sum(T)

TS = [0] * (N+1)
for i in range(N):
  TS[i+1] = TS[i] + T[i]
T_Left = TS[:N]
T_Right = TS[1:]
#print(T_Left,T_Right,V)

## これで下記がちゃんとつくれた。
# Tleft[i] <= t <= Tright[i] の間、 V[i]以下でなければいけない

# VV[tt] tt/2秒時の速度。両端がゼロ、という条件から初期値を生成する。
VV = [min(i*0.5, (TMAX*2-i) * 0.5) for i in range(TMAX*2+1)]
#print(VV)

# 区間iについて
for i in range(N):
  for tt in range(TMAX*2+1):
    VV[tt] = min(VV[tt], V[i] + max(0, (T_Left[i]*2 - tt) * 0.5, (tt-T_Right[i]*2) * 0.5))
#print(VV)
# 面積は両端がゼロであることから、速度合計を２で割る（0.5秒ごとだから）で出る。
# v-tグラフの面積を台形の面積で考えればよい。
print(sum(VV)/2)

Measured memory_bytes: 76092
#include <stdio.h>
void Rect(unsigned int h,unsigned int w){
	int i, j;
	for (i = 0; i < h; i++){
		for (j = 0; j < w; j++){
			printf("#");
		}
		printf("\n");
	}
	printf("\n");
}

int main(void){
	unsigned int h, w;
	while (1){
		scanf("%d %d", &h, &w);
		if (!(h * w))break;
		Rect(h, w);
	}
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  int ans;
  for(int i = 1; i < int(sqrt(m)); i++){
    if(m % i == 0 && i <= m / n) ans = max(ans, i);
    if(m % i == 0 && m / i <= m / n) ans = max(ans, m / i);
  }
  
  if(n == 1) ans = m;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n,m;
  cin >> n >> m;
  UnionFind<ll>tree(n);
  rep(i,m){
    ll l,r,d;
    cin >> l >> r >> d;
    l--;
    r--;
    if(tree.issame(l,r)){
      ll diff=tree.diff(l,r);
      if(diff!=d){
        cout << "No" << endl;
        return 0;
      }
    }
    else tree.merge(l,r,d);
  }
  cout << "Yes" << endl;
        return 0;
}


Measured memory_bytes: 13824
def equal_list(lst1, lst2):
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            break
    else:
        if not lst:
            return True
    return False


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

if a == [0]*N:
    print("Yes")
    exit()

if N % 3 == 0:
    n = N // 3
    sets = list(set(a))
    order = max(a).bit_length()
    if len(sets) == 3:
        for s in sets:
            if a.count(s) != n:
                print("No")
                exit()

        for i in range(order):
            b = [sets[0] >> i & 1, sets[1] >> i & 1, sets[2] >> i & 1]
            if b == [0, 0, 0]:
                continue
            if not equal_list(b, [0, 1, 1]):
                print("No")
                exit()
    elif len(sets) == 2:
        if a.count(sets[0]) == n:
            for i in range(order):
                b = [sets[0] >> i & 1, sets[1] >> i & 1]
                if b == [0, 0]:
                    continue
                if b != [0, 1]:
                    print("No")
                    exit()
        elif a.count(sets[1]) == n:
            for i in range(order):
                b = [sets[0] >> i & 1, sets[1] >> i & 1]
                if b == [0, 0]:
                    continue
                if b != [1, 0]:
                    print("No")
                    exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()

    print("Yes")

else:
    print("No")
    exit()


Measured memory_bytes: 14228
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	vector<int> D;
	cin >> N;
	int A;
	rep(i, 0, N)
	{
		cin >> A;

		D.push_back(A);
	}

	sort(all(D));

	D.erase(unique(all(D)), D.end());

	cout << SZ(D) << endl;

	return 0;
}

Measured memory_bytes: 256
odd = list('RUD')
evn = list('LUD')
S = list(input())

flag = True
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] in odd:
            pass
        else:
            flag = False
            break
    else:
        if S[i] in evn:
            pass
        else:
            flag = False
            break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];
    lli cnt = 0;
    for(lli i=1; i<n-1; i++) if((p[i]<p[i+1] && p[i]>p[i-1]) || (p[i]<p[i-1] && p[i]>p[i+1])) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 256