akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    vs32 v(3);
    cin >> v[0] >> v[1] >> v[2];

    int ans = 0;
    while (v[0] != v[1] || v[1] != v[2] || v[2] != v[0])
    {
        sort(v.begin(), v.end());
        if (v[2] - v[0] > 1)
        {
            ans += (v[2] - v[0]) / 2;
            v[0] += (v[2] - v[0]) / 2 * 2;
        }
        else if (v[2] - v[0] == 1)
        {
            if (v[1] == v[2])
            {
                ans += 2;
                v[0] += 1;
            }
            else
            {
                ans += 1;
                v[2] -= 1;
            }
        }
    }

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



Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int n=s.size()-2;
    while(n){
        if(s.substr(0,n/2)==s.substr(n/2,n/2)){
            cout<<n<<endl;
            return 0;
        }
        n-=2;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>


using namespace std;


int A[1000001];


void shell_sort(int A[], int N, int g, int *cnt)
{
    for (int i = g; i < N; i++) {
        int v, j;
        v = A[i];
        j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            (*cnt)++;
        }
        A[j + g] = v;
    }
}


int main(void)
{
    vector<int> G;

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

    G.push_back(1);
    for (int g = 4; g < N; g = 3 * g + 1)
        G.push_back(g);

    int cnt = 0;
    for (int i = G.size() - 1; i >= 0; i--)
        shell_sort(A, N, G[i], &cnt);

    cout << G.size() << endl;
    for (int i = G.size() - 1; i > 0; i--)
        cout << G[i] << " ";
    cout << G[0] << endl;
    cout << cnt <<endl;

    for (int i = 0; i < N; i++)
        cout << A[i] << endl;

    return 0;
}



Measured memory_bytes: 6992
//52
#include<iostream>

using namespace std;

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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio;
    int n,l;
    cin>>n>>l;
    vector<string> v1;
    string s1;
    loop(i,0,n)
    {
        cin>>s1;
        v1.pb(s1);
    }
    SORT(v1);
    loop(i,0,n)
    cout<<v1[i];
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3616
import collections
n = int(input())
*a, = map(int, input().split())

c = collections.Counter(a)
for k, v in c.items():
    if n%2 == 0:
        if v != 2:
            print(0)
            quit()
    else:
        if k != 0 and v != 2 or k == 0 and v != 1:
            print(0)
            quit()

print(2**(n//2)%(10**9+7))


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

int main() {
	// your code goes here
	int n[6],a=0,b=0,c=0,d=0;
	for(int i=0;i<6;i++)
	{
	    cin>>n[i];
	    switch(n[i])
	    {
	        case 1:a++;break;
	        case 2:b++;break;
	        case 3:c++;break;
	        case 4:d++;break;
	    }
	}
	if(a>0 && a<3 && b>0 && b<3 && c>0 && c<3 && d>0 && d<3)
	{
	    cout<<"YES";
	}
	else
	{
	    cout<<"NO";
	}
	return 0;
}


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

int main(){

    int n;
    cin>>n;
    set<int> chair;
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        for(int i=l;i<=r;i++){
            chair.insert(i);
        }
    }
    cout<<chair.size()<<endl;


    return 0;
}

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

const int N = (20) + 5;
int v[N], c[N];
int n;

// claudio van
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &v[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &c[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += max(v[i] - c[i], 0);
  }
  printf("%d\n", ans);
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1') {
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }


void main(){
	auto n = read.to!long;
	auto q = read.to!long;
	
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	debug writeln("as: ", as);
	
	long[] bs;
	foreach_reverse(a; as) bs ~= a;
	debug writeln("bs: ", bs);
	
	long[] sums;
	foreach(i; 0 .. n){
		if(i == 0) sums ~= bs[i];
		else sums ~= sums[$ - 1] + bs[i];
	}
	debug writeln("sums: ", sums);
	
	long[] evensums;
	for(int i = 0; i * 2 < n; i ++){
		if(i == 0) evensums ~= bs[i * 2];
		else evensums ~= evensums[$ - 1] + bs[i * 2];
	}
	debug writeln("evensums: ", evensums);
	long evensum = evensums[$ - 1];
	debug writeln("evensum: ", evensum);
	
	long[] cs;
	for(int i = 0; i * 2 < n; i ++) cs ~= bs[i] + bs[i * 2];
	debug writeln("cs: ", cs);
	
	foreach(t; 0 .. q){
		auto x = read.to!long;
		auto i = uplimit(0, (n - 1) / 2, i => (x * 2 <= cs[i]));
		if(i < 0) i = 0;
		debug writeln("x: ", x, " i: ", i);
		auto ans = sums[i] + evensum - evensums[i];
		ans.writeln;
	}
	
}


// fをみたす最大(二分探索; binary search)
long uplimit(long a, long c, bool delegate(long) f){
	if(f(c)) return c;
	if(! f(a)) return a - 1;
	while(a + 1 < c){
		long b = (a + c) / 2;
		if(f(b)) a = b;
		else c = b;
	}
	return a;
}


Measured memory_bytes: 11812
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] a = Console.ReadLine().Split(" ").Select(x => decimal.Parse(x)).OrderByDescending(x => x).ToArray();
            decimal res;
            res = Math.Floor(a[0] * a[1]);
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 28516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	ll a,b,c;
	cin>>a>>b>>c;
	if(c-a-b<=0) {
		cout<<"No"<<endl;
		return 0;
	}
	ll r=(c-a-b)*(c-a-b);
	ll l=4*a*b;
	if(l<r){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;


}

Measured memory_bytes: 256
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0 || i % 5 == 0) {
                continue;
            }
            ans += i;
        }
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 25788
#include<bits/stdc++.h>
using namespace std;
int n,m;
bitset<300005>BIT;
int main()
{
	scanf("%d %d",&n,&m);
	n=n*2-1;
	if(m==n||m==1)printf("No");
	else
	{
		printf("Yes\n");
		if(m==(n/2)+1)
		{
			for(int i=1;i<=n;i++)printf("%d\n",i);
		}
		else if(m<(n/2)+1)
		{
			BIT[1]=true,BIT[m]=true,BIT[m+1]=true,BIT[m+2]=true;
			for(int i=1;i<=(n/2)+2;i++)if(!BIT[i])printf("%d\n",i);
			printf("%d\n1\n%d\n%d\n",m+1,m,m+2);
			for(int i=(n/2)+3;i<=n;i++)if(!BIT[i])printf("%d\n",i);
		}
		else
		{	
			BIT[n]=true,BIT[m]=true,BIT[m-1]=true,BIT[m-2]=true;
			for(int i=1;i<=(n/2)-2;i++)if(!BIT[i])printf("%d\n",i);
			printf("%d\n%d\n%d\n%d\n",m-1,n,m,m-2);
			for(int i=(n/2)-1;i<=n;i++)if(!BIT[i])printf("%d\n",i);
			
		}
	}
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
	long long n,i;
	vector< pair <long long int,long long int> > vect;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>arr[i];
		arr1[i]=i+1;
	}
	for (int i=0; i<n; i++) 
    {vect.push_back( make_pair(arr[i],arr1[i]) ); }
    sort(vect.begin(),vect.end());
    for (i=0;i<n;i++)
    {
    	cout<<vect[i].second<<" ";
	}
	cout<<endl;
}

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

int main(){
    char chara ;
    cin >> chara ;
    if( chara == 'a' || chara == 'e' || chara == 'i' || chara == 'o' || chara == 'u'  )
        cout << "vowel" << endl ;
    else
        cout << "consonant" << endl ;
    return 0;


}

Measured memory_bytes: 256
program main
  implicit none
  integer(8) :: n, s, sqrt_n, b, p
  read(*, *) n
  read(*, *) s

  if (n < s) then
    write(*, "(i0)") -1
    stop 0
  else if (n == s) then
    write(*, "(i0)") n + 1
    stop 0
  end if

  sqrt_n = integer_sqrt(n)

  do b = 2, sqrt_n
    if (f(b, n) == s) then
      write(*, "(i0)") b
      stop 0
    end if
  end do

  do p = sqrt_n, 1, -1
    b = (n - s) / p + 1
    if (b >= 2) then
      if (f(b, n) == s) then
        write(*, "(i0)") b
        stop 0
      end if
    end if
  end do

  write(*, "(i0)") -1

  contains

  function integer_sqrt(n)
    implicit none
    integer(8), intent(in) :: n
    integer(8) :: integer_sqrt, i
    if (n < 0) stop 101
    do i = 0, n + 1
      if (i ** 2 > n) then
        integer_sqrt = i - 1
        exit
      end if
    end do
  end function integer_sqrt

  recursive function f(b, n) result(res)
    implicit none
    integer(8), intent(in) :: b, n
    integer(8) :: res
    if (n < b) then
      res = n
    else
      res = f(b, n / b) + mod(n, b)
    end if
  end function f
end program main


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, k, i, ans;
    cin >> n >> k;
    ans = n;
    vll a(k);
    for(i = 0; i < k; i++)
        cin >> a[i];
    sort(all(a));
    while(1)
    {
        ll x = ans;
        bool p = true;
        while(x && p)
        {
            ll y = x % 10;
            x /= 10;
            if(binary_search(all(a), y))
                p = false;
        }
        if(p)
            break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a + b == 15){
			System.out.println("+");
		}
		else if(a * b == 15){
			System.out.println("*");
		}
		else {
			System.out.println("x");
		}
	}

}


Measured memory_bytes: 21844
#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<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define int long long
//#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;


signed main(){
	
	int n;
	string s[4];
	cin>>n;
	int ans=0;
	for(int i=0;i<3;i++)cin>>s[i];
	for(int i=0;i<n;i++){
		int count[26]={0};
		for(int j=0;j<3;j++){
			count[s[j][i]-'a']++;
		}
		sort(count,count+26);
		ans+=3-count[25];
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
a,b,c = gets.split.map(&:to_i)
ans = 0
if a == b && b == c && a.even?
  puts -1
  exit
end
while a.even? && b.even? && c.even?
  a,b,c = (b+c)/2,(c+a)/2,(a+b)/2
  ans += 1
end
puts ans

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

int main(){
    int N, X;
    cin >> N >> X;
    int L[N];
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    int current_d = 0;
    int count = 1;

    for (int i = 1; i < N + 1;i++)
    {
        current_d = current_d + L[i - 1];
        if(current_d <= X){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
function main(input) {
  	var firstNumber = input.split(' ')[0]
    var secondNumber = input.split(' ')[1]
    if(firstNumber%2 == 0 || secondNumber%2 == 0){
      console.log('Even')
    } else {
      console.log('Odd')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21936
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n; cin >> n;
	ll ans = 1;
	for (int i = 0; i <= sqrt(n); i++) {
		if (i * i <= n) {
			ans = pow(i, 2);
		}
	}
	cout << ans << endl;
}

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

int main() {
  int n; cin >> n;
  ll ans = 1;
  REP(i,n) ans = (ans * (i+1)) % 1000000007;
  cout << ans << endl;
  return 0;
}

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

int main(){
  int K, N;
  cin >> N >> K;
  vector<double> P(N);
  for(int i=0; i<N; i++){
    cin >> P[i];
    P[i]=P[i]*(P[i]+1)/2/P[i];
  }
  double m=0;
  for(int i=0; i<K; i++){
    m+=P[i];
  }
  vector<double> S(N-K+1,0);
  for(int i=0; i<K; i++){
    S[0]+=P[i];
  }
  for(int i=1; i<=N-K; i++){
    S[i]=S[i-1]-P[i-1]+P[i-1+K];
  }
  sort(S.begin(),S.end(),greater<double>());
  cout << setprecision(10) << S[0] << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=1e9+9;
int ans=inf;
string s;
int32_t main()
{
  BOOST;
  cin>>s;
  int n=sz(s);
  for (int i=0;i<n-1;i++) if (s[i]!=s[i+1])ans=min(ans,max(i+1,n-i-1));
  ans=min(ans,n);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 512
import copy
s = list(input())
ans = len(s) // 2
if ("".join(s) == s[0]*len(s)):
  ans = 0
for i in range(97, 97+26):
  c = chr(i)
  c_s = copy.copy(s)
  cnt = 0
  for j in range(len(s)-1):
    cnt += 1
    for k in range(len(s)-1-j):
      if (c_s[k] == c or c_s[k+1] == c):
        c_s[k] = c
    l = len(s)-1-j
    if (c*l == "".join(c_s[:l])):
      ans = min(ans,cnt)
print(ans)



Measured memory_bytes: 41788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc119B();
    }
}
class Calc{
void abc119B() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double money = 0;
		for(int i=0 ; i<n ; i++) {
			double y = sc.nextDouble();
			String s = sc.next();
			switch(s) {
			case("JPY"):money += y;
                break;
			case("BTC"):money += y * 380000;
                break;
			}
		}
		System.out.println(money);
	}
}

Measured memory_bytes: 24532
# frozen_string_literal: true

loop do
  line = readline.split(' ')
  a = line[0].to_i
  op = line[1]
  b = line[2].to_i
  break if op == '?'

  puts case op
       when '+'
         a + b
       when '-'
         a - b
       when '*'
         a * b
       when '/'
         a / b
  end
end



Measured memory_bytes: 6884
package main

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

const nothing = math.MaxInt64

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)
	nEdges := scanInt(sc)

	d := make([][]int, nNodes)

	for i := 0; i < nNodes; i++ {
		d[i] = make([]int, nNodes)
		for j := 0; j < nNodes; j++ {
			if i == j {
				d[i][j] = 0
			} else {
				d[i][j] = nothing
			}
		}
	}

	for i := 0; i < nEdges; i++ {
		from := scanInt(sc)
		to := scanInt(sc)
		cost := scanInt(sc)
		d[from][to] = cost
	}

	floyd(d)

	if hasNegativeCycle(d) {
		fmt.Println("NEGATIVE CYCLE")
	} else {
		w := bufio.NewWriter(os.Stdout)
		for _, costs := range d {
			for ic, c := range costs {
				if ic > 0 {
					fmt.Fprint(w, " ")
				}
				if c == nothing {
					fmt.Fprint(w, "INF")
				} else {
					fmt.Fprint(w, c)
				}
			}
			fmt.Fprintln(w)
		}
		w.Flush()
	}
}

func floyd(d [][]int) {
	n := len(d)

	// i -> j について、 0~k までのノードのみを経由可能とした場合に
	// コストが最小となる経路のコストを d[i][j] にセットしていく。
	// 0~k の経路を使う最小コストを基に 0~k+1 の経路を使う最小コストを求めていく。
	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			if d[i][k] == nothing {
				continue
			}
			for j := 0; j < n; j++ {
				if d[k][j] == nothing {
					continue
				}
				d[i][j] = min(
					// k を経由する場合
					d[i][j],
					// k を経由しない場合
					d[i][k]+d[k][j],
				)
			}
		}
	}
}

func hasNegativeCycle(d [][]int) bool {
	for i := 0; i < len(d); i++ {
		if d[i][i] < 0 {
			return true
		}
	}
	return false
}

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

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}



Measured memory_bytes: 1496
# 17D8103013C miukou42 python3

n,k=map(int,input().split())
w=[int(input()) for i in range(n)]

def binarySearch(left,right):
    mid=0
    while right>left:
        mid=int(left+(right-left)//2)
        if check(mid,w,k):
            right=mid
        else:
            left=mid+1
    return left

def check(p,w,k):
    k_tmp=1
    w_tmp=0
    for w_i in w:
        w_tmp+=w_i
        if w_tmp>p:
            w_tmp=w_i
            k_tmp+=1
            if k_tmp>k:
                return False
    return True

print(binarySearch(max(w),sum(w)))



Measured memory_bytes: 9580
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
	ll n,k;
	cin >> n >> k;
	vector<ll> arr(n);
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(),arr.end());

	ll ans = 1LL<<50LL;
	for(int i = k-1; i < n; i++) {
		ans = min(ans,arr[i]-arr[i-k+1]);
	}

	cout << ans << endl;
	return 0;
}


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

using namespace std;

int gcd(int a, int b){
  if(b > a){
    a ^= b;
    b ^= a;
    a ^= b;
  }
  
  int r = a % b;
  while(r > 0){
    a = b;
    b = r;
    r = a % b;
  }
  
  return b;
}

int main(){
  int n, x; cin >> n >> x;
  vector<int> x_dst(n);
  for(int i = 0; i < n; i++){
    int y; cin >> y;
    x_dst[i] = abs(y - x);
  }
  
  int g = x_dst[0];
  for(int i = 1; i < n; i++) g = gcd(x_dst[i], g);
  
  cout << g << endl;
  
  return 0;
}

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

typedef long long ll; 

int main()
{
    ll n;
    cin>>n;
    ll h[n];
    for(ll i=0 ; i<n ; i++)cin>>h[i];
    ll dp[n+1]={0};
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    dp[2]=min(dp[1]+abs(h[2]-h[1]),dp[0]+abs(h[2]-h[0]));
    for(ll i=3 ; i<n ; i++)
    {
        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];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	auto ans = "hon";
	auto i = N % 10;
	switch (i)
	{
	case 3:
		ans = "bon";
		break;

	case 0:
	case 1:
	case 6:
	case 8:
		ans = "pon";
		break;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


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

    int a, b;
    cin >> a >> b;
    cout<< a + (b/ 2) << endl;


    return 0;
}


Measured memory_bytes: 3612
from sys import stdin
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + [int(stdin.readline()) for _ in range(A)]+[INF]
T = [-INF] + [int(stdin.readline()) for _ in range(B)]+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(input())  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


Measured memory_bytes: 14056
import random
import math
N = int(input())
XY = []
for i in range(N):
    XY.append(list(map(int,input().split())))

def make_circle(points):
	# Convert to float and randomize order
	shuffled = [(float(x), float(y)) for (x, y) in points]
	random.shuffle(shuffled)
	
	# Progressively add points to circle or recompute circle
	c = None
	for (i, p) in enumerate(shuffled):
		if c is None or not is_in_circle(c, p):
			c = _make_circle_one_point(shuffled[ : i + 1], p)
	return c

# One boundary point known
def _make_circle_one_point(points, p):
	c = (p[0], p[1], 0.0)
	for (i, q) in enumerate(points):
		if not is_in_circle(c, q):
			if c[2] == 0.0:
				c = make_diameter(p, q)
			else:
				c = _make_circle_two_points(points[ : i + 1], p, q)
	return c

# Two boundary points known
def _make_circle_two_points(points, p, q):
	circ = make_diameter(p, q)
	left  = None
	right = None
	px, py = p
	qx, qy = q
	
	# For each point not in the two-point circle
	for r in points:
		if is_in_circle(circ, r):
			continue
		
		# Form a circumcircle and classify it on left or right side
		cross = _cross_product(px, py, qx, qy, r[0], r[1])
		c = make_circumcircle(p, q, r)
		if c is None:
			continue
		elif cross > 0.0 and (left is None or _cross_product(px, py, qx, qy, c[0], c[1]) > _cross_product(px, py, qx, qy, left[0], left[1])):
			left = c
		elif cross < 0.0 and (right is None or _cross_product(px, py, qx, qy, c[0], c[1]) < _cross_product(px, py, qx, qy, right[0], right[1])):
			right = c
	
	# Select which circle to return
	if left is None and right is None:
		return circ
	elif left is None:
		return right
	elif right is None:
		return left
	else:
		return left if (left[2] <= right[2]) else right

def make_diameter(a, b):
	cx = (a[0] + b[0]) / 2.0
	cy = (a[1] + b[1]) / 2.0
	r0 = math.hypot(cx - a[0], cy - a[1])
	r1 = math.hypot(cx - b[0], cy - b[1])
	return (cx, cy, max(r0, r1))


def make_circumcircle(a, b, c):
	# Mathematical algorithm from Wikipedia: Circumscribed circle
	ox = (min(a[0], b[0], c[0]) + max(a[0], b[0], c[0])) / 2.0
	oy = (min(a[1], b[1], c[1]) + max(a[1], b[1], c[1])) / 2.0
	ax = a[0] - ox;  ay = a[1] - oy
	bx = b[0] - ox;  by = b[1] - oy
	cx = c[0] - ox;  cy = c[1] - oy
	d = (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) * 2.0
	if d == 0.0:
		return None
	x = ox + ((ax*ax + ay*ay) * (by - cy) + (bx*bx + by*by) * (cy - ay) + (cx*cx + cy*cy) * (ay - by)) / d
	y = oy + ((ax*ax + ay*ay) * (cx - bx) + (bx*bx + by*by) * (ax - cx) + (cx*cx + cy*cy) * (bx - ax)) / d
	ra = math.hypot(x - a[0], y - a[1])
	rb = math.hypot(x - b[0], y - b[1])
	rc = math.hypot(x - c[0], y - c[1])
	return (x, y, max(ra, rb, rc))


_MULTIPLICATIVE_EPSILON = 1 + 1e-14

def is_in_circle(c, p):
	return c is not None and math.hypot(p[0] - c[0], p[1] - c[1]) <= c[2] * _MULTIPLICATIVE_EPSILON


# Returns twice the signed area of the triangle defined by (x0, y0), (x1, y1), (x2, y2).
def _cross_product(x0, y0, x1, y1, x2, y2):
	return (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0)

x = make_circle(XY)
print(x[-1])

Measured memory_bytes: 4080
MOD = 1000000007

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

cnt = [-1, -1, -1]
ans = 1
for a in A:
    num = 0
    i = -1
    for j in range(3):
        if a == cnt[j] + 1:
            num += 1
            i = j
    if num == 0:
        ans = 0
        break
    ans *= num
    ans %= MOD
    cnt[i] = a

print(ans)


Measured memory_bytes: 14056
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;
            int currentmax = 0;

            for (int i = 0; i < n; i++) {
                if (h[i] >= currentmax) ++ans;
                if (h[i] > currentmax) currentmax = h[i];
            }
            // 出力
            out.println(ans);

        }

    }
}



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

int main(){
    ll n; cin >> n;
    vector<vector<ll>> r(n, vector<ll>(26,0));
    rep(i, 0, n){
        string s;
        cin >> s;
        for(auto c : s){
            r[i][c-'a']++;
        }
    }
    vector<ll> mns(26, 1e9);
    rep(i, 0, 26){
        rep(j, 0, n){
            mns[i] = min(mns[i], r[j][i]);
        }
    }

    rep(i, 0, 26){
        rep(j, 0, mns[i]){
            cout << (char)(i+'a');
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        String op = sc.next();
        int B = sc.nextInt();

        if (op.equals("+")){
            System.out.println(A+B);
        }
        else{
            System.out.println(A-B);
        }
        sc.close();
    }
}

Measured memory_bytes: 23764
#これはBFSの練習である。なので記述を丁寧に行う

from collections import deque

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

#今後座標を記述する際に(y,x)の順であることに気を付ける

dy,dx=[1,0,-1,0],[0,1,0,-1]
#すべての地点をスタート位置からの距離infとして初期化する
d=[[float("inf") for i in range(w)] for j in range(h)] 
d[0][0]=0 #スタート位置はスタート位置からの距離0
queue=deque([]) 
queue.append([0,0]) #まず初めに、スタート地点をqueueに入れる

#ここから
while len(queue): #queueが空になるまで操作を行う
    p=queue.popleft() #queueの先頭を取り出す
    if p==[h-1,w-1]: break #取り出したものがゴールなら、探索終了
    for i in range(4): #調べているマスの上下左右4方向の状態を調べる
        ny=p[0]+dy[i]
        nx=p[1]+dx[i]
        #そのマスが移動可能、かつ訪れたことがあるかを判定する
        if (0<=ny<h and 0<=nx<w and s[ny][nx]=="." and d[ny][nx]==float("inf")):
            queue.append([ny,nx]) #訪れたことがないならqueueに追加
            d[ny][nx]=d[p[0]][p[1]]+1 #訪れたことがないなら移動前の地点の距離+1で確定
#ここまでがBFS(この問題の主要部)

if d[h-1][w-1]==float("inf"): #ゴールにたどり着けないのならば
    print(-1)
else: #たどり着けたのならば
    tot=0
    for i in range(h): # "#"がいくつあるか数える
        for j in range(w):
            if s[i][j]=="#": tot+=1
    print(h*w-((d[h-1][w-1]+1)+tot))

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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll N;
vector<vector <ll>> nbr;

void farthest(ll ref, ll here, ll& node, ll& dist) {
  DLOG("farthest %lld %lld\n", ref, here);
  ll cmax = -1;
  ll cmaxarg;
  for (ll c : nbr.at(here)) {
    if (c == ref)  continue;
    ll nd;
    ll dt;
    farthest(here, c, nd, dt);
    if (cmax < dt) {
      cmax = dt;
      cmaxarg = nd;
    }
  }
  if (cmax == -1) {
    node = here;
    dist = 0;
  }else {
    node = cmaxarg;
    dist = cmax + 1;
  }
  DLOG("farthest %lld %lld ---> %lld %lld\n", ref, here, node, dist);
}

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  nbr.resize(N+1);
  for (ll i = 0; i < N-1; i++) {
    ll a, b;
    cin >> a >> b;
    nbr.at(a).push_back(b);
    nbr.at(b).push_back(a);
  }
  ll x, y, dist1, dist2;
  farthest(-1, 1, x, dist1);
  farthest(-1, x, y, dist2);
  DLOG("distance %lld\n", dist2);
  if ((dist2 + 2) % 3 == 0) {
    cout << "Second" << endl;
  }else {
    cout << "First" << endl;
  }

  return 0;
}



Measured memory_bytes: 29952
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vull = vector<ull>;
#define rep(i, n) for (ull i = 0; i < n; ++i)
#define rep1(i, n) for (ull i = 1; i < n; ++i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define pb push_back
#define fi first
#define se second
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

#define N_MAX 200005
vi E[N_MAX];
int tour[N_MAX*2],be[N_MAX],en[N_MAX];
int k=0;
void dfs(int v,int p){
  be[v]=k;
  tour[k]=v;
  k++;
  for(auto u:E[v]){
    if(u==p) continue;
    dfs(u,v);
    tour[k]=v;
    k++;
  }
  en[v]=k;
}

void solve() {
  // input
  int n,q; cin>>n>>q;
  rep(i,n-1) {
    int a,b; cin>>a>>b;
    a--; b--;
    E[a].pb(b); E[b].pb(a);
  }
  // Euler tour
  int root=0;
  dfs(root,-1);
  // imos
  int imos[N_MAX*2]={};
  rep(i,q){
    int p,x; cin>>p>>x;
    p--;
    imos[be[p]]+=x;
    imos[en[p]]-=x;
  }
  rep1(i,2*n){
    imos[i]+=imos[i-1];
  }
  rep(i,n) cout<<imos[be[i]]<<endl;
}

int main() {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 27392
def find(A):
    N = len(A)
    ans = [0]*N
    odd_sum = [0]*N
    even_sum = [0]*N
    for i in range(N):
        if i%2 == 0:
            if i-2>=0:
                even_sum[i] = even_sum[i-2] + A[i]
            else:
                even_sum[i] = A[i]
        else:
            if i-2>=0:
                odd_sum[i] = odd_sum[i-2] + A[i]
            else:
                odd_sum[i] = A[i]

#     print(odd_sum)
#     print(even_sum)
    for i in range(1,N):
        length = i+1
        if length%2==0:
            ans[i] = max(A[i] + ans[i-2],odd_sum[i-1]+even_sum[i-1] )
        else:
            ans[i] = max(A[i] + ans[i-2],ans[i-1])
            
    return ans[-1]
    
input()   
print(find(list(map(int,input().strip().split()))))

Measured memory_bytes: 94008
s = input()
n, p = len(s), 2019

ans = 0

d = {i:0 for i in range(p)}
d[0] = 1

ap = 1
if p not in [2, 5]:
    pre = 0
    for si in s[::-1]:
        si = int(si)
        a = (si * ap + pre) % p
        ans += d[a]
        d[a] += 1
        pre = a
        ap = (ap * 10) % p
else:
    for i, si in enumerate(s):
        if int(si) % p == 0:
            ans += i+1
print(ans)


Measured memory_bytes: 9440
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N,T;
  cin>>N>>T;
  vector<int> data(N);
  for (int i = 0; i < N; i++)
  {
    cin>>data[i];
  }
  int ANS = 0;

  int NEXT = -INF;
  for (int i = 0; i < N; i++)
  {
    if(NEXT > data[i])
    {
      ANS -= NEXT - data[i];
    }

    ANS += T;  
    NEXT = data[i] + T;

  }
  
  cout<<ANS<<endl;
  
  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t MOD = 1e9 + 7;

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

    vector<int> b(n, 0);
    rep(i, n)
    {
        int a;
        cin >> a;
        b[a]++;
    }

    int64_t result = 1;
    rep(i, n)
    {
        if (i % 2 == 0) {
            if ((n - 1) % 2 == 0) {
                result *= i == 0 ? (b[i] == 1 ? 1 : 0) : (b[i] == 2 ? 2 : 0);
            } else {
                result *= b[i] == 0 ? 1 : 0;
            }
        } else {
            if ((n - 1) % 2 == 0) {
                result *= b[i] == 0 ? 1 : 0;
            } else {
                result *= b[i] == 2 ? 2 : 0;
            }
        }
        result %= MOD;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	sum := 0.0
	for i := 0; i < N; i++ {
		var x float64
		fmt.Scan(&x)
		sum += 1.0 / x
	}

	fmt.Println(1.0 / sum)
}


Measured memory_bytes: 1768
import java.util.*;

public class Main {
  private static long INF = 1_000_000_000_000L;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int Q = sc.nextInt();
    
    long[] s = new long[A+2];
    s[0] = -INF;
    s[A+1] = INF;
    for (int i = 1; i <= A; i++) {
      s[i] = sc.nextLong();
    }
    
    long[] t = new long[B+2];
    t[0] = -INF;
    t[B+1] = INF;
    for (int i = 1; i <= B; i++) {
      t[i] = sc.nextLong();
    }
    
    for (int i = 0; i < Q; i++) {
      long x = sc.nextLong();
      int sr = search(s, x, 0, A+1);
      int tr = search(t, x, 0, B+1);
      long min = INF;
      min = Math.min(min, x-Math.min(s[sr-1], t[tr-1]));
      min = Math.min(min, Math.max(s[sr], t[tr])-x);
      min = Math.min(min, 2*(x-s[sr-1])+(t[tr]-x));
      min = Math.min(min, (x-s[sr-1])+2*(t[tr]-x));
      min = Math.min(min, 2*(x-t[tr-1])+(s[sr]-x));
      min = Math.min(min, (x-t[tr-1])+2*(s[sr]-x));
      
      System.out.println(min);
    }
  }
  
  private static int search(long[] a, long x, int l, int r) {
    
    if (a[l] < x && x < a[l+1]) {
      return l+1;
    }
    if (a[r-1] < x && x < a[r]) {
      return r;
    }
    
    int m = (l+r)/2;
    if (x < a[m]) {
      return search(a, x, l, m);
    } else {
      return search(a, x, m, r);
    }
  }
}

Measured memory_bytes: 96728
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    ll ans = 0;
    rep(i,N) ans += (ll)(i+1)*(N-i);
    rep(i,N-1) {
        ll u,v; cin >> u >> v;
        if (u > v) swap(u,v);
        ans -= u*(N+1-v);
    }

    cout << ans << ln;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;

int W,H;
string dp[71][71];
vector<string> f;

bool compare(const string& l, const string& r) {
	if (l.size() != r.size()) return l.size() < r.size();
	return l < r;
}

int main() {
	while(true) {
		cin >> W >> H;
		if (W == 0) break;
		f.clear();
		string line;
		for (int i = 0; i <= H; ++i) {
			if (i < H) cin >> line;
			f.push_back(line);
			for (int j = 0; j <= W; ++j) {
				dp[i][j].clear();
			}
		}
		string ans = "";
		for (int i = H-1; i >= 0; --i) {
			for (int j = W-1; j >= 0; --j) {
				char c = f[i][j];
				if ('0' <= c && c <= '9') {
					string base = "";
					if (compare(base, dp[i+1][j])) base = dp[i+1][j];
					if (compare(base, dp[i][j+1])) base = dp[i][j+1];
					dp[i][j] = c + base;
					if (c != '0' && compare(ans, dp[i][j])) ans = dp[i][j];
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1388
#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(i=1;i<=n;i++)
#define lopxy(i,x,y) for(i=x;i<y;i++)
#define ll long long
#define vl vector<long long>
#define pll pair<long long,long long>
#define sl set<long long>
#define uset unordered_set<long long>
#define umap unordered_map
#define prq priority_queue
#define pqll priority_queue<ll> 
#define hell 1000000007
#define mod 998244353
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define N 100000
#define N2 200000
#define bpc(x) __builtin_popcount(x)
#define inf 1e16
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<endl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
using namespace std;
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return (power(x, y / 2) * power(x, y / 2)) % mod;
    else
        return ((x * power(x, y / 2)) % mod * power(x, y / 2)) % mod;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;  
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little theorem. 
ll fac[N+1]; 
void pre(ll p){
    fac[0] = 1; 
    for (ll i=1 ; i<=N; i++) 
        fac[i] = (fac[i-1]*i)%p; 
}
ll nCrModPFermat(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
    if(r>n)
      return 0;
    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; 
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt.txt","r",stdin);
    freopen("output.txt.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
   
    ll n,i,ans=0;
    cin>>n;
    for(i=1;i<=n;i++){
        if(n%i!=0)
            ans+=n/i;
        else ans+=n/i-1;
    }
    cout<<ans;

    cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
    return 0;
}


Measured memory_bytes: 3652