akhauriyash/Code-Regression huggingface dataset:
// A Dynamic Programming based solution for 0-1 Knapsack problem 
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
// A utility function that returns maximum of two integers 
//int max(int a, int b) { return (a > b)? a : b; } 

// Returns the maximum value that can be put in a knapsack of capacity W 
ll int knapSack(ll int W,ll int wt[], ll int val[],ll int n) 
{ 
	ll int i, w; 
	ll int K[n+1][W+1]; 

	// Build table K[][] in bottom up manner 
	for (i = 0; i <= n; i++) 
	{ 
		for (w = 0; w <= W; w++) 
		{ 
			if (i==0 || w==0) 
				K[i][w] = 0; 
			else if (wt[i-1] <= w) 
					K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); 
			else
					K[i][w] = K[i-1][w]; 
		} 
	} 
	/*for (i = 0; i <= n; i++) 
	{ 
		for (w = 0; w <= W; w++) 
		{ 
			cout<<K[i][w]<<" ";
		} 
		cout<<endl;
	} */
	return K[n][W]; 
} 

int main() 
{ 
	ll int n,W;
	cin>>n>>W;
	ll int wt[n],val[n];
	for (ll int i = 0; i < n; ++i)
	{
		cin>>wt[i]>>val[i];
	}
	ll int ans=knapSack(W, wt, val, n); 
	cout<<ans<<endl;
	return 0; 
} 


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    int len = n + 1;
    vector<int> ans;
    for (int s = 0; s < n; s++)
    {
        vector<int> d(n, -1);
        vector<int> pre(n, -1);
        queue<int> que;
        d[s] = 0;
        que.push(s);
        while (!que.empty())
        {
            int t = que.front();
            que.pop();
            for (auto nxt : G[t])
            {
                if (d[nxt] == -1)
                {
                    d[nxt] = d[t] + 1;
                    pre[nxt] = t;
                    que.push(nxt);
                }
            }
        }
        for (int t = 0; t < n; t++)
        {
            if (s == t || d[t] == -1)
                continue;
            for (auto p : G[t])
            {
                if (p == s)
                {
                    vector<int> v({s});
                    int now = t;
                    while (now != s)
                    {
                        v.push_back(now);
                        now = pre[now];
                    }
                    if (len > v.size())
                    {
                        len = v.size();
                        ans = v;
                    }
                }
            }
        }
    }
    sort(all(ans));
    if (len == n + 1)
        cout << -1 << endl;
    else
    {
        cout << len << endl;
        rep(i, len) cout << ans[i] + 1 << endl;
    }
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[111];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int r = 0;
	for (int i = 0; i < n; i++)
		i % 2 ? r += a[i] : r -= a[i];
	cout << abs(r) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll solve(ll x){
    ll ans = 0;
    while(x > 0){
        ll now = 0;
        rep(i, 40)if(x & (1LL<<i))now++;
        x %= now;
        ans++;
    }
    return ans;
} 

ll modpow(ll a, ll b, ll m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	ll memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}

int main() {
    ll n, cnt = 0;
    string s;
    cin >> n >> s;
    vector<ll> b(n);
    rep(i, n){
        b[i] = s[i] - '0';
        if(s[i] == '1')cnt++;
    }

    ll sum1 = 0, sum2 = 0;
    reverse(all(b));
    rep(i, n)if(b[i] == 1)sum1 = ( sum1 + modpow(2, i, (cnt+1)) ) % (cnt+1);
    if(cnt > 1){rep(i, n)if(b[i] == 1)sum2 = ( sum2 + modpow(2, i, (cnt-1)) ) % (cnt-1);}

    vector<ll> ans(n);
    rep(i, n){
        if(b[i] == 0){
            cnt++;
            ll now = (sum1 + modpow(2, i, cnt))% cnt;
            ans[i] = solve(now)+1;
            cnt--;
        }else{
            if(cnt == 1){ans[i] = 0; continue;}
            cnt--;
            ll now = (sum2 - modpow(2, i, cnt) + 1000*cnt) % cnt;
            ans[i] = solve(now)+1;
            cnt++;
        }
    }

    reverse(all(ans));
    rep(i, n)cout << ans[i] << endl;
}


Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
int n;
int m[] = {1, 2, 4, 8, 16, 32, 64};
int main() {
    cin >> n;
    for (int i = 6; i >= 0; --i) {
        if (m[i] <= n) {
            cout << m[i] << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int K = 62;
ll b[K];
ll a[K];
ll c[K];
int n;

bool check(ll mask) {
	for (int i = 0; i < n; i++)
		c[i] = 0;
	int m = 0;
	for (int i = 0; i < K; i++) {
		if (((mask >> i) & 1) == 0) continue;
		for (int j = 0; j < n; j++)
			if ((a[j] >> i) & 1)
				c[j] ^= 1LL << m;
		m++;
	}
	for (int i = 0; i < m; i++)
		b[i] = -1;
	for (int i = 0; i < n; i++) {
		ll x = c[i];
		for (int j = 0; j < m; j++) {
			if (((x >> j) & 1) == 0) continue;
			if (b[j] == -1) {
				b[j] = x;
				break;
			} else {
				x ^= b[j];
			}
		}
	}
	ll x = (1LL << m) - 1;
	for (int i = 0; i < m; i++) {
		if (((x >> i) & 1) == 0) continue;
		if (b[i] == -1) return false;
		x ^= b[i];
	}
	return true;
}

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

	for (int i = 0; i < K; i++)
		b[i] = -1;
	ll XR = 0;
	scanf("%d", &n);
	while(n--) {
		ll x;
		scanf("%lld", &x);
		XR ^= x;
		for (int i = 0; i < K; i++) {
			if (((x >> i) & 1) == 0) continue;
			if (b[i] == -1) {
				b[i] = x;
				break;
			} else {
				x ^= b[i];
			}
		}
	}
	n = 0;
	for (int i = 0; i < K; i++)
		if (b[i] != -1)
			a[n++] = b[i];
	ll ans = 0;
	for (int i = K - 1; i >= 0; i--) {
		if ((XR >> i) & 1) continue;
		ans ^= 1LL << i;
		if (!check(ans)) ans ^= 1LL << i;
	}
	printf("%lld\n", XR + 2 * ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
 
  for (int i = 0;i < N; i++) {
   
   string S_i;
   cin >> S_i;
     if (S_i == "Y") {
       cout << "Four" << endl;
       break; }
     if (i == N - 1){
       cout << "Three" << endl;
       break; }
  }
  
  }
 

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

void solve(){
    int n;
    ll A, B;
    cin >> n >> A >> B;
    vector <ll> a(n + 1);
    
    for (int i = 1; i <= n; i++) cin >> a[i];
    
    ll res = 0;

    for (int i = 2; i <= n; i++){
        res += (min( (a[i] - a[i - 1]) * A, B));
    }
    cout << res << endl;
}       
int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    //freopen("input.txt", "r", stdin);//freopen("output1.txt", "w", stdout);
    //freopen("icecream.in","r",stdin);// freopen("exam.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

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

int N, A;
int x[51] = {0};
// dp[j][k][s] := x1, ... ,xjからk枚選んでxiの合計をｓにするような選び方の総数
long long int dp[51][51][2501] = {0};


void solve(){
  for (int j = 0; j < N + 1; j++){
    // dpの初期化
    dp[j][0][0] = 1;
  }

  // 具体的な漸化式を解く
  for (int j = 1; j < N + 1; j++){
    for(int k = 1; k < j + 1; k++){
      for(int s = 1; s < N * A + 1; s++){
        dp[j][k][s] = dp[j - 1][k][s];
        if (s >= x[j]){
          dp[j][k][s] += dp[j - 1][k - 1][s - x[j]];
        }
      }
    }
  }
  long long int count = 0;
  for(int k = 1; k < N + 1; k++){
    count += dp[N][k][k * A];
  }
  cout << count << endl;
  return ;
}


int main(){
  cin >> N >> A;
  for(int i = 1; i < N + 1; i++){
    cin >> x[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 25600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
int n;
int a[200001];
int main(){
    cin>>n;
    rep(i,n) cin>>a[i];
    int cur=0;
    rep(i,n)if(cur+1==a[i]) ++cur;
    if(cur==0) cout<<-1<<endl;
    else cout<<n-cur<<endl;
    return 0;
}

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

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<int(1e9)+7>;

const int MAXN = 210000;

num dp_next[MAXN];

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> c;
	c.push_back(0);
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a != c.back()) c.push_back(a);
	}
	c.push_back(200010);
	for(int i = 0; i < c.size(); i++){
		num ans;
		if(i == 0){
			ans = 1;
		} else {
			ans = dp_next[c[i]];
		}
		if(i + 1 == c.size()){
			cout << int(ans) << '\n';
		} else {
			dp_next[c[i+1]] += ans;
		}
	}
}

Measured memory_bytes: 2296
def sieve(n):
  is_prime = [True for _ in range(n+1)]
  is_prime[0] = False
  for i in range(2, n+1):
    if is_prime[i-1]:
      j = 2 * i
      while j <= n:
        is_prime[j-1] = False
        j += i
  table = [i for i in range(1, n+1) if is_prime[i-1]]
  return table

N = int(input())
A = list(map(int, input().split()))
Amax = max(A)
lis = [0]*(Amax+1)
for i in range(N):
  lis[A[i]] += 1
table = sieve(Amax)
setwise = False
for t in table:
  cnt = sum(lis[t::t])
  if cnt==N:
    print('not coprime')
    break
  if 2<=cnt<N:
    setwise=True
else:
  if setwise==True:
    print('setwise coprime')
  else:
    print('pairwise coprime')


Measured memory_bytes: 219824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl;
#define pv(v) for(auto a: v){ cout << a << endl; }

int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;
  s[k-1] = (char) tolower(s[k-1]);
  p(s);
}


Measured memory_bytes: 256
(let* ((k (read))
       (n (read))
       (a (make-array `(,n) :initial-element 0))
       (d 0))
  (setf (aref a 0) (read))
  (loop :for i :from 1 :to (1- n)
        :do (progn
              (setf (aref a i) (read))
              (setf d (max d (- (aref a i) (aref a (1- i)))))))
  (setf d (max d (+ (aref a 0) (- k (aref a (1- n))))))
  (format t "~A~%" (- k d)))


Measured memory_bytes: 78752
#include <iostream>
#include <map>
#include <climits>
#include <algorithm>
using namespace std;

int main(){
  int n, res=0;
  cin >> n;

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

  for(auto itr=m.begin(); itr!= m.end(); itr++){
    if(itr->first > itr->second) res += itr->second;
    else if(itr->first < itr->second) res += itr->second-itr->first;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 5120
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for n in range(len(SA)):
    tmp = K-SA[n]
    if tmp < 0:
        break
    m = bisect_right(SB, tmp)
    ans = max(ans, n+m)
print(ans)

Measured memory_bytes: 49140
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  int a,b,x;
  cin>> a >> b >> x;
  if (x<=a+b && x>=a) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3568
# 愚直にやる以外の方法がまっっっっったく浮かばないのだが？？？
# いくつ入れるか+どこにいれるか

# 実装が頭ハゲるかと思った...1時間くらいかかったのでは...

s = gets.chomp.chars.map(&:to_i)
ans = s.map(&:to_s).join.to_i
def perm(i, current_arr, source_arr, limit)
  length = source_arr.size
  # return  if length < limit
  if current_arr.size == limit
    @res_arr << current_arr
  else
    i.upto(length) do |j|
      next if i==j
      perm(j, current_arr.clone<<source_arr[j-1], source_arr, limit)
    end
  end
end

def s(arr, s)
  ai = 0
  ret = 0
  cur = 0
  s.each.with_index do |sv, sidx|
    if ai < arr.size && sidx==arr[ai]
      ret += cur*10+sv
      cur = 0
      ai+=1
      next
    end
    cur *=10
    cur += sv
  end
  ret += cur
  return ret
end

# 入れる場所は0からs.size-1箇所
1.upto(s.size-1) do |i|
  @res_arr = []
  perm(0, [], (0...s.size-1).to_a, i)
  @res_arr.each do |a|
    ans+=s(a, s)
  end
end
p ans



Measured memory_bytes: 2044
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int K = scan.nextInt();
		scan.close();
		int ans = 0;
		if(A >= B && A >= C) {
			ans = A * (int)Math.pow(2, K) + B + C;
		}else if(B >= A && B >= C) {
			ans = B * (int)Math.pow(2, K) + A + C;
		}else if(C >= A && C >= B) {
			ans = C * (int)Math.pow(2, K) + A + B;
		}
		System.out.println(ans);

	}
}

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

int main()
{
    int n, k = 0, x, d[1000];
    cin >> n >> x;
    d[0] = 0;
    for(int i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        d[i + 1] = d[i] + p;
    }
    for(int i = 0; i <= n; i++)
    {
        if(d[i] <= x)
            k++;
    }
    cout << k;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
    int array[5][4][11] = {0},
        i,j,k,n,b,f,r,v;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf(" %d %d %d %d ", &b, &f, &r, &v);
        array[b][f][r] += v;
    }
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",array[i+1][j+1][k+1]);
            }
            printf("\n");
        }
        if(i!=3)printf("####################\n");
    }
    return 0;
}

Measured memory_bytes: 1808
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Measured memory_bytes: 6420
#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>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MOD = 1000000007;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m; cin >> n >> m;
  ll x[n]; FOR(i,0,n) cin >> x[i];
  ll y[m]; FOR(i,0,m) cin >> y[i];
  ll ans = 0;
  FOR(i,0,n-1) ans = (ans % MOD + (x[i+1] - x[i]) % MOD * (i + 1) % MOD * (n - i - 1)) % MOD;
  ll ans2 = 0;
  FOR(i,0,m-1) ans2 = (ans2 % MOD + (y[i+1] - y[i]) % MOD * (i + 1) % MOD * (m - i - 1)) % MOD;
  ans *= ans2;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

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

struct lst {
	int n;
	string it[101];
};
lst ls[101];
map<string,int> co,ln;

int ren(string st) {
	int i,k,m,s=0;
	k=ln[st]; m=ls[k].n;
	if (m==0) return co[st];
	for (i=0;i<m;i++) s+=ren(ls[k].it[i]);
	if (s>co[st]) s=co[st]; 
	return s;
	 }

int main() {
	int i,j,k,n,m,c;
	string st;
	while(cin >> n) {
		if (n==0) break;
		for (i=0;i<n;i++) { cin >> st >> c; co[st]=c; ln[st]=i;}
		cin >> n;
		for (i=0;i<n;i++) {
			cin >> st; k=ln[st];
			cin >> m; ls[k].n=m;
			if (m!=0) for (j=0;j<m;j++) cin >> ls[k].it[j];
		}
		cin >> st;
		k=ren(st);
		cout << k << endl;
	}	  
	return 0;
} 

Measured memory_bytes: 1312
<?php

fscanf(STDIN, "%d %d", $K, $N);
$A = trim(fgets(STDIN));
$array = explode(" ", $A);

$max = 0;
for ($i = 1; $i < $N; $i++) {
  $a = $array[$i] - $array[$i - 1];
  $max = max($max, $a);
}
$maxDistance = max($max, ($array[0] + ($K-$array[$N-1])));

echo $K - $maxDistance;

Measured memory_bytes: 18932
#include <stdio.h>
int main(void){
    while(1){
        int H;
        scanf("%d",&H);
        if(H==0)break;
        int A[H][5];
        for(int i=0;i<H;i++)for(int j=0;j<5;j++)scanf("%d",&A[i][j]);
        int ans=0;
        while(1){
            int flag=0;
            for(int i=0;i<H;i++){
                if(A[i][0]==A[i][1]&&A[i][1]==A[i][2]&&A[i][2]==A[i][3]&&A[i][3]==A[i][4]&&A[i][2]!=0){flag=1;ans+=A[i][0]*5;for(int j=0;j<5;j++)A[i][j]=0;}
                else if(A[i][0]==A[i][1]&&A[i][1]==A[i][2]&&A[i][2]==A[i][3]&&A[i][2]!=0){flag=1;ans+=A[i][0]*4;for(int j=0;j<4;j++)A[i][j]=0;}
                else if(A[i][1]==A[i][2]&&A[i][2]==A[i][3]&&A[i][3]==A[i][4]&&A[i][2]!=0){flag=1;ans+=A[i][1]*4;for(int j=1;j<=4;j++)A[i][j]=0;}
                else if(A[i][2]==A[i][3]&&A[i][3]==A[i][4]&&A[i][2]!=0){flag=1;ans+=A[i][2]*3;for(int j=2;j<5;j++)A[i][j]=0;}
                else if(A[i][1]==A[i][2]&&A[i][2]==A[i][3]&&A[i][2]!=0){flag=1;ans+=A[i][2]*3;for(int j=1;j<4;j++)A[i][j]=0;}
                else if(A[i][0]==A[i][1]&&A[i][1]==A[i][2]&&A[i][2]!=0){flag=1;ans+=A[i][2]*3;for(int j=0;j<3;j++)A[i][j]=0;}
            }
            while(1){
                int flag3=0;
                for(int i=0;i<H-1;i++)for(int j=0;j<5;j++){
                    if(A[i+1][j]==0&&A[i][j]!=0){flag3=1;A[i+1][j]=A[i][j];A[i][j]=0;}
                }
                if(flag3==0)break;
            }
            if(flag==0)break;
        }
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 2128
#include<iostream>
#include<cstdio>
#include<algorithm>
int main()
{
	int n,k;
	while(1){
		scanf("%d%d",&n,&k);	
		if(n==0&&k==0)
			break;
		
		const int K=100000;
		bool card[K+1]={false};
		for(int i=0;i!=k;++i){
			int c;
			scanf("%d",&c);
			card[c]=true;
		}	
	
		int before=-1;
		int m=0;
		if(card[0]){
			int no=-1;
			for(int i=1;i<=n;++i){
				if(card[i]){
					if(before==-1||!card[before])
						before=i;
				}
				else if(no==-1||before>no){
					no=i;
				}
				else if(before!=-1){
					m=std::max(m,i-before);
					before=no+1;
					no=i;
				}
			}
			if(before!=-1)
				m=std::max(m,n-before+1);
		}
		else{
			for(int i=1;i<=n;++i){
				if(card[i]){
					if(before==-1||!card[before])
						before=i;
				}
				else if(before!=-1){
					m=std::max(m,i-before);
					before=i+1;
				}
			}
			if(before!=-1)
				m=std::max(m,n-before+1);
		}
		std::cout<<m<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1300
S = list(map(int,input().split("/")))
ans = False
if S[0] > 2019:
    ans = True
elif S[0] >= 2019 and S[1] > 4:
    ans = True
elif S[0] >= 2019 and S[1] >= 4 and S[2] > 30:
    ans = True

if ans == True:
    print("TBD")
else:
    print("Heisei")

Measured memory_bytes: 3060
from heapq import heapify, heappush, heappop

K = int(input())

ll = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(ll)

def next_num(X):
    n = int(str(X)[-1])
    if n == 0:
        return (0, 1)
    elif n == 9:
        return (8, 9)
    else:
        return (n-1, n, n+1)

for _ in range(K-1):
    lli = heappop(ll)
    next_nums = next_num(lli)
    for ni in next_nums:
        heappush(ll, lli*10+ni)

ans = ll[0]
print(ans)


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

int main() {
  char S;
  cin >> S;
  string T = "aeiou";
  string U;
  
  for (int i=0; i < T.size(); i++){
    if ( S == T.at(i)){
      U = "vowel";
      break;
    }
    else {
      U = "consonant";
    }
  }
  cout << U << endl;
      

  // ここにプログラムを追記
  
 
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<double> t(N+2);
    for (int i = 1; i <= N; i++){
        double n;
        cin >> n;
        t[i] = t[i-1] + 2*n;
    }
    t[N+1] = t[N];

    vector<double> v(N+2);
    for (int i = 1; i <= N; i++){
        cin >> v[i];
    }
    
    vector<double> s(t[N], 100000);
    for (int i = 0; i <= t[N]; i++) {
        for (int j = 0; j <= N+1; j++) {
            double f;
            if(i >= t[j]) {
                f = v[j] + 0.5 * (i-t[j]);
            }
            else if(i >= t[j-1]) {
                f = v[j];
            }
            else {
                f = v[j] + 0.5 * (t[j-1] - i);
            }

            s[i] = min(s[i], f);
        }
    }

    double ans = 0;
    for(int i = 1; i <= t[N]; i++) {
        ans += 0.25 * (s[i] + s[i-1]);
    }
    
    printf("%.5lf", ans);
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=10001;
int a[N];
int n,m;
ll ans=1e9;
int main(){
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	for (int s=1; s<=100; s++){
		ll sum=0;
		for (int i=1; i<=n; i++)
			sum=sum+(s-a[i])*(s-a[i]);
		ans=min(ans,sum);
	}
	printf("%lld\n",ans);
	return 0;	
}

Measured memory_bytes: 128
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#include<iomanip>
using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);

#define csh(a,n) memset(a,n,sizeof(a));

int main(){
	int n;
	cin>>n;
	map<int,int>mp;
	int p=1;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(mp[a]==1){
			if(p)
			cout<<"NO"<<endl;
			p=0;
		}
		else{
			mp[a]=1;
		}
	}
	if(p)
	cout<<"YES"<<endl;
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
typedef long long int ll;
int main(){
ll A, V;
cin >> A >> V;
ll B,W;
cin >> B >> W;
ll T;
cin >> T;
ll D=abs(A-B);
ll D2=(V-W)*T;
puts(D<=D2?"YES":"NO");
}

Measured memory_bytes: 3592
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)


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

    int n=700;

    rep(i,0,3)
    if(s[i]!='x')
      n+=100;

    prin(n);        
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

int P, Q, R;

int main() {
    cin >> P >> Q >> R;
    cout << P + Q + R - max(P, max(Q, R)) << 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;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;++i){
        ans+=i*(n+1-i);
    }
    rep(i,n-1){
        ll u,v;
        cin>>u>>v;
        if(u>v)swap(u,v);
        ans-=u*(n-v+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k; cin >> n >> k;
    vector<pair<int, int>> v;
    vector<int> sp;
    ll tot = 1;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        (tot *= a) %= MOD;
        if (a < 0) v.emplace_back(-a, 1), sp.emplace_back(a);
        else v.emplace_back(a, 0);
    }
    if (k == n) return cout << (tot % MOD + MOD) % MOD << '\n', 0;
    sort(v.rbegin(), v.rend());
    int neg = 0, lp = -1, ln = -1;
    for (int i = 0; i < k; ++i) {
        if (v[i].second) ++neg, ln = i;
        else lp = i;
    }
    if (!(neg & 1)) {
        ll fa = 1;
        for (int i = 0; i < k; ++i) (fa *= v[i].first) %= MOD;
        return cout << fa << '\n', 0;
    }
    vector<int> ap, an;
    for (int i = k; i < n; ++i) {
        if (v[i].second) an.emplace_back(v[i].first);
        else ap.emplace_back(v[i].first);
    }
    if (neg == k && ap.empty()) {
        sort(sp.rbegin(), sp.rend());
        ll fa = 1;
        for (int i = 0; i < k; ++i) (fa *= sp[i]) %= MOD;
        return cout << fa + MOD << '\n', 0;
    }
    if (neg == k) {
        ll fa = 1;
        for (int i = 0; i < k - 1; ++i) (fa *= v[i].first) %= MOD;
        (fa *= ap[0]) %= MOD;
        return cout << fa << '\n', 0;
    }
    ap.emplace_back(-MOD), an.emplace_back(-MOD);
    ll fa = 1;
    int idx = 0;
    if (1LL * v[lp].first * ap[0] > 1LL * v[ln].first * an[0]) fa = ap[0], idx = ln;
    else fa = an[0], idx = lp;
    for (int i = 0; i < k; ++i) {
        if (i == idx) continue;
        (fa *= v[i].first) %= MOD;
    }
    cout << fa << '\n';
}

Measured memory_bytes: 6552
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long 
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define N ((ll)(2e6+100))
#define MAX ((ll)(1e16+100))
#define ARRS ((ll)(3e5+100))
#define MOD ((ll)(1e9+7))
#define M1 ((ll)(1001783))
#define M2 ((ll)(1001941))
#define M3 ((ll)(1002073))
#define pb push_back


ll n,m;
ll a[ARRS];
ll b[ARRS];
string s;

int main(){
	cin>>n;
	ll s1,s2;
	s1=s2=0;
	for(int i=0; i<n; i++){
		cin>>a[i];
		s1+=a[i];
	}

	ll c1,c2;
	c1=c2=0;
	for(int i=0; i<n; i++){
		cin>>b[i];
		s2+=b[i];
		if(a[i]==b[i])continue;
		else if(a[i]<b[i]){
			c1+=(b[i]-a[i]+1)/2;
			c2+=(b[i]-a[i])&1;
		}
		else c2+=a[i]-b[i];
		//cout<<c1<<" "<<c2<<endl;
	}
	ll c=s2-s1;
	if(max(c1,c2)<=c)
		cout<<"Yes";
	else cout<<"No";
}
 


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

int n;

void dfs(string s, char mx) {
    if (s.size() == n) {
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= mx + 1; c++) {
        string t = s;
        t += c;
        dfs(t, max(mx, c));
    }
}

int main() { 
    cin >> n;
    // cout << 'a'-1 << endl;
    dfs("", 'a'-1);
    return 0;
}


Measured memory_bytes: 1536
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let mut a = input_vector::<usize>();
    a.sort();
    println!("{}", a.iter().take(2).sum::<usize>());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	ll tmp=a[0];
	for(int i=1; i<n; i++){
		tmp ^=a[i];
	}
	tmp^=a[n-1];
	if(tmp==a[n-1]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC83(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC81();
}

void ABC81(void){
    int k=0;
    char a[3];
    cin>>a[0]>>a[1]>>a[2];
    for(int i=0;i<=2;++i){
        if(a[i]=='1')++k;
    }
    cout<<k<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  in n;
  cin>>n;
  int m=0;//文字数
  vector<in> a(100,0);
  rep(i,100){
    a.at(i+1) = 26*a.at(i)+26;
    if(a.at(i+1)>n){
      m=i+1;
      break;
    }
  }
  if(n==a.at(m-1))
    m--;
  //cout<<m<<endl;
  in h = n - a.at(m-1)-1;//数
  vector<char> s(m);
  rep(i,m){
    int w = h%26;
    s.at(i) = (char)(w+(int)'a');
    h-=w;
    h=h/26;
  }
  rep(i,m)
    cout<<s.at(m-1-i);
  cout<<endl;
}

Measured memory_bytes: 3636
//ハッシュ法を実装
#include <stdio.h>
#include <string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L]; //二次元配列

//文字から数値に変換
int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

//文字列から数値へ変換してkeyを生成する
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i = 0; i < strlen(str); i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M-1));}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);//文字列を数値に変換
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str); //文字列を数値に変換
  for(i = 0; ; i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h], str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for(i = 0; i < M; i++)
    H[i][0] = '\0';
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s %s", com, str); //より高速な入力scanfを使用

    if(com[0] == 'i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
  return 0;
}

















Measured memory_bytes: 16052
n = int(input())
spot = [0] + list(map(int, input().split())) + [0]
plst = [0] * n
dissum = 0
for i in range(1, n + 1):
  plst[i - 1] = (abs(spot[i + 1] - spot[i - 1])) - (abs(spot[i + 1] - spot[i]) + abs(spot[i] - spot[i - 1]))
  dissum += abs(spot[i] - spot[i - 1])
dissum += abs(spot[n])
for i in range(n):
  print(dissum + plst[i])

Measured memory_bytes: 20564
#include <stdio.h>

int main(){
	int height[10];
	int juni[3];
	int i;
	for(i=0;i<3;i++){
		juni[i]=0;
	}
	for(i=0;i<10;i++){
		scanf("%d",&height[i]);
		if(height[i]>juni[0]){
			juni[2]=juni[1];
			juni[1]=juni[0];
			juni[0]=height[i];
		}else if(height[i]>juni[1]){
			juni[2]=juni[1];
			juni[1]=height[i];
		}else if(height[i]>juni[2]){
			juni[2]=height[i];
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",juni[i]);
	}
	return 0;
}

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

void solve(long long X, long long K, long long D){
    X = abs(X);
    long long ans = 0;
    if(X/D <= K){
        long long e = X/D;
        K = K - e;
        X = X - D * e;
        if(K%2 == 1) X = abs(X - D);
        ans = X;
    }
    else ans = X - K*D;
    cout << ans << endl;
    return;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3760
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
    
    return 0

#input


N,T=pin()
timing=tuple(pin())

ans=0
for i in range(N):
        if i!=(N-1):ans+=min(timing[i+1]-timing[i],T)
        else:ans+=T
print(ans)
#output
#print(solution(H,N))
#print(["No","Yes"][cond])



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

typedef long long int ll;
ll x, n, temp;
set<ll> p;

int main() {
    scanf("%lld %lld", &x, &n);
    for(ll i = 0; i < n; ++i) {
        scanf("%lld", &temp);
        p.insert(temp);
    }

    ll range = 0;
    while(x + range <= 101 || x - range >= 0) {
        if(x - range >= 0 && p.find(x-range) == p.end()) {
            printf("%lld\n", x - range);
            return 0;
        } 
        if(p.find(x + range) == p.end()) {
            printf("%lld\n", x + range);
            return 0;
        }
        range++;
    }
}

Measured memory_bytes: 3836
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans

def getval(a,k):
    val=1
    while(a<k):
        a*=2
        val/=2
    return val
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,k= map(int, sys.stdin.readline().split(' '))
    ans=0
    for i in range(1,n+1):
        ans+=getval(i,k)
    print(ans/n)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include<array>

int main() {
	u64 k, a, b;
	::std::cin >> k >> a >> b;
	if (b <= a + 2) {
		::std::cout << k + 1 << ::std::endl;
	}
	else {
		if (a > k) {
			::std::cout << k + 1 << ::std::endl;
		}
		else {
			u64 ans = a;
			k -= a - 1;
			ans += (b - a)*(k / 2);
			k %= 2;
			if (k) {
				++ans;
			}
			::std::cout << ans << ::std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll ksm(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=2e5+10;
int n;
ll a[N],f[N],s[N];
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%lld",&a[i]);
	}
	s[1]=a[1];
	for(int i=3;i<=n;i+=2){
		s[i]+=s[i-2]+a[i];
	}
	for(int i=2;i<=n;i++){
		if(i&1){
			f[i]=max(f[i-1],f[i-2]+a[i]);
		}
		else{
			f[i]=max(s[i-1],f[i-2]+a[i]); 
		} 
	}
	printf("%lld",f[n]);
    return 0;
}


Measured memory_bytes: 8496
#include<iostream>

using namespace std;

int main(void)
{
  int f[5],k; cin>>f[0]>>f[1]>>f[2]>>f[3]>>f[4]>>k;
  int max=f[0],min=f[0];
  
  for(int i=1;i<5;i++){
    if(max<f[i]){max=f[i];}
    if(min>f[i]){max=f[i];}
  }
  
  if((max-min)<=k){puts("Yay!");}
  else{puts(":(");}
  
  return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
d = gets.chomp.split(" ").map(&:to_i)

ans = 0

(0..n-1).each do |i|
  (0..n-1).each do |j|
    next if i == j
    ans += d[i] * d[j]
  end
end

puts ans / 2

Measured memory_bytes: 1788
#include <stdio.h>
#include <math.h>
 
typedef struct{
  double x;
  double y;
}P;
 
void kock(int, P, P);
 
int main(){
 
  int n;
  P p1 = {0.0, 0.0}, p2 = {100.0, 0.0};
 
  scanf("%d", &n);
 
  printf("%f %f\n", p1.x, p1.y);
 
  kock(n, p1, p2);
 
  printf("%f %f\n", p2.x, p2.y);
 
  return 0;
}
 
void kock(int n, P p1, P p2){
 
  P s, t, u;
 
  if(n == 0) return 0;
 
  s.x = (p1.x * 2 + p2.x) / 3;
  s.y = (p1.y * 2 + p2.y) / 3;
  t.x = (p1.x + p2.x * 2) / 3;
  t.y = (p1.y + p2.y * 2) / 3;
  u.x = (t.x - s.x) * cos(M_PI / 3) - (t.y - s.y) * sin(M_PI / 3) + s.x;
  u.y = (t.x - s.x) * sin(M_PI / 3) + (t.y - s.y) * cos(M_PI / 3) + s.y;
 
  kock(n-1, p1, s);
  printf("%f %f\n", s.x, s.y);
  kock(n-1, s, u);
  printf("%f %f\n", u.x, u.y);
  kock(n-1, u, t);
  printf("%f %f\n", t.x, t.y);
  kock(n-1, t, p2);
 
}


 

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();
		sc.close();

		if (S.length() <= K) {
			System.out.println(S);
		} else {
			System.out.println(S.substring(0,K) + "...");
		}

	}

}

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

int main()
{
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans = max({a,b,c});
  int sum = pow(2,k)*ans - ans;
  
  cout << a+b+c+sum << endl;
  return 0;
}

Measured memory_bytes: 384