akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

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

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

ll gcd(ll x,ll y){
    x = x%y;
    return x == 0 ? y : gcd(y,x);
}
ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}



int main(){
 
    int n,k;
    cin >> n >> k;
    double ans = 0;
    rep(i,n+1){
        if(i==0) continue;
        ll t = i;
        int count = 0;
        double tans = 1.0/n;
        while(t < k){
            t *= 2;
            tans /= 2;
        }
        ans += tans;
    }
    cout << setprecision(12) <<ans << endl;

    return 0;
}


Measured memory_bytes: 3156
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);

		String A = sc.next();
		String S = sc.next();
		String C = sc.next();

		String a = A.substring(0,1);
		String s = S.substring(0,1);
		String c = C.substring(0,1);

		System.out.println(a+s+c);
	}

}


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

int n;
int root=0;
vector<P> G[100005];
ll dist[100005];

int q,k;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		ll c;
		scanf("%d%d%lld",&a,&b,&c);
		a--;
		b--;
		G[a].push_back(P(b,c));
		G[b].push_back(P(a,c));
	}
	scanf("%d%d",&q,&k);
	k--;
	for(int i=0;i<n;i++){
		dist[i]=INF;
	}
	priority_queue<P,vector<P>,greater<P> > que;
	dist[k]=0;
	que.push(P(0,k));
	while(que.size()){
		P p=que.top();
		que.pop();
		if(p.first<dist[p.second])continue;
		int v=p.second;
		for(int i=0;i<G[v].size();i++){
			if(dist[G[v][i].first]>dist[p.second]+G[v][i].second){
				dist[G[v][i].first]=dist[p.second]+G[v][i].second;
				que.push(P(dist[G[v][i].first],G[v][i].first));
			}
		}
	}
	for(int i=0;i<q;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		printf("%lld\n",dist[a]+dist[b]);
	}
	return 0;
}

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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())

typedef long long ll;

using namespace std;

int main(){
  int n;
  double t, a;
  cin >> n >> t >> a;
  int best = -1;
  double bestA = 100000;

  rep(i, n){
    double h;
    cin >> h;
    double checkA = double(t) - 0.006*h;
    if(bestA > abs(a - checkA)){
      bestA = abs(a - checkA);
      best = i+1;
    }
  }
  cout << best << endl;

  return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=550;
//↑templete
int main() {
	int N;
	cin>>N;
	vint A,B,C;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		a--;
		A.pb(a);
	}
	for(int i=0;i<N;i++){
		int b;
		cin>>b;
		B.pb(b);
	}
	for(int i=0;i<N-1;i++){
		int c;
		cin>>c;
		C.pb(c);
	}
	ll ans=0;
	for(int i=0;i<N;i++){
		ans+=B[A[i]];
		//cout<<ans<<endl;
		if(i==0)
			continue;
		if(A[i-1]==A[i]-1)
			ans+=C[A[i-1]];
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;

int n,m;
bool visited[N];
vector<int>adj[N];

void dfs(int n)
{
    visited[n]=true;

    for(auto it: adj[n])
    if(!visited[it])
    dfs(it);
}

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

    while(m--)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    int ans=0;

    rep(i,1,n+1)
    {
        if(!visited[i])
        {   
            dfs(i);
            ans++;
        }
    }

    cout<<ans-1;
return 0;
}

Measured memory_bytes: 30716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer tHP = sc.nextInt();
		Integer tAT = sc.nextInt();
		Integer aHP = sc.nextInt();
		Integer aAT = sc.nextInt();

		while(tHP > 0 && aHP > 0) {
			aHP = aHP - tAT;
			tHP = tHP - aAT;
		}
		
		if(aHP <= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int main()
{
    string s,t;
    int wrong_counts = 0;

    cin >> s >> t;

    for (int i = 0; i < s.size(); i++)
    {
        if(s.at(i) != t.at(i))
        {
            wrong_counts++;
        }
    }

    cout << wrong_counts << endl;
    return 0;
}

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

bool num[15];

bool check(int x)
{
	while (x)
	{
		int t = x % 10;
		if (num[t]) return 0;
		x /= 10;
	}
	return 1;
}

int main()
{
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1, t; i <= k; i++)
	{
		cin >> t;
		num[t] = 1;
	}
	for (int i = n; ; i++)
	{
		if (check(i))
		{
			cout << i << endl;
			break; 
		} 
	}
	return 0;
}


Measured memory_bytes: 256
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
#define int long long
const int mod=1000000007;
//const int mod=5000000;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int Pow(int a,int b)
{
    int wynik=1;
    while(b)
    {
        if(b&1)
            wynik=(wynik*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return wynik;
}
const int r=500000;
int F[r+5];
int symbol(int a,int b)
{
    return ((F[a]*Pow(F[b],mod-2)%mod)*Pow(F[a-b],mod-2))%mod;
}
int funkcja(int a,int b)
{
    return (symbol(a,b)*F[b])%mod;
}
int32_t main()
{
    speed
    F[0]=1;
    for(int i=1;i<=r;i++)
        F[i]=(F[i-1]*i)%mod;
    int n,m;
    cin>>n>>m;
    int wynik=0;
    for(int i=0;i<=n;i++)
    {
        int aktual=symbol(n,i)*funkcja(m-i,n-i);
        aktual%=mod;
        if(i&1)
            aktual=-aktual;
        aktual+=mod;
        aktual%=mod;
        wynik+=aktual;
        wynik%=mod;
        //cout<<wynik<<endl;
    }
    //cout<<wynik<<endl;
    wynik*=funkcja(m,n);
    wynik%=mod;
    cout<<wynik;

    return 0;
}


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

int main() {
    long long a, b, k;
    cin >> a >> b >> k;

    if (k <= a) {
        cout << a-k << " " << b << endl;
    }
    else if (k <= a+b) {
        cout << 0 << " " << a+b-k << endl;
    }
    else {
        cout << "0 0" << endl;
    }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000007
int main(){
	
  long long int w=0,i=0,j=0,y=0,z=0,h=0;
  string a,b,out;
  cin >> h >> w;
  long long int m= a.size(),n =b.size();
  long long int dp[h+1][w+1];
  char arr[h+1][w+1];
  for(i=0;i<h;i++){
  	for(j=0;j<w;j++){cin >> arr[i][j];}
  }
  memset(dp,0,sizeof(dp));
  for(i=1;i<h;i++){
  	if(arr[i][0]=='.'){dp[i][0]=1;}
    else break;
  }
  for(i=0;i<w;i++){
  	if(arr[0][i]=='.'){dp[0][i]=1;}
    else break;
  }
  for(i=1;i<h;i++){
  	for(j=1;j<w;j++){
      if(arr[i][j]=='.') dp[i][j] = (dp[i][j-1]%inf+dp[i-1][j]%inf)%inf;
      //cout << dp[i][j]<<endl;
    }
  }
 cout << dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 9088
n,blue = map(int,input().split())
red = n-blue
mod = 10 ** 9 + 7

now = [1]
get = [1]
for i in range(1,red+2):
    next = []
    for j in range(min(i+1,blue+1)):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((now[j-1]+now[j])%mod)
    now = next
for i in range(1,blue):
    next = []
    for j in range(i+1):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((get[j-1]+get[j])%mod)
    get = next

  # print(now)
for i in range(1,blue+1):
    try:
  #        print(now[i],get[i-1])
        print((now[i] * get[i-1])%mod)
    except:
        print(0)

Measured memory_bytes: 3444
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a<b){
		if(b<c){
	
		printf("Yes\n");
		}
		else{
			printf("No\n");}
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

typedef pair<int, int>P;


int H[101];
signed main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	ans += max(A, B);
	if (A > B) {
		A--;
	}
	else B--;
	ans += max(A, B);
	print(ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n,h,w;
    cin >> n >> h >> w;
    vector<ll> a(n),b(n);
    ll ans=0;
    rep(i,n){
        cin >> a[i] >> b[i];
        if(a[i]>=h && b[i]>=w) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;

    if ( u == s ) {
        cout << a - 1 << " " << b << endl;;
    }
    else if ( u == t ) {
        cout << a << " " << b - 1 << endl;;
    }

    return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
N, M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
	print(0)
	exit()
X.sort()
dis = [b - a for a, b in zip(X, X[1:])]
dis.sort()
#print(dis)
print(sum(dis[:M-N]))

Measured memory_bytes: 13968
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8,cnt;


int main(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll x=0;
	for(ll i=0; i<n; i++){
		if(s[i]=='I'){
			x++;
			mx=max(mx,x);
		}
		else {
			x--;
			mx=max(mx,x);
		}
	}
	cout<<mx<<endl;
}


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

int main() {
    int n;
    cin >> n;
    ll ans = (ll) n * (n-1);
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
k,n = map(int, input().split())
c = list(map(int,input().split()))
answer = k

x = c[n-1]-c[0]
if x < answer:
  answer = x

y = c[0]+k-c[1]
if y < answer:
  answer = y

z = k-c[n-1]+c[n-2]
if z < answer:
  answer = z

w = c[n-1] - c[0]
if w < answer:
  answer = w

for i in range(1,n-1):
  a = c[i-1]+k-c[i]
  b = c[i]+k-c[i+1]
  if a < answer:
    answer = a
  elif b < answer:
    answer = b

print(answer)

Measured memory_bytes: 26444
#include<iostream>
using namespace std;
int N_MAX=120;
int main()
{
  int a,b,x,t;
  cin >> x;
  for(a=0;a<N_MAX;a++)
    for(b=a-1;b>-N_MAX;b--){
      t=a*a*a*a*a-b*b*b*b*b;
      if(t==x){
        cout << a << " " << b << endl;
        return 0;
      }
      if(t>x)
        break;
    }
  return 0;
}

Measured memory_bytes: 3192
N = int(input())
A = [int(i) for i in input().split()]

# Aを降順に並び替える
A = sorted(A)[::-1]

# A0 + A1 + A1 + A2 + A2 + ....
sum = 0
for i in range(len(A) - 1):
    if i % 2 == 1:
        sum += A[int((i+1)/2)]
    elif i % 2 == 0:
        sum += A[int(i/2)]
print(sum)

Measured memory_bytes: 31388
def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = sorted(X)
    for i in range(N):
        if X[i] <= Y[N//2-1]:
            print(Y[N//2])
        else:
            print(Y[N//2-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 93780
#include <cstdio>
#include <algorithm>
using namespace std;


int senbei[10][10000];

int main()
{
	int r, c;
	while (scanf("%d %d", &r, &c), r + c){
		for (int i = 0; i < r; i++){
			for (int j = 0; j < c; j++){
				scanf("%d", &senbei[i][j]);
			}
		}
		
		int maxi = 0;
		for (int i = 0; i < (1 << r); i++){
			int sum = 0;
			for (int j = 0; j < c; j++){
				int cnt = 0;
				for (int k = 0; k < r; k++){
					cnt += senbei[k][j] ^ !!((1 << k) & i);
				}
				
				sum += max(cnt, r - cnt);
			}
			maxi = max(maxi, sum);
		}
		
		printf("%d\n", maxi);
	}
	
	return 0;
}

Measured memory_bytes: 1416
#include <iostream>

using namespace std;

class Dice{
public:
     //  コンストラクタ
     Dice();
     //  デストラクタ
     ~Dice();
     //  メソッド
     int east();
     int west();
     int south();
     int north();
     void set(int sai[6]);
     int look(int men);
private:
     int me[7];
};

//  コンストラクタ
Dice::Dice()
{
}
//  デストラクタ
Dice::~Dice()
{
}
void Dice::set(int sai[6])
{
    int i;
    for(i = 0;i<6; i++) {
//        cout << sai[i] << endl;
        me[i+1] = sai[i];
    }
}
int Dice::east()
{
    int tmp = me[4];
    me[4] = me[6];
    me[6] = me[3];
    me[3] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::west()
{
    int tmp = me[3];
    me[3] = me[6];
    me[6] = me[4];
    me[4] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::south()
{
    int tmp     = me[5];
    me[5] = me[6];
    me[6] = me[2];
    me[2] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::north()
{
    int tmp     = me[2];
    me[2] = me[6];
    me[6] = me[5];
    me[5] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::look(int men)
{
    return(me[men]);
}
int main() {
    int sai[6];
    int i, l, f=1;
    char c;
    for(i =0; i < 6; i++){
        cin >> l;
        sai[i] = l;
    }
    Dice d;
    d.set(sai);
    c = getchar();
    while(f) {
        c = getchar();
        switch(c) { 
            case 'E': d.east();  break;
            case 'W': d.west();  break;
            case 'S': d.south(); break;
            case 'N': d.north(); break;
            default: f=0; break;
        }
//        cout << c << endl;
    }
    cout <<  d.look(1) << endl;
    return 0;

}



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

using namespace std;
typedef unsigned long long ull;

ull MaxDiff(ull k, vector<ull> a){
	ull max, a_size = a.size(), cur;
	sort(a.begin(), a.end());
	max = a[0] + (k - a[a_size - 1]);
	for(int i = 1; i < a_size; ++i){
		cur = a[i] - a[i - 1];
		if(cur > max) max = cur;
	}
	return max;
}

ull MinMove(ull k, vector<ull> a){
	return k - MaxDiff(k, a);
}

int main(void){
	ull k, n;
	vector<ull> a;

	cin >> k >> n;
	for(int i = 0; i < n; ++i){
		ull a_cur;
		cin >> a_cur;
		a.push_back(a_cur);
	}

	cout << MinMove(k, a) << endl;

	return 0;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    int CH, CW, DH, DW;
    cin >> CH >> CW >> DH >> DW;
    CH--;
    CW--;
    DH--;
    DW--;
    
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    vector<vector<int>> dist(H, vector<int>(W, 1e9));
    dist[CH][CW] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push({0, CH*W+CW});
    vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
    while (!pq.empty()) {
        int x = pq.top().second/W;
        int y = pq.top().second%W;
        int d = pq.top().first;
        pq.pop();
        if (d > dist[x][y]) continue;
        for (int i = 0; i <= 3; i++) {
            int nx = x+dx[i], ny = y+dy[i];
            if (nx <= -1 || nx >= H || ny <= -1 || ny >= W) continue;
            if (grid[nx][ny] == '#') continue;
            if (dist[nx][ny] <= d) continue;
            dist[nx][ny] = d;
            pq.push({d, nx*W+ny});
        }
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                int nx = x+i, ny = y+j;
                if (nx <= -1 || nx >= H || ny <= -1 || ny >= W) continue;
                if (grid[nx][ny] == '#') continue;
                if (dist[nx][ny] <= d+1) continue;
                dist[nx][ny] = d+1;
                pq.push({d+1, nx*W+ny});
            }
        }
    }
    if (dist[DH][DW] >= 1e8) cout << -1 << endl;
    else cout << dist[DH][DW] << endl;
	return 0;
}


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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int k;
  cin >> k;
  rep(i,k){
    int s = max({a,b,c});
    if(s==a) a=a*2;
    else if(s==b) b=b*2;
    else c=c*2;
  } 
  cout << a+b+c << endl; 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>

#define ull unsigned long long int
#define ll long long int
#define rep(var, from, to) for (ll var=(from); var<=(to); var++)
#define INF (1<<30)

using namespace std;

int a[3][105];

int dp[2][105];

int main()
{
  int n;
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  for (int j=0; j<2; j++)
  {
    for (int i=0; i<n; i++)
    {
      cin >> a[j][i];
    }
  }
  dp[0][0] = a[0][0];
  for (int i=1; i<n; i++)
  {
    dp[0][i] = dp[0][i-1]+a[0][i];
  }
  dp[1][0] = a[0][0]+a[1][0];
  for (int i=1; i<n; i++)
  {
    dp[1][i] = max(dp[1][i-1],dp[0][i])+a[1][i];
  }
  cout << dp[1][n-1] << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

const double EPS = 1e-10;
const double PI  = acos(-1);

typedef long long ll;

template<class T> inline void change_max(T& a, T const& b){a=std::max(a,b);}

int main(int argc, char* argv[])
{
  ll n,k;

  std::cin >> n >> k;

  ll ans = 0;

  if (k==0){
    std::cout << n*n << std::endl;
    exit(0);
  }
  
  // bを固定
  for (ll b = k+1; b <= n; b++) {
    ll tmp1 = std::max(0LL, (n % b - k + 1));
    ll tmp2 = (n/b)*(b-k);
    //std::cout << b << " " << tmp1 << " " << tmp2 << std::endl;
    ans += tmp1 + tmp2;
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (ll)(1e9+7);

const int SZ = 312345;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  cout << "choose(" << n << ", " << r << ")" << endl;
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}


const int MAX_N = 112345;
vector<int> g[MAX_N];

ll ans = 0;
void dfs(int u, int prev, const int K, int done) {

  ans *= max(0, (K - done));
  ans %= MOD;

  int use = 1;
  if (prev != -1) use++;
  for (int v : g[u]) if (v != prev) {
    dfs(v, u, K, use);
    use++;
  }
}

int main2() {
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  int K = nextInt();
  REP(i, N-1) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  ans = 1;
  dfs(0, -1, K, 0);
  cout << ans << endl;
  return 0;
}

int main() {
  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 18048
#include<stdio.h>

int main(void)
{
  int a, b;

  scanf("%d%d", &a, &b);

  if (a > b)
    printf("a > b\n");
  else if (a == b)
    printf("a == b\n");
  else
    printf("a < b\n");

  return 0;
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    scanf("%d %d", &n, &m);
    if (n == m) {
		printf("Yes");
	} else {
		printf("No");
	}
    return 0;
}


Measured memory_bytes: 3804
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    char[] toppings = line.toCharArray();
    int count = 0;
    for (int i = 0; i < 3; i++) {
      if (toppings[i] == 'o') {
        count++;
      }
    }
    System.out.println(700 + count * 100);
  }
}

Measured memory_bytes: 21076
N = int(input())
A = input().split()
A = [int(a) for a in A]

D = {}

for a in A:
    D[a] = D.get(a, 0) + 1

cnt = 0
for k, v in D.items():
    if k < v:
        cnt += v - k
    elif v < k:
        cnt += v
print(cnt)


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

int main() {
  int N, M; cin >> N >> M;
  int A[M]; for (int i = 0; i < M; i++) cin >> A[i];
  int sum = 0; for (int i = 0; i < M; i++) sum += A[i];
  cout << max(-1, N - sum) << endl;
}

Measured memory_bytes: 3672
n, x = map(int, input().split())
def doit(l, x):
    layers = 2 ** (l + 1) - 3
    if x >= layers * 2 + 3:
        return 2 ** (l + 1) - 1
    elif x >= layers + 2:
        return doit(l - 1, x - layers - 2) + 2 ** l
    elif x >= 1:
        return doit(l - 1, x - 1)
    else:
        return 0
print(doit(n, x))

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

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

  int n,i;
  cin >> n >> i;

  cout << n-i+1 << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define id(x,y,z)(((x)-1)*6+(y)*3+(z)%3+1)
using namespace std;
const int N=50005,M=1e6;
int n,m,q,mo,g,c0,s,t,r;
int a[N],b[N],c[N];
int f[N*6];
bool is[M][2],can;
int F(int x){return f[x]==x?x:f[x]=F(f[x]);}
int gcd(int x,int y){
	for(;y;y%=x)swap(x,y);
	return x;
}
void link(int x,int y){f[F(x)]=F(y);}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>q>>mo;
	fo(i,1,m){
		cin>>a[i]>>b[i]>>c[i];
		if(i>1)g=gcd(g,abs(c[i]-c[1]));
	}
	if(!g)g=mo;
	mo=gcd(g*3,mo);
	c0=c[1]%(g*3);
	for(int i=0,a=c0;i<=mo;++i,a=a*2%mo)is[a][i%2]=1;
	fo(i,1,6*n)f[i]=i;
	fo(i,1,m){
		c[i]=(c[i]-c0+g*3)/g%3;
		fo(p,0,1)
			fo(q,0,2)
				link(id(a[i],p,q),id(b[i],!p,q*2+c[i])),link(id(b[i],p,q),id(a[i],!p,q*2+c[i]));
	}
	for(;q--;){
		cin>>s>>t>>r;
		can=0;
		fo(p,0,1)
			fo(q,0,2)
				if(F(id(t,0,0))==F(id(s,p,q))&&is[(r+c0+(3-q)*g)%mo][p])
					can=1;
		printf(can?"YES\n":"NO\n");
	}
}

Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    char s[h][w];
    rep(i,h){
        rep(j,w) cin>>s[i][j];
    }
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.'){
                int cnt=0;
                if(i>0&&j>0&&s[i-1][j-1]=='#') cnt++;
                if(j>0&&s[i][j-1]=='#') cnt++;
                if(i<h-1&&j>0&&s[i+1][j-1]=='#') cnt++;
                if(i>0&&s[i-1][j]=='#') cnt++;
                if(i+1<h&&s[i+1][j]=='#') cnt++;
                if(i-1>=0&&j+1<w&&s[i-1][j+1]=='#') cnt++;
                if(j+1<w&&s[i][j+1]=='#') cnt++;
                if(i+1<h&&j+1<w&&s[i+1][j+1]=='#') cnt++;
                s[i][j]=cnt+'0';
            }
        }
    }
    rep(i,h){
        rep(j,w) cout<<s[i][j];
        cout<<'\n';
    }
}

Measured memory_bytes: 256
//#include <stdio.h>
#include <bits/stdc++.h>
#include <climits>
using namespace std;
int main()
{   
    int ans =0;
   int m1,d1,d2,m2;
    cin >> m1>>d1;
    cin >> m2 >> d2;
    if(m1 !=m2){
        ans=1;
    }

    
    cout << ans <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " "; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   int n;
   double d;
   cin >> n >> d;
   int c= 0;
   for(int i = 0 ; i < n ; i++){
    double x,y;
    cin >> x >> y;
    double res = sqrt((x*x)+(y*y));
    if(res > d){
      
    }
    else{
      c++;
    }
   }
   cout << c;
}


Measured memory_bytes: 3832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(void){
    int K, S;
    cin>>K>>S;
    int ans = 0;
    FOR(X, 0, K+1){
        FOR(Y, 0, K+1){
            if(S-X-Y>=0 && S-X-Y<=K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int B[4][3][10] = {};
    int n, b, f, r, v, i;
    
    cin >> n;
    
    for(i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        B[b-1][f-1][r-1] += v;
    }
    
    for(b=0;b<4;b++){
        for(f=0;f<3;f++){
            for(r=0;r<10;r++){
                cout << " " << B[b][f][r];
            }
            cout << endl;
        }
        
        if(b != 3){
            cout << "####################" << endl;
        }
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,X,Y; cin >> N >> K>>X>>Y;
    int ans;
    if(N>K) ans = K * X + (N-K)*Y;
    else ans = N * X;

    cout << ans << endl;


}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

const int N = 100000;

int n;
int m;
vii v[2 * N];
ll val[2 * N];
int was[2 * N];
vi p, q;

int go (int x, ll y) {
	if (was[x]) {
		if (val[x] != y) re 0;
		re 1;
	}
	if (x < n) p.pb (x); else q.pb (x - n);
	was[x] = 1;
	val[x] = y;
	for (int i = 0; i < sz (v[x]); i++)
		if (!go (v[x][i].fi, v[x][i].se - y))
			re 0;
	re 1;
}

int main () {
	int q;
	scanf ("%d%d%d", &n, &m, &q);
	for (int i = 0; i < q; i++) {
		int a, b, c;
		scanf ("%d%d%d", &a, &b, &c); a--; b--;
		v[a].pb (mp (b + n, c));
		v[b + n].pb (mp (a, c));
	}
	for (int i = 0; i < n + m; i++)
		if (!was[i]) {
			p.clear ();
			::q.clear ();
			if (!go (i, 0)) {
				printf ("No\n");
				re 0;
			}
			ll mp = 1e18, mq = 1e18;
			for (int j = 0; j < sz (p); j++)
				mp = min (mp, val[p[j]]);
			for (int j = 0; j < sz (::q); j++)
				mq = min (mq, val[::q[j] + n]);
			if (mp + mq < 0) {
				printf ("No\n");
				re 0;
			}
		}
	printf ("Yes\n");
	return 0;
}

Measured memory_bytes: 17196
N,M=map(int,input().split())
E = [list(map(int,input().split())) for _ in range(M)]
from collections import defaultdict

ans=0
for i in range(M):
    d = defaultdict(list)
    for j in range(M):
        if i!=j:
            d[E[j][0]].append(E[j][1])
            d[E[j][1]].append(E[j][0])
    f = defaultdict(lambda: 0)
    f[1]=1
    que=d[1]
    while len(que)>0:
        tmp=[]
        for q in que:
            if f[q]==0:
                f[q]=1
                tmp+=d[q]
        que=tmp
    if len(f.keys())<N:
        ans+=1
print(ans)



Measured memory_bytes: 41200
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int r = scan.nextInt();
		int d = scan.nextInt();
		int count = r/d - l/d;
		if(l % d == 0) {
			count++;
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 27020
#include <iostream>
using namespace std;
static const int INFTY = (1<<29);

int main() {
  int n, m;
  cin >> n >> m;
  int C[m];
  for (int i = 0; i < m; i++) {
    cin >> C[i];
  }
  int T[n+1];
  for (int i = 0; i < n+1; i++) {
    T[i] = INFTY;
  }
  T[0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n+1; j++) {
      if ((j+C[i]) > n) continue;
      T[j+C[i]] = min(T[j+C[i]], T[j] + 1);
    }
  }
  cout << T[n] << endl;
  return 0;
}



Measured memory_bytes: 3292
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    int N,M;
    cin >> N >> M;
    
    ll num[8][1001]={};
    
    for(int i=0; i<N; i++){
        ll x,y,z;
        cin >> x >> y >> z;
        
        num[0][i] = x+y+z;
        num[1][i] = x+y-z;
        num[2][i] = x-y+z;
        num[3][i] = x-y-z;
        num[4][i] = -x+y+z;
        num[5][i] = -x+y-z;
        num[6][i] = -x-y+z;
        num[7][i] = -x-y-z;
    }
    
    for(int i=0; i<8; i++){
        sort(num[i],num[i]+N);
    }
    
    ll ans=0;
    for(int i=0; i<8; i++){
        ll tmp=0;
        for(int j=N-1; j>=N-M; j--){
            tmp+=num[i][j];
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
int n,a[max_n];
int pre[max_n],suf[max_n];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)pre[i]=__gcd(pre[i-1],a[i]);
    for(int i=n;i>=1;i--)suf[i]=__gcd(suf[i+1],a[i]);
    int ans=0;
    for(int i=1;i<=n;i++)ans=max(ans,__gcd(pre[i-1],suf[i+1]));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(){
    int i,N[7],T,F,R,t;
    char S[105];
    for(i=1;i<=6;i++)
        scanf("%d",N+i);
    scanf("%s",S);
    scanf("%s",S);
    for(T=1,F=2,R=3,i=0;S[i];i++)
    {
        switch(S[i])
        {
        case 'N':t=T,T=F,F=7-t;break;
        case 'E':t=R,R=T,T=7-t;break;
        case 'S':t=F,F=T,T=7-t;break;
        case 'W':t=T,T=R,R=7-t;break;
        }
    }
    printf("%d\n",N[T]);
    return 0;
}


Measured memory_bytes: 2764
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt()
	t := readInt64()
	a := make([]int64, n)
	for i := range a {
		a[i] = readInt64()
	}
	ans := t // last duration
	for i := 0; i < n-1; i++ {
		ans += minInt64(a[i+1]-a[i], t)
	}
	println(ans)

}

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

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 4608
// finish date: 2018/01/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

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

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int fact(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans *= i;
    }
    return ans;
}

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


    return 0;
}

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

using namespace std;

int main(){
  int N,i,j;
  cin >> N;
  int d[N];
  for(i=0;i<N;i++){
    cin >> d[i];
  }
  
  int del=0;
  for(i=0;i<N;i++){
    for(j=i+1;j<N;j++){
      del+=d[i]*d[j];
    }
  }
  
  cout << del << endl;
}

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

int main() {
  int a,e,f;
  string b;

  cin>>a>>b;
  vector<int>c(a+1),d(a+1);
  c[0]=0;
  d[0]=0;
  f=a;
  for(int i=0;i<a;i++){
      if(b[i]=='#'){
        c[i+1]=c[i]+1;
        d[i+1]=d[i];
      }
      else{
        c[i+1]=c[i];
        d[i+1]=d[i]+1;
      }
    }
 for(int i=0;i<a;i++){
f=min(f,c[i]+d[a]-d[i+1]);
 }

cout<<f<<endl;
}


Measured memory_bytes: 2180
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		
		System.out.println(a.substring(a.length()-1).equals(b.substring(0,1)) && b.substring(b.length()-1).equals(c.substring(0,1)) ? "YES" : "NO");
	}
}


Measured memory_bytes: 35672
package main

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

func main() {
	N := nextInt()
	a := 0
	b := 50001

	for a+1 != b {
		c := (a + b) / 2
		x := int(math.Floor(float64(c) * 1.08))

		if x <= N {
			// 払える
			a = c
		} else {
			b = c
		}
	}

	if int(math.Floor(float64(a)*1.08)) != N {
		fmt.Println(":(")
	} else {
		fmt.Println(a)
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[15],f[15][3],n;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	f[0][1]=1;
	for (int i=1;i<=n;i++)
		for (int j=a[i]-1;j<=a[i]+1;j++)
			for (int k=0;k<2;k++)
				f[i][k&j&1]+=f[i-1][k];
	printf("%d\n",f[n][0]);
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	char c;
	while(1){
		scanf("%c", &c);
		if(c=='\n') { break;}
		if( c >= 'a' && c <= 'z') { printf("%c", c-32); }
		else { printf("%c",c); }
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 520
#include <stdio.h>
#include <math.h>
int main() {
	int Zj, Zk, Zl;
	scanf("%d %d %d", &Zj, &Zk, &Zl);
	abs(Zj - Zk) < abs(Zj - Zl) ? printf("A") : printf("B");
	return 0;
}

Measured memory_bytes: 1648
a=input()
a=list(a)

l=0
m=0
n=0
o=0

for i in range(len(a)):
    if a[i]=="K":
        l+=1
    if a[i]=="U":
        m+=1
    if a[i]=="P":
        n+=1
    if a[i]=="C":
        o+=1
        
min=l
zero=0
if min>m:
    zero=m
    m=min
    min=zero
zero=0
if min>n:
    zero=n
    n=min
    min=zero
zero=0
if min>o:
    zero=o
    o=min
    min=zero

print(min)



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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int x, a , b ;
	cin >> x>> a >> b ;
	int day = b - a  ;
	 if(-a+b <= 0 )puts("delicious");
	 else if(day <= x)puts("safe");
	 else puts("dangerous");
}


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

int main() {
	int cost,check,N,x;
	

	
	cin>>N;
	
	x=ceil(N/1.08); 
	check=x*1.08;
	

 
    
	if(N==check){
	cout<<x<<endl;
	}
	
	else{
		cout<<":("<<endl;

	}

	return 0;
}

Measured memory_bytes: 256
#pragma region template
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define pb push_back
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vstr = vector<string>;
static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
#pragma endregion template

void solve(ll S, ll W) {
  string Yes = "safe\n", No = "unsafe\n";
  Yes(S > W);
}

int main() {
  ll S;
  ignore_ret(scanf("%lld",&S));
  ll W;
  ignore_ret(scanf("%lld",&W));
  solve(S, W);
  return 0;
}


Measured memory_bytes: 3692
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int sum = 0;
                for (int i = 0; i < 5; i++) {
                        sum += Math.max(40, sc.nextInt());
                }
                System.out.println(sum / 5);
        }
}

Measured memory_bytes: 26216