akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, K, ans;
    string S;
    scanf("%d %d", &N, &K);
    cin >> S;
    int ChangeFlag  = 0;
    int CharCounter = 1;
    if ( K > 0 ){
        REP(int,i,0,N-1){
            if ( S.at(i) == S.at(i+1) ){
                CharCounter++;
            }
            else if ( K > 0 && ChangeFlag ){
                int j = i;
                while ( CharCounter > 0 ){
                    if ( S.at(j) == 'L' ){
                        S.at(j) = 'R';
                    }
                    else if ( S.at(j) == 'R' ){
                        S.at(j) = 'L';
                    }
                    j--;
                    CharCounter--;
                }
                K--;
                CharCounter = 1;
                ChangeFlag = 0;
            }
            else if ( !ChangeFlag ){
                ChangeFlag = 1;
                CharCounter = 1;
            }
        }
        if ( ChangeFlag == 1 && K > 0 ){
            int j = N - 1;
            while ( CharCounter > 0 ){
                if ( S.at(j) == 'L' ){
                    S.at(j) = 'R';
                }
                else{
                    S.at(j) = 'L';
                }
                j--;
                CharCounter--;
            }
        }
    }
    ans = 0;
    if ( N >= 2 ){
        if ( S.at(0) == 'R' ){
            if ( S.at(1) == S.at(0) ) ans++;
        }
        if ( S.at(N-1) == 'L' ){
            if ( S.at(N-2) == S.at(N-1) ) ans++;
        }
        REP(int,i,1,N-1){
            if ( S.at(i) == 'L' ){
                if ( S.at(i-1) == S.at(i) ) ans++;
            }
            else if ( S.at(i) == 'R' ){
                if ( S.at(i) == S.at(i+1) ) ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

int main(){
  ll n,xt,yt,ht,x[101],y[101],h[101],H;
  cin>>n;
  for(ll i=0;i<n;i++){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i] > 0){
      swap(x[i], x[0]);
      swap(y[i], y[0]);
      swap(h[i], h[0]);
    }
  }
  
  for(ll cx=0;cx<=100;cx++){
    for(ll cy=0;cy<=100;cy++){      
      H=h[0]+abs(x[0]-cx)+abs(y[0]-cy);
      bool flag = true;
      for(ll i=1;i<n;i++){
        if(h[i]!=max(H-abs(x[i]-cx)-abs(y[i]-cy),0LL))flag=false;
      }
      if(flag){
        cout<<cx<<" "<<cy<<" "<<H<<endl;
        return 0;
      }
    }
  }
  return 0;
}
  

Measured memory_bytes: 256
using System;



class Program
{
    static void Main(string[] args)
    {
        Input CInput = new Input();
        //EasyTask CEasyTask = new EasyTask();
        //int input = 0;
        //int[] input = new int[(int)Input.Define.MAX_ArraySize];
        //int[,] input = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        //int num = 0;
        //input = CInput.Line1_int();
        //input = CInput.Multiline_int(' ', 2, ref num);

        int input1 = 0;
        int[] input2 = new int[(int)Input.Define.MAX_ArraySize];

        input1 = CInput.Line1_int();
        input2 = CInput.Line1_int(' ', input1);

        for (int i = 0; i < input1; i++)
        {
            if (i == input1 -1) System.Console.WriteLine("{0}", input2[0]);
            else System.Console.Write("{0} ", input2[input1 - i - 1]);
        }
    }
}








class Input
{
    public enum Define
    {
        MAX_ArraySize = 1000000,
        ArraySize2d = 2,                // 2?¬?????????????[][?] ???????
    }

    public string Line1_string()
    {
        return Console.ReadLine();
    }

    public int Line1_int()
    {
        var input = Console.ReadLine();
        return int.Parse(input);
    }

    public double Line1_double()
    {
        var input = Console.ReadLine();
        return double.Parse(input);
    }

    public int[] Line1_int(int chr, int num)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int[100];
        for (int i = 0; i < num; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        return spliti;
    }

    public int[] Multiline_int(ref int datanum)
    {
        int i = 0;
        int[] data = new int[(int)Input.Define.MAX_ArraySize];
        while (true)
        {
            var input = Console.ReadLine();
            var value = int.Parse(input);
            if (value == 0) break;
            data[i] = value;
            i++;
        }
        datanum = i;
        return data;
    }
    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="datanum">??????????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, ref int datanum)
    {
        int i = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
            }
            if (spliti[0] == 0 && spliti[1] == 0) break;
            data[i, 0] = spliti[0];
            data[i, 1] = spliti[1];
            i++;
        }
        datanum = i;
        return data;
    }
}

class EasyTask
{
    public void Swap(ref int a, ref int b)
    {
        int buf = 0;
        buf = a;
        a = b;
        b = buf;
    }






}

Measured memory_bytes: 13088
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, A; cin >> N >> A;
  cout << N * N - A << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int odd = 0;
	int evn = 0;
	for (int i = 0; i < N; i++){
		int n;
		cin >> n;
		if (n % 2 == 0){
			evn++;
		}
		else{
			odd++;
		}

	}
	if (odd % 2 == 0){
		cout << "YES";
	}
	else{
		cout << "NO";
	}
	//printf("%d\n", evn);
	//printf("%d\n", odd);
	return 0;
}


Measured memory_bytes: 764
N, X, Y = map(int, input().split())

def dist(fr, to):
    return min(
        to - fr,
        abs(to - Y) + 1 + abs(fr - X),
        abs(fr - Y) + 1 + abs(to - X)
    )

cnt = [0] * N

ans = 0
for fr in range(1, N + 1):
    for to in range(fr + 1, N + 1):
        cnt[dist(fr, to)] += 1

print(*(cnt[1:]), sep='\n')

Measured memory_bytes: 3444
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int N = input[0];
		int A = input[1];
		int B = input[2];
		var v = Console.ReadLine().Split().Select(long.Parse).ToArray();

		decimal ans = 0;
		
		long cnt = 0;

		Array.Sort(v);
		Array.Reverse(v);
        for(var i = 0; i < A; i++)
		{
			ans = (i * ans + v[i]) / (i + 1);
		}
		
		int start = -1;
		int end = A - 1;
		bool same = false;

		for (var i = 0; i < N; i++) 
		{
			if (v[i] == v[A - 1] && start == -1) { start = i; }
			else if (v[i] == v[A - 1])  { end = i; }

			if (start == 0 && end > A - 1) { same = true; }
		}
		var c = new Calculation();
		if (same)
		{
			long sum = 0;

			for (int i = A - 1; i < Math.Min(B,end+1); i++)
			{
				sum += c.GetNCR(end + 1, i + 1);
			}
			cnt = sum;
		}
		else
		{
			cnt = c.GetNCR(end - start + 1, A - start);
		}
        

		Console.WriteLine(ans);
		Console.WriteLine(cnt);


		

	}
}

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
//入力用

public class Calculation //各種値の計算メソッド
{
	public int GetGcd(int a, int b) //最大公約数(２数)
	{

		if (a < b)
		{
			int c = a;
			a = b;
			b = c;
		}
		if (b == 0)
		{
			return a;
		}
		int r = a % b;
		while (r > 0)
		{
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}
	public int GetGcdOfSortedArray(int[] array) //最大公約数(ソート済み数列)
	{
		if (array.Length == 0) { return 1; }
		else if (array.Length == 1) { return array[0]; }
		else
		{
			int n = 0;
			int g = array[0];
			while (n <= array.Length - 2)
			{

				int a = array[n + 1];
				int b = g;
				int r = a % b;
				while (r > 0)
				{
					a = b;
					b = r;
					r = a % b;
				}
				g = b;
				
			    n++;
			}

			return g;

		}
	}

	public long GetNCR(int n, int r) //二項係数(生の値)
	{
		if (n == 1) { return 1; }
		long[] nC = new long[n + 1];
		nC[0] = 1;
		for (var i = 0; i <= r - 1; i++)
		{
			nC[i + 1] = nC[i] * (n - i) / (i + 1);
		}
		return nC[r];
	}


}

class Modulo //1000000007で割る問題用
{
	private const int M = 1000000007;
	private readonly int[] m_facs;
	public int Mul(int a, int b) //掛け算
	{
		return (int)(Math.BigMul(a, b) % M);
	}
	public Modulo(int n)
	{
		m_facs = new int[n + 1];
		m_facs[0] = 1;
		for (int i = 1; i <= n; ++i)
		{
			m_facs[i] = Mul(m_facs[i - 1], i);
		}
	}
	public int Fac(int n)
	{
		return m_facs[n];
	}
	public int Pow(int a, int m) //累乗
	{
		switch (m)
		{
			case 0:
				return 1;
			case 1:
				return a;
			default:
				int p1 = Pow(a, m / 2);
				int p2 = Mul(p1, p1);
				return ((m % 2) == 0) ? p2 : Mul(p2, a);
		}
	}
	public int Div(int a, int b) //除算
	{
		return Mul(a, Pow(b, M - 2));
	}
	public int Ncr(int n, int r) //二項係数
	{
		if (n < r) { return 0; }
		if (n == r) { return 1; }
		int res = Fac(n);
		res = Div(res, Fac(r));
		res = Div(res, Fac(n - r));
		return res;
	}
	public Modulo() { }
}





Measured memory_bytes: 13524
#include <stdio.h>
#include <math.h>

int main(void)
{
	double x1, y1, x2, y2, d;
	
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
	printf("%f\n", sqrt(d));
	
	return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <string.h>
int main(){
	int k;
	scanf("%d",&k);
	char s[100];
	scanf("%s",&s);
	int lol = strlen(s);
	s[k] = '\0';
	for(int i=0;s[i]!='\0';i++){
		printf("%c",s[i]);
	}
	if(k<lol){
		printf("...");
	}
return 0;
}

Measured memory_bytes: 1688
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,tot=0,b[N],deep[N],sum[N],blog[N],head[N];
struct node
{
	int vet,nxt,flag;
}edge[N];
void add(int u,int v)
{
	edge[++tot].vet=v;
	edge[tot].nxt=head[u];
	head[u]=tot;
}
void dfs(int u,int fa)
{
	b[u]=1;
	deep[u]=deep[fa]+1;
	for(int i=head[u];i;i=edge[i].nxt)
	{
		int v=edge[i].vet;
		if(v==fa)continue;
		if(!b[v])
		{
			dfs(v,u);
			if(blog[v])
			{
				edge[i].flag=1;
				sum[u]++;
			}
		}else
			if(deep[v]<deep[u])
			{
				edge[i].flag=1;
				sum[u]++;
			}
	}
	if(sum[u]%2==1)
	{
		for(int i=head[u];i;i=edge[i].nxt)
			if(edge[i].vet==fa)
			{
				edge[i].flag=1;
				sum[u]++;
				break;
			}
	}else blog[u]=1;
}
int main()
{
	scanf("%d%d",&n,&m);
	if(m%2==1)
	{
		puts("-1");
		return 0;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	memset(b,0,sizeof(b));
	memset(deep,0,sizeof(deep));
	memset(sum,0,sizeof(sum));
	memset(blog,0,sizeof(blog));
	dfs(1,0);
	for(int u=1;u<=n;u++)
		for(int i=head[u];i;i=edge[i].nxt)
			if(edge[i].flag)
				printf("%d %d\n",u,edge[i].vet);
	return 0;
}

Measured memory_bytes: 13952
#include <stdio.h>
#define MAX 30

int main(void){
    int w,n, tmp;
    int a,b;
    int lot[MAX+1]; // 1-origin

    scanf("%d", &w);
    scanf("%d", &n);
    for (int i=1; i<=w; i++) lot[i] = i;
    for (int i=1; i<=n; i++){
        scanf("%d,%d", &a, &b);
        tmp = lot[a];
        lot[a] = lot[b];
        lot[b] = tmp;
    }
    for (int i=1; i<=w; i++){
        printf("%d\n", lot[i]);
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
using namespace std;

int main()
{
	ll t;
//	cin>>t;
	t=1;
	while(t--){
		string s;
		cin>>s;
		ll val=0;
		for(ll i=0;i<s.size();i++){
			val=(val+(s[i]-'0'))%9;
		}
		if(val==0){
			cout<<"Yes\n";
		}
		else{
			cout<<"No\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n + 1) cin >> a[i];

  vector<ll> l(n + 1), r(n + 2); // 深さiにおける最小ノード数lと、最大ノード数r
  l[n] = r[n] = a[n];
  for (int i = n - 1; i >= 0; --i) {
    l[i] = (l[i + 1] + 1) / 2 + a[i];
    r[i] = a[i] + r[i + 1];
  }

  if (l[0] > 1) {
    cout << -1 << endl;
    return 0;
  }

  ll cur = 1;
  ll ans = 0;
  rep(i, n + 1) {
    ans += cur;
    cur -= a[i];
    cur = min(cur*2, r[i + 1]);
  }
  cout << ans << endl;
}

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

long long N;
long long A[100005];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
	}
	sort(A, A + N);

	long long cur = 0;
	long long idx = 0;
	for(long long i = 0; i < N - 1; i++){
		cur += A[i];
		if(cur * 2 < A[i+1]){
			idx = i + 1;
		}
	}
	cout << N - idx << endl;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func main() {
	n := nextInt()

	switch {
	case n < 10:
		fmt.Println(n)
		return
	case n >= 10 && n < 100:
		fmt.Println(9)
		return
	case 100 <= n && n < 1000:
		fmt.Println(9 + (n - 100 + 1))
		return
	case 1000 <= n && n < 10000:
		fmt.Println(9 + 900)
		return
	case 10000 <= n && n < 100000:
		fmt.Println(9 + 900 + (n - 10000 + 1))
		return
	case n == 100000:
		fmt.Println(90909)
		return
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c[4],c2[4],a;
  bool flag=false;
  
  while(1){
    cin >> n;
    if(n==0)break;
    
    if(flag)cout <<endl;
    
    for(int i=0 ; i < 4 ; i++){
      cin >>c[i];
    }
    
    int sum=10*c[0]+50*c[1]+100*c[2]+500*c[3];
    int ans=sum-n;
    
    c2[3]=ans/500;
    ans%=500;
    c2[2]=ans/100;
    ans%=100;
    c2[1]=ans/50;
    ans%=50;
    c2[0]=ans/10;
    
    if(c[0]-c2[0] > 0){
      cout <<"10 "<<c[0]-c2[0]<<endl;
    }
    if(c[1]-c2[1] > 0){
      cout <<"50 "<<c[1]-c2[1]<<endl;
    }
    if(c[2]-c2[2] > 0){
      cout <<"100 "<<c[2]-c2[2]<<endl;
    }
    if(c[3]-c2[3] > 0){
      cout <<"500 "<<c[3]-c2[3]<<endl;
    }
 
    flag=true;

  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >>n;
  ll h[n+1];
  ll dp[n+1];
  for(ll i=1;i<n+1;i++) cin >>h[i];
  for(ll i=0;i<n+1;i++) dp[i]=1e9+7;
  dp[0]=0;
  dp[1]=0;//足場1動かなくていいので0
  dp[2]=abs(h[2]-h[1]);
  for(ll i=3;i<n+1;i++){
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
  }
  cout << dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>
#include<deque>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n)
#define sintt(n,m) scanf("%d%d",&n,&m)
#define sinttt(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define MAX 1000000000
#define end(a,b) if(a==b)break;

using namespace std;


int main(){
	while(1){
		int masu[101][101][4];
		
		int n,m;
		sintt(n,m);
		
		end(n,0);
		
		rep(i,100)rep(j,100)rep(k,4)masu[i][j][k]=0;
		
		masu[0][0][0]=masu[0][0][1]=1;
		
		rep(i,n){
			rep(j,m){
				masu[i][j+1][2]+=masu[i][j][0]%100000;
				masu[i+1][j][3]+=masu[i][j][1]%100000;
				masu[i+1][j][1]+=masu[i][j][2]%100000;
				masu[i][j+1][2]+=masu[i][j][2]%100000;
				masu[i+1][j][3]+=masu[i][j][3]%100000;
				masu[i][j+1][0]+=masu[i][j][3]%100000;
			}
		}
		
		/*
		rep(i,n){
			rep(j,m){
				rep(k,4){
					printf("%d-",masu[i][j][k]);
				}printf(" ");
			}puts("");
		}
		*/
		int ans=0;
		rep(i,4){
			ans+=masu[n-1][m-1][i];
		}
		
		printf("%d\n",ans%100000);
	}
}

Measured memory_bytes: 0
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;



int main(){

	int n;
	while(cin>>n,n){

		map<long double,set<string> > ans;
		for(int i=0;i<n;i++){
			string name;
			long double p,a,b,c,d,e,f,s,m;
			cin>>name>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			ans[((f*s*m)-p)/(a+b+c+m*(d+e))].insert(name);
		}

		for(auto it=ans.rbegin();it!=ans.rend();it++){
			set<string> ss =it->second;
			for(auto it2=ss.begin();it2!=ss.end();it2++) cout<<(*it2)<<endl;
			
		}
		cout<<"#"<<endl;
	}

	return 0;
}

Measured memory_bytes: 3252
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

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

    s[3] = '8';

    for(int i = 0; i < 10; i++) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    string S;
    cin >> S;

    int passed = 0;
    int countB = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'a') {
            if (passed < A + B) {
                cout << "Yes" << endl;
                passed++;
            } else {
                cout << "No" << endl;
            }
        } else if (S[i] == 'b') {
            countB++;
            if ((passed < A + B) && (countB <= B)) {
                cout << "Yes" << endl;
                passed++;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[200001]={0};
  rep(i,n){
    cin>>a[i];
    if(i!=0) a[i]+=a[i-1];
  }
  sort(a,a+n+1);
  int now=1e17,cnt=0;
  int ans=0;
  rep(i,n+1){
    if(now!=a[i]){
      ans+=(cnt*(cnt-1))/2;
      cnt=1;
      now=a[i];
    }else{
      cnt++;
    }
  }
  ans+=(cnt*(cnt-1))/2;
  cout<<ans<<endl;
  
  

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
  long long i, N, res = 1;
  cin >> N;
  
  for (i = 1; i <= N; i++) {
    res = res*i % ((long long)pow(10,9) + 7);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
const ll MOD=1e9+7;
ll mod(ll x)
{
   return (x%MOD+MOD)%MOD;
   // works for neg and pos values of x.
}
void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    ll ans1=a*d,ans2=a*c,ans3=b*c,ans4=b*d;
    cout<<max({ans1,ans2,ans3,ans4});

}
int main()
{

//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        ArrayList<ArrayList<Integer>> cave = new ArrayList<>();
        //i番目の部屋は(i-1])に対応

        for (int i = 0; i < n; i++) {
            //Listを作って代入、だと上手くいかないので先に空のListをN個入れておく
            cave.add(new ArrayList<Integer>());
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            cave.get(a - 1).add(b - 1);//caveのa-1番目の要素にb-1というintを代入
            cave.get(b - 1).add(a - 1);
        }

        int[] dist = new int[n];
        for (int i = 0; i < n; i++) {
            dist[i] = -1;//全部屋見つかってない状態に初期化
        }

        LinkedList<Integer> queue = new LinkedList<>();
        queue.add(0);//まず1番目の部屋番号をキューに入れる

        int a = 0;
        while (!queue.isEmpty()) {
            int num = queue.pollLast();//キューの一番下の値をget
            for (int k : cave.get(num)) {//そのキューに繋がってる部屋番号でfor文回す
                if (dist[k] == -1) {//部屋にまだ行ってなかった場合の処理
                    queue.addFirst(k);//その番号をキューの一番上に代入
                    dist[k] = num + 1;//看板を立てる
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append("Yes" + "\n");

        for(int i = 1 ; i < n ; i++){
            sb.append(dist[i] + "\n");
        }

        System.out.println(sb);
    }
}


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

int main(){
    /*
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    */

   int k;
   cin >> k;
   int x = 7%k;
   set<int> s;
   int i = 1;
   while (s.count(x) == 0){
       if ( x == 0){
           cout << i << endl;
           return 0;
       }
       s.insert(x);
       x = (x*10+7)%k;
       ++i;
   }
   cout << -1 << endl;
   return 0;
}

Measured memory_bytes: 50504
n, m = map(int, input().split(" "))
number = [[] for _ in range(n)]
height = list(map(int, input().split(" ")))
result = 0
for i in range(0, m):
    a, b = map(int, input().split(" "))
    number[b - 1].append(a - 1)
    number[a - 1].append(b - 1)
for i in range(0, n):
    if (len(number[i]) == 0):
        result += 1
    else:
        sig = 1
        for k in number[i]:
            if (height[i] <= height[k]):
                sig = 0
                break
        if sig == 1:
            result+=1
print(result)

Measured memory_bytes: 30892
#include<stdio.h>
int main(){
	int n,i,a[1000];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=n-1;i>0;i--)printf("%d ",a[i]);
	printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
  int a,b,c;cin >> a >> b;
  c=a+b;
  if(c%2 == 1){
    cout << (c+1)/2 << endl;
  }else{
    cout << c/2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

int main()
{
		int a, b, c;
		std::cin >> a >> b >> c;
		int i, count=0;
		for(i=a; i<b+1; i++) {
				if(c % i == 0) {
						count++;
				}
		}
		std::cout << count << std::endl;
		return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int
lli dp[3005][3005] = {};

void solve(long long N, long long T, std::vector<long long> A,
           std::vector<long long> B)
{
  lli ret = 0;
  vector<pair<int, int>> v;
  rep(i, N) v.emplace_back(A[i], B[i]);
  sort(v.begin(), v.end());
  rep(i, N) A[i] = v[i].first, B[i] = v[i].second;

  rep(i, N) rep(j, T)
  {
    chmax(dp[i + 1][j], dp[i][j]);
    if (j + A[i] < T)
    {
      chmax(dp[i + 1][j + A[i]], dp[i][j] + B[i]);
    }
    else
    {
      chmax(ret, dp[i][j] + B[i]);
    }
    chmax(ret, dp[i][j]);
  }
  cout << ret << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  long long T;
  scanf("%lld", &T);
  std::vector<long long> A(N);
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, T, std::move(A), std::move(B));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

int n, a, b;
string s;

void read() {
  cin >> n >> a >> b;
  cin >> s;
}

void kill() {
  int cur = 0;
  int ov = 0;
  for (char c : s) {
    bool ans = false;
    if (c == 'c')
      ans = false;
    else if (c == 'a') {
      if (cur < a + b) {
        ++cur;
        ans = true;
      } else {
        ans = false;
      }
    } else if (c == 'b') {
      if (cur < a + b && ov < b) {
        ans = true;
        cur++;
      } else {
        ans = false;
      }
      ++ov;
    }

    cout << (ans ? "Yes\n" : "No\n");
  }


}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 848
N, K = map(int, input().split())
p = list(map(int, input().split()))

res = 0

for k in range(K):
    t = p[0]
    c = 0
    for i in range(len(p)):
        if t > p[i]:
            t = p[i]
            c = i

    res += p.pop(c)

print(res)


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

using namespace std;

#define pb            push_back
#define mp            make_pair
#define po            pop_back
#define fi            first
#define se            second
#define mxn           100005
#define ll            long long int
#define ldb           long double
#define fr(i,a,b,k)   for(int i=a ; i<b ; i+=k)
#define frr(i,a,b,k)  for(int i=a ; i>b ; i-=k)
#define all(v)        v.begin(),v.end()
#define endl          "\n"
#define deg(x)        cout<<endl<<#x<<" = "<<(x)<<endl;
#define casep(x)      cout<<"Case #"<<(x)<<": ";
#define fast          ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef pair<int,int> pp;
typedef vector<int> vi;
typedef vector<pp> vpp;
typedef vector<vi> vvi;

const ll inf = LLONG_MAX;

ll power_mod(int a, int n, int mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
ll power(ll a,ll n){if(n==0){return 1;}ll p=power(a,n/2);p = (p * p);if (n%2==1){p=(p*a);}return p;}
int gcd(int a,int b){ return __gcd(a,b);}
int lcm(int a,int b){return a*b/__gcd(a,b);}
vector<vector<int>> adj;
bool vis[mxn];

void run(ll test){

    ll d,t,s;
    cin >> d >> t >> s;

    string res = (s*t < d)?"No":"Yes";
    cout << res;
}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        run(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((abs(b-a)<=d&&abs(c-b)<=d)||abs(a-c)<=d){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N;
int cnt[10][10];

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

    cin >> N;
    FOR (i, 1, N + 1) {
        string s = to_string(i);
        cnt[s.front() - '0'][s.back() - '0']++;
    }
    int ans = 0;
    FOR (i, 1, 10) FOR (j, 1, 10) {
        ans += cnt[i][j] * cnt[j][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
i = 0
input_null = 0
input_list = []

n = 10 #input個数
while i < n:
    input_list.append(int(input()))
    #print(input_list[i])
    i += 1
    
sort_input_list = sorted(input_list,reverse=True)

j = 0

while j < 3:
    print(sort_input_list[j])
    j += 1


Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, kk;
	cin >> nn >> kk;
	if(nn % kk == 0)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const long long max_n=100010;
long long n,c[max_n];
vector<pair<long long,long long> > t[max_n];
void dfs(long long b,long long previous=-1){
	for (auto it: t[b]){
		long long a=it.first;
		long long d=it.second%2;
		if (a!=previous){
			c[a]=c[b]^d;
			dfs(a,b);
		}
	}
}
int main()
{
	cin>>n;
	for (int i=0;i<n-1;++i){
		long long a,b,d;
		cin>>a>>b>>d;
		t[a].push_back({b,d});
		t[b].push_back({a,d}); 
	}
	dfs(1);
	for (int i=1;i<=n;++i)
	    cout<<c[i]<<endl;
}

Measured memory_bytes: 10240
import sys
input = sys.stdin.readline

# B - Path
route = []

for i in range(3):
	a, b = map(int, input().split())	
	route.append(a)
	route.append(b)

count = 0

for i in range(1, 5):
	if route.count(i) >= 2:
		count += 1

if count >= 2:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

const ll MOD = 1e9 + 7;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

void mainsolve(){

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

	ll res = 0;

	vector<ll> cuminv(n+1);
	rep(i,n) cuminv[i+1] = (cuminv[i] + modinv(i+1,MOD) ) % MOD;

	rep(i,n-1){
		(res += ((a[i+1] - a[i]) * cuminv[i+1] ) % MOD) %= MOD;
	}
 
	rep(i,n-1) (res *= i+1) %= MOD;
	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

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

int main() {
  string str;
  cin >> str;
  int res = 1000;
  for (int i = 0; i + 2 < str.size(); ++i) {
    string sub = str.substr(i, 3);
    int num = 0;
    for (int j = 0; j < 3; ++j) num *= 10, num += sub[j]-'0';
    res = min(res, abs(num - 753));
  }
  cout << res << endl;
}
              
    

Measured memory_bytes: 256
def pow(m, n, mod):
    if n == 0:
        return 1
    elif n == 1:
        return m
    if n % 2 == 0:
        return pow(m, n // 2, mod) ** 2 % mod
    else:
        return pow(m, n // 2 + 1, mod) * pow(m, n // 2, mod) % mod




m, n = map(int, input().split())
mod = 10 ** 9 + 7

print(pow(m, n, mod))



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int main(){
	int n;
	while(cin>>n,n){
		char conv[1000]={};
		REP(i,n){
			char from,to;
			cin>>from>>to;
			conv[from]=to;
		}
		int m;
		cin>>m;
		REP(i,m){
			char c;
			cin>>c;
			if(conv[c]==0){
				printf("%c",c);
			}else{
				printf("%c",conv[c]);
			}
		}
		printf("\n");
	}

}

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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

/*bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // __gcd(0,0) gives exception

const int MAX_N = 1234;

int main(){
    int N,x,n;
    map<int,int> M;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&x);
        M[x]++;
    }
    int m;
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%d",&x);
        if(M.find(x)!=M.end() && M[x]!=0){
            M[x]--;
        }
        else{
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000
#define PI 3.141592653589793

int main() {
	string s, t, ans = "No";
	cin >> s >> t;

	if (t.substr(0, s.size()) == s) ans = "Yes";

	cout << ans;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

int b[100001];

void solve()
{
    int N;
    cin >> N;
    vector<int> a(N);
    int min_a = 1e8;
    int max_a = 0;

    REP0(i, N)
    {
        int a;
        cin >> a;
        b[a]++;
        min_a = min(min_a, a);
        max_a = max(max_a, a);
    }
    int ans = 0;
    FOR(i, min_a, max_a + 1)
    {
        ans = max(ans, b[i - 1] + b[i] + b[i + 1]);
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

double n, d;
signed main() {
	cin >> n >> d;
	cout << ceil(n / (2.0 * d + 1.0)) << endl;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	map<int, int> a;
	rep(i, n){
		int tmp;
		cin >> tmp;
		if(a.count(tmp)){
			a.at(tmp)++;
		}else{
			a[tmp] = 1;
		}
	}
	vector<int> s;
	for(auto t: a){
		int tmp = t.second;
		s.push_back(tmp);
	}
	sort(all(s));
	int ans = 0;
	if(s.size() > k){
		for(int i = 0; i < s.size()-k; i++){
			ans += s[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

ll n, k;
ll ans = 0;
VV G;

int dfs(int u, int p) {
  int res = 0;
  for (auto &v : G[u]) {
    chmax(res, dfs(v, u));
  }
  ++res;
  if (res == k && p != 0) {
    ++ans;
    res = 0;
  }
  return res;
}


int main() {
  cin >> n >> k;
  G.assign(n, V());

  rep(i, n) {
    int x; cin >> x;
    --x;
    if (i == 0) {
      if (x != 0) ++ans;
      continue;
    }
    G[x].push_back(i);
  }

  dfs(0, 0);

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


Measured memory_bytes: 10368
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;

    if(s.at(0)=='7' || s.at(1)=='7' || s.at(2)=='7')
    {
        cout<<"Yes"<<endl;
    }

    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


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

void solve(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
      cout<<"Yes";
    else
    cout<<"No";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main()
{
  string s;
  ll k;
  cin>>s>>k;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='1') cnt++;
    else break;
  }
  if(cnt>=k){
    cout<<1;
  }
  else cout<<s[cnt];
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
dp = [[0]*3 for _ in range(n+5)]
t = n%2
for i in range(n):
    dp[i][0] = dp[i-2][0] + a[i]
    dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + a[i]
    if t:
        dp[i][2] = max(dp[i-2][2], dp[i-3][1], dp[i-4][0]) + a[i]
if t:
    print(max(dp[n-3][0], dp[n-2][1], dp[n-1][2]))
else:
    print(max(dp[n-2][0], dp[n-1][1]))


Measured memory_bytes: 66404
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y
from math import ceil

for _ in range(int(input()) if not True else 1):
    n = int(input())
    a = list(map(int, input().split()))
    cur = a[0]
    ans=0
    for i in range(1, n):
        if a[i] >= cur:
            cur = a[i]
            continue
        ans += cur - a[i]
    print(ans)

Measured memory_bytes: 95796