akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 60;
constexpr int INFi = 1 << 29;

int main() {
  ll n, m, l;
  cin >> n >> m >> l;
  vector<vector<ll>> matrix(n, vector<ll>(n, INF));
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    matrix[a][b] = c;
    matrix[b][a] = c;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k][j]);
      }
    }
  }
  vector<vector<int>> matrix2(n, vector<int>(n, INFi));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (matrix[i][j] <= l) {
        matrix2[i][j] = 0;
      }
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        matrix2[i][j] = min(matrix2[i][j], matrix2[i][k] + matrix2[k][j] + 1);
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    if (matrix2[s][t] >= INFi) {
      cout << -1 << endl;
    } else {
      cout << matrix2[s][t] << endl;
    }
  }
}


Measured memory_bytes: 1664
import java.util.Scanner;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
      
      String a ="Sunny";
      String b ="Cloudy";
      String c ="Rainy";
      
      if(S.equals(a)){
      System.out.println(b);
      }
      else if(S.equals(b)){
      System.out.println(c);
      }
      else if(S.equals(c)){
      System.out.println(a);
      }
    }
 }

Measured memory_bytes: 20948
""" 逆元を利用し、nCrを高速で求めるクラス """
class Cmb:
    def __init__(self, N=10**5, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

N,K = map(int,input().split())
A = list(map(int,input().split()))
mod=10**9+7
A.sort()
A_rev = A[::-1]
f_max, f_min = 0, 0
cmb = Cmb(mod=mod)
for i, num in enumerate(A):
    f_max += num*cmb(i, K-1) if i >= K-1 else 0
for i, num in enumerate(A_rev):
    f_min += num*cmb(i, K-1) if i >= K-1 else 0
print((f_max - f_min)%mod)

Measured memory_bytes: 21716
#include <stdio.h>

int main(void)
{
    int n;
    char s[16];
    char new_num[8] = { 0, 1, 2, 3, 5, 7, 8, 9 };
    int i;

    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }

        sprintf(s, "%o", n);
        for (i = 0; s[i] != '\0'; i++){
            if (s[i] >= '5'){
                s[i]++;
            }
            if (s[i] >= '4'){
                s[i]++;
            }
        }
        printf("%s\n", s);
    }

    return (0);
}

Measured memory_bytes: 616
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    internal static void Main(string[] args) {
        var N = int.Parse(ReadLine());
        var txy = new int[] { 0, 0 };
        var ans = "No";

        for (int i = 0; i < N; i++) {
            ans = "No";
            var inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            var t = inp[0];
            var x = inp[1];
            var y = inp[2];
            var time = t - txy[0];
            var move = Math.Abs(x + y - txy[1]);

            if (time < move) { break; }

            if (!(time % 2 == move % 2)) { break; }

            ans = "Yes";
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 17452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
 
const int Nmax=200010;
 
int main() {
	int A,B;
	cin >> A >> B;
	cout << 40 << " " << 100 << endl;
     for(int i=1;i <= 500;i++){
		if(i <= A-1) cout << '#' << '.';
		else cout << '#' << '#';
		if(i%50==0){
			cout << endl;
			for(int j=0;j < 50;j++) cout << '#' << '#';
			cout << endl;
		}
	}
	for(int i=0;i < 50;i++) cout << '.' << '.';
	cout << endl;
	for(int i=1;i <= 500;i++){
		if(i <= B-1) cout << '.' << '#';
		else cout << '.' << '.';
		if(i%50==0 && i!=500){
			cout << endl;
			for(int j=0;j < 50;j++) cout << '.' << '.';
			cout << endl;
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define INF 100000000
#define mod 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}


int main() {
    ll x, y, ans=0;
    cin >> x >> y;
    while(x<=y) {
        x*=2;
        ans++;
    }
    cout << ans;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int A[200][200];
int G[200],X[200],cost,min,result;
	int n,i,j,k;
scanf("%d",&n);
for(i=0;i<n;i++){
	for(j=0;j<n;j++){
		scanf("%d",&A[i][j]);
	}
}

k=1;
X[0] = 0;
G[0] = 1;
for(i=1;i<n;i++){
	G[i] = 0;
}
while(1){
	cost = 2001;
	for(i=0;i<k;i++){
		for(j=0;j<n;j++){
			if(A[X[i]][j] < cost && A[X[i]][j] != -1 && G[j] != 1){
				cost = A[X[i]][j];
				min = j;
			}
		}
	}
	if(k != n){
		X[k] = min;
		G[min] = 1;
		result += cost;
		k++;
	}
	else break;
}

printf("%d\n",result);
return 0;
}

Measured memory_bytes: 684
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		//入力を数値に変換
		Scanner sc = new Scanner(System.in);
		int oto[] = new int[3];

		for (int i = 0; i < 3; i++) {
			oto[i] = sc.nextInt();
		}

		if(oto[0] != 5) {
			int toriaezu = oto[1];
			oto[1] = oto[0];
			oto[0] = toriaezu;
		}

		if(oto[2] != 5) {
			int toriaezu = oto[1];
			oto[1] = oto[2];
			oto[2] = toriaezu;
		}

		if(oto[0] == 5 && oto[1] == 7 && oto[2] == 5) {
			System.out.print("YES");
		}else {
			System.out.print("NO");
		}
}
}


Measured memory_bytes: 21332
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100*s/(w+s)
                            memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
    solve()

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

vector<ll> memo;
vector<int> candidate = {3, 5, 7};

void make_candidate(int digit, ll num) {
	if (digit == 0) {
		memo.push_back(num);
	} else {
		for (auto &n: candidate) {
			make_candidate(digit - 1, num * 10 + n);
		}
	}
}


int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	ll tmp = n;
	
	int digit = 0;
	while (n > 0) {
		digit++;
		n /= 10;
	}
//	cout << digit << endl;
	n = tmp;
	
	FORE(i, 3, digit) {
		make_candidate(i, 0);
	}
	
	int cnt = 0;
	rep(i, memo.size()) {
		if (memo[i] > n) break;
		bool three = false, five = false, seven = false;
		while (memo[i] > 0) {
			if (memo[i] % 10 == 3) three = true;
			else if (memo[i] % 10 == 5) five = true;
			else seven = true;
			memo[i] /= 10;
		}
		if (three && five && seven) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
typedef long long ll;
typedef pair < int , int > Pii;
int main(){
	vector < int > vi;
	rep(i,10){
		int tmp;
		scanf("%d",&tmp);
		vi.push_back(tmp);
	}
	int ans1;
	stable_sort(vi.begin(),vi.end());
	ans1 = vi[9]+vi[8]+vi[7];
	vi.clear();
    rep(i,10){
		int tmp;
		scanf("%d",&tmp);
		vi.push_back(tmp);
	}
	int ans2;
	stable_sort(vi.begin(),vi.end());
	ans2 = vi[9]+vi[8]+vi[7];
	printf("%d %d\n",ans1,ans2);
	return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>

int main(void){
int A,B,C,days,coin;

scanf("%d %d %d",&A,&B,&C);
days=0;
coin=0;
while( coin < C){
days++;
coin = coin + A ;
if(days % 7 == 0){ coin = coin + B;}
}
printf("%d\n",days);
return 0;
}



Measured memory_bytes: 2756
import numpy as np

def main():
    n = int(input())
    a = []
    b = list(map(int, input().rstrip().split(" ")))

    for i in range(n):
        ind = -1
        for j in range(len(b)):
            if b[j] == j + 1:
                if j + 1 == len(b):
                    ind = j
                elif b[j+1] != j + 2:
                    ind = j
        if ind >= 0:
            a.append(b.pop(ind))

    a.reverse()
    if len(a) == n:
        for v in a:
            print(v)
    else:
        print(-1)



if __name__ == '__main__':
   main()

Measured memory_bytes: 12396
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
signed main()
{

    rootdada;
   string s;
   cin>>s;
    if(s=="SUN")
        cout<<7<<endl;
    if(s=="SAT")
        cout<<1<<endl;
    if(s=="MON")
        cout<<6<<endl;
    if(s=="TUE")
        cout<<5<<endl;
    if(s=="WED")
        cout<<4<<endl;
    if(s=="THU")
        cout<<3<<endl;
    if(s=="FRI")
        cout<<2<<endl;
        

}

Measured memory_bytes: 256
#printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


rem = [1,10,9,12,3,4]
s = input().strip()
sr = s[::-1]
n = len(s)
dp = [ [0]*13 for i in range(n) ]
if sr[0]=='?':
    for j in range(10):
        dp[0][j] = 1
else:
    j = int(sr[0])
    dp[0][j] = 1

for i in range(1,n):
    r = rem[i%6]
    if sr[i]=='?':
        for j in range(10):
            for k in range(13):
                dp[i][(k+j*r)%13] = (dp[i][(k+j*r)%13] + dp[i-1][k])%R
    else:
        j = int(sr[i])
        for k in range(13):
                dp[i][(k+j*r)%13] = (dp[i][(k+j*r)%13] + dp[i-1][k])%R

print(dp[n-1][5])


Measured memory_bytes: 62300
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
  int a = scan.nextInt();
    int b =scan.nextInt();
    int c = Math.max(a+b , a-b);
    System.out.println(Math.max(c,a*b));
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
#define st first
#define nd second
#define dokladnosc cout<<fixed<<setprecision(10);
using namespace std;
const int MAX=305;
ld dp[MAX][MAX][MAX];
ld ev[MAX][MAX][MAX];
int cnt[4];
int main()
{
    BOOST;
    dokladnosc;
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        cnt[a]++;
    }
    dp[cnt[1]][cnt[2]][cnt[3]]=1;
    for (int c=n;c>=0;c--)
    {
        for (int b=n;b>=0;b--)
        {
            for (int a=n;a>=0;a--)
            {
                if (a+b+c>n)continue;
                if (a==0 && b==0 && c==0) continue;
                ld p_waste=(ld)(n-a-b-c)/n;
                ld ev_waste=p_waste/(1-p_waste);
                ev[a][b][c]+=ev_waste*dp[a][b][c];
                if (a!=0)
                {
                    ld p_go=(ld)a/(a+b+c);
                    ev[a-1][b][c]+=ev[a][b][c]*p_go;
                    dp[a-1][b][c]+=dp[a][b][c]*p_go;
                }
                if (b!=0)
                {
                    ld p_go=(ld)b/(a+b+c);
                    dp[a+1][b-1][c]+=dp[a][b][c]*p_go;
                    ev[a+1][b-1][c]+=ev[a][b][c]*p_go;
                }
                if (c!=0)
                {
                    ld p_go=(ld)c/(a+b+c);
                    dp[a][b+1][c-1]+=dp[a][b][c]*p_go;
                    ev[a][b+1][c-1]+=ev[a][b][c]*p_go;
                }
            }
        }
    }
    cout<<ev[0][0][0]+cnt[1]+2*cnt[2]+3*cnt[3];
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int>P;

#define INF 2<<29
#define F first
#define S second

int main(){
  ll n,a,b;
  ll ans;
  scanf("%lld %lld %lld",&n,&a,&b);
  
  ans=(a+b*(n-1))-(a*(n-1)+b)+1;

  printf("%lld\n",max(ans,0ll));
  
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
vec(F,0);
vector<vector<pair<ll,ll>>> p(0,vector<pair<ll,ll>>(0));
ll ans=0;
void dfs(ll now,ll end){
  if(now==end){
    bool flag=0;
    rep(i,end){
      if(F[i]==1){
        rep(j,p[i].size()){
          if(F[p[i][j].FI]!=p[i][j].SE){
            i=end;
            flag=1;
            break;
          }
        }
      }
    }
    if(flag==0){
      ll tmp=0;
      rep(i,end){
        if(F[i]==1)tmp++;
      }
      ans=max(ans,tmp);
    }
    return;
  } 
  else{
    F[now]=0;
    dfs(now+1,end);
    F[now]=1;
    dfs(now+1,end);
  }
}


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    ll n;
    cin>>n;
    vec(A,n);
    F.resize(n);
    p.resize(n);
    rep(i,n){
      cin>>A[i];
      p[i].resize(A[i]);
      rep(j,A[i]){
        cin>>p[i][j].FI;
        p[i][j].FI--;
        cin>>p[i][j].SE;
      }
    }
    dfs(0,n);
    op(ans)
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  cout << N*(N+1)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n; cin>>n;
  ll ans=n-1;
  for (ll i=2; i*i<=n; ++i)
    if (n%i==0) {
      ll j=n/i;
      ans=min(ans,i+j-2);
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
s=map(int,input().split())
s=map(int,input().split())
ans = []
for i in s:
    tmp=i
    count=0
    while(1):
        if tmp%2==0:
            tmp=tmp/2
            count=count+1
        else:
            break
    ans.append(count)
print(min(ans))

Measured memory_bytes: 3060
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

x = int(arr_data[0][0])

print(24-x+24)

Measured memory_bytes: 3064
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	int n, m, ai, bi;
	cin >> n >> m;
	vector<int> h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	vector<int> adj[n];
	while (m--) {
		cin >> ai >> bi;
		ai--;
		bi--;
		adj[ai].push_back(bi);
		adj[bi].push_back(ai);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		bool flag = true;
		for (auto ele : adj[i]) {
			if (h[ele] >= h[i])
				flag = false;
		}
		if (flag)
			ans++;
	}
	cout << ans;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 9788
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    int a,b,c; cin >> a >> b >> c;

    if(a<b){
        if(a<c and c<b){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        if(a>c and b<c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}


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

vector<ll> divisor(ll n) {
  vector< ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

int main(){
    ll N; cin >> N;
    vector<ll> t = divisor(N);
    ll n = t.size();
    ll z = t[n-1];
    //cout << z << endl;
    ll ans = 0;
    while(z > 0){
        z /= 10;
        ans++;
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int bubbleSort(int *arr, int size) {
  int flg=1, tmp, cnt=0;
  while (flg) {
    flg=0;
    for (int i=size-1; i>0; i--) {
      if (arr[i]<arr[i-1]) {
        tmp=arr[i-1];
        arr[i-1]=arr[i];
        arr[i]=tmp;
        flg=1;
        cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n;
  scanf("%d", &n);
  int arr[n];

  for (int i=0; i<n; i++) {
    scanf("%d", &arr[i]);
  }

  int cnt=bubbleSort(arr, n);

  for (int i=0; i<n; i++) {
    if (i<n-1) {
      printf("%d ", arr[i]);
    } else {
      printf("%d\n", arr[i]);
    }
  }

  printf("%d\n", cnt);
  return 0;
}


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

typedef long long int ll;
#define f(a, b) for(auto i = a;i < b;i++)

bool sortbysec(const pair<ll, ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 
void solve()
{
	return ;
}
ll mod = 1e9 + 7;
int main()
{
	ll n, m, sum = 0;
	cin >> n >> m;

	// if(n < m){
	// 	cout << "1\n";
	// 	return 0;
	// }

	f(m, n + 2)
	{
		ll x = i - 1, y = n - x;
		x = i*(i + 1)/2;	
		y = y*(i) + x;

		sum += (y - x + 1);
		sum = sum%mod;
	}
	cout << sum << "\n";

}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
const int MAX_STR=80;
int main(){
	int res=0;
	char s[MAX_STR+1];
	while(cin>>s){
		for(int i=0;i<strlen(s);i++){
			if(isdigit(s[i])){
				int t=0;
				for(;i<strlen(s)&&isdigit(s[i]);i++){
					t*=10;
					t+=s[i]-'0';
				}
				res+=t;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc010.contest.atcoder.jp/tasks/agc010_b>
問題文============================================================
 N 個の箱が円環状に並んでおり、i 番目の箱には Ai 個の石が入っています。
 
 以下の操作を繰り返して、全ての石を取り除くことができるか判定してください。
 
 箱を一か所選ぶ。それを i 番目としたとき、1 から N の各 j に対して、i+j 番目の箱から石をちょうど j 個取り除く。
 ただし、N+k 番目と表される箱は k 番目の箱と同一視するものとする。
 各操作において、取り除きたい個数の石がない箱があるときは、その操作を行えないことに注意してください
=================================================================

解説=============================================================

================================================================
*/
string solve(){
    ll N; cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for(auto &in:A){ cin >> in; sum += in; }
    ll x = N*(N+1)/2;
    if(sum%x != 0) return "NO";
    ll k = sum / (N*(N+1)/2);
    for(int i = 0; i < N;i++){
        ll d = A[(i+1)%N] - A[i];
        if(d - k > 0 || abs(d-k)%N != 0) return "NO";
    }
    return "YES";
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  ll n, p;
  cin >> n >> p;
  if (n == 1)
  {
    cout << p << endl;
    return 0;
  }

  ll q = p;
  ll ans = 1;
  for (ll i = 2; i * i <= p; i++)
  {
    int cnt = 0;
    while (q % i == 0)
    {
      q /= i;
      cnt++;
    }
    rep(j, cnt / n) ans *= i;
  }

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


Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;
#define int long long

void add(int& i , int j){
	i += j ;
	if(i >= MOD)
		i -= MOD ;	
}

int32_t main(){_
	int n,k ;
	cin >> n >> k ;
	vi a(k) ;
	inp(a) ;
	vi dp(n+1) ;
	for(int i = 0 ; i < k ; i++)
		dp[a[i]] = -1 ;
	dp[0] = 1 ; 
	if(dp[1] == 0) dp[1] = 1 ;	
	for(int i = 2 ; i <= n ; i++){
		if(dp[i] == -1 && dp[i-1] == -1){
			return cout << 0 , 0 ;
		}
		if(dp[i] == -1) continue ;
		if(dp[i-1] != -1) add(dp[i], dp[i-1]) ;
		if(dp[i-2] != -1) add(dp[i], dp[i-2]) ;
	}
	cout << dp[n] << endl ;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  string s = "a";
  if (n == 1) {
    cout << s << endl;
    return 0;
  }

  string goal;
  for (char c = 'a'; c < 'a' + n; c++) goal.push_back(c);
  vector<vector<pair<string, char>>> dp(n, vector<pair<string, char>>(0));
  dp[0].push_back({"a", 'a'});
  string t;
  for (ll i = 1; i < n; i++) {
    for (ll j = 0; j < dp[i - 1].size(); j++) {
      for (char c = 'a'; c <= dp[i - 1][j].second + 1; c++) {
        t = dp[i - 1][j].first;
        t.push_back(c);
        if (c < dp[i - 1][j].second + 1) dp[i].push_back({t, dp[i - 1][j].second});
        else dp[i].push_back({t, dp[i - 1][j].second + 1});
      }
    }
  }
  for (ll i = 0; i < dp[n - 1].size(); i++) cout << dp[n - 1][i].first << endl;
}

Measured memory_bytes: 10736
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    string s;cin>>s;
    int ans=1;
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int s;
    cin>>s;
    int d=1e9;
    rep(x,d+1){
        if((s+x)%d==0){
            cout<<"0 0 "<<d<<sp<<1<<sp<<x<<sp<<(s+x)/d<<endl;
            return;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline void read(int &x){
    char c = getchar();
    int p = 1;
    x = 0;
    while(!isdigit(c)){
        if(c == '-')p = -1;
        c = getchar();
    }
    while(isdigit(c)){
        x = (x << 1) + (x << 3) + (c ^ '0');
        c = getchar();
    }
    x *= p;
}
#define mp make_pair
string vec1, vec2;
map<pair<string, string>, int>ma;
char s[50];
int n, ans;
signed main(){
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    read(n);
    scanf("%s", s);
    int lim = 1 << n;
    for(register int i = 0; i < lim; ++i){
        vec1.clear(), vec2.clear();
        for(register int j = 0; j < n; ++j){
            if(1 & (i >> j))vec1.push_back(s[j]);
            else vec2.push_back(s[j]);
        }
        /*for(auto a : vec1){
            printf("%c", a);
        }
        puts("");*/
        ma[mp(vec1, vec2)]++;
    }
    for(register int i = 0; i < lim; ++i){
        vec1.clear(), vec2.clear();
        for(register int j = n - 1; j >= 0; --j){
            if(!(1 & (i >> j)))vec1.push_back(s[j + n]);
            else vec2.push_back(s[j + n]);
        }
        /*for(auto a : vec2){
            printf("%c", a);
        }
        puts("");*/
        ans += ma[mp(vec1, vec2)];
        //cout<<ma[vec2]<<endl;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 91904
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <math.h>
#include <memory.h>
#include <stdio.h>

#include <algorithm>
#include <complex>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define left asdgashgrketwjklrej
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-12
#define M_PI 3.141592653589793
#define bsize 1024

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 1100031;

int n;
string st[N];
int C;
int is_terminal[26*N];
int parent[N];
int son[N][26];
long long ans;
int count_with[N][26];
int edge_letter[N];
int already_have[30];
int subtree_size[N];

void add_to_trie(string st){
	int cur=0;
	for (int i=0;i<st.size();i++){
		int id=st[i]-'a';
		if (son[cur][id]==0){
			++C;
			son[cur][id]=C;
			parent[C]=cur;
			edge_letter[C]=id;
		}
		cur=son[cur][id];
	}
	is_terminal[cur]=1;
	for (int i=0;i<26;i++){
		already_have[i]=0;
	}
	while (cur>0){
		subtree_size[cur]++;
		already_have[edge_letter[cur]]=1;
		cur=parent[cur];
		for (int i=0;i<26;i++){
			if (already_have[i])
				count_with[cur][i]++;
		}
	}
}

int main() {
   //freopen("input.txt", "r", stdin);
   //freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(0);
  // cin.tie(0);

  cin>>n;

  for (int i=1;i<=n;i++){
	  cin>>st[i];
  }

  for (int i=1;i<=n;i++){
	  reverse(st[i].begin(),st[i].end());
	  add_to_trie(st[i]);
  }

  for (int i=1;i<=C;i++){
	  if (is_terminal[i]){
		  int Q=parent[i];
		  int interesting_letter=edge_letter[i];
		  for (int j=0;j<26;j++){
			  if (son[Q][j]>0){
				  int to=son[Q][j];
				  if (j!=edge_letter[i])
					  ans+=count_with[to][interesting_letter];
				  else
				  {
					  ans+=subtree_size[to];
				  }
			  }
		  }
		  --ans; // with itself
	  }
  }

  cout<<ans<<endl;

  cin.get(); cin.get();
  return 0;
}


Measured memory_bytes: 255872
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        
        int res = 0;
        for(int a = 0; a <= A; a++) {
        	for(int b = 0; b <= B; b++) {
        		int c = (X - a * 500 - b * 100) / 50;
        		if(c >= 0 && c <= C) {
        			res ++;
        		}
        	}
        }
        
        System.out.println(res);
    }
}

Measured memory_bytes: 23892
def resolve():
	# N: 足場の個数, K: 1回で右にジャンプできる足場の数
	N, K = map(int, input().split())
	# h: 各足場の高さ
	# dpテーブル宣言: dp[今いる足場の番号-1]=[最小コスト, 足場の高さ]
	dp = [
		[float('inf'), int(h_)]
		for h_ in input().split()
	]
	dp[0][0] = 0
	dp[1][0] = abs(dp[0][1] - dp[1][1])

	# k個左の足場からジャンプして来た時の最小コストを調べる
	for n in range(2, N):
		index_0 = max(0, n-K)
		h_ = dp[n][1]
		dp[n][0] = min(
			[
				abs( h_ - dp_[1] ) + dp_[0]
				for dp_ in dp[index_0:n]
			]
		)
	print(dp[N-1][0])

resolve()

Measured memory_bytes: 25040
import java.util.*

fun main(args: Array<String>) {
	val S = Scanner(System.`in`).next()
	var ans = 0
	for (i in 0 until S.length) {
		if (i % 2 == S[i].toString().toInt()) {
			ans++
		}
	}
	println(if (S.length / 2 < ans) S.length - ans else ans)
}


Measured memory_bytes: 38776
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y = map(int, readline().split())

    print(X + Y // 2)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://sen-comp.hatenablog.com/entry/2019/11/17/003150, 解法1
// https://atcoder.jp/contests/abc145/submissions/15274857
int dp[2][3005][3005];
void solve() {
    int n, t;
    cin >> n >> t;
    
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    
    rep(i, n) for (int j = t; j >= 1; --j) {
        chmax(dp[0][i + 1][j], dp[0][i][j]);
        if (j - a[i] < 1) continue;
        chmax(dp[0][i + 1][j - a[i]], dp[0][i][j] + b[i]);
    }
    for (int i = n - 1; i >= 0; --i) for (int j = t; j >= 1; --j) {
        chmax(dp[1][i][j], dp[1][i + 1][j]);
        if (j - a[i] < 1) continue;
        chmax(dp[1][i][j - a[i]], dp[1][i + 1][j] + b[i]);
    }
    
    int ans = 0;
    rep(i, n) rep3(j, 1, t + 1) chmax(ans, dp[0][i][j] + b[i] + dp[1][i + 1][t + 1 - j]);
    cout << ans << endl;
}



Measured memory_bytes: 74096
#include <iostream>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
int main()
{
	fast 
	string s;
	cin>>s;
	if(s=="Sunny")
	{
		cout<<"Cloudy\n";
	}
	else if(s=="Cloudy")
	{
		cout<<"Rainy\n";
	}
	else
	{
		cout<<"Sunny\n";
	}
	
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<long long>X(N);
	vector<long long>Y(N);
	vector<long long>Z(N);
	for (int i = 0;i<N;++i) {
		cin >> X[i] >> Y[i] >> Z[i];
	}
	long long ans = 0;
	for (int i = 0;i <(1<<3);++i) {
		vector<long long>P(N);
		for (int j = 0;j<N;++j) {
			if ((i >> 0)&1) {
				P[j] += X[j];
			}
			else {
				P[j] -= X[j];
			}
			if ((i >> 1) & 1) {
				P[j] += Y[j];
			}
			else {
				P[j] -= Y[j];
			}
			if ((i >> 2) & 1) {
				P[j] += Z[j];
			}
			else {
				P[j] -= Z[j];
			}
		}
		std::sort(P.rbegin(), P.rend());
		long long anstmp = 0;
		for (int j = 0; j < M; ++j) {
			anstmp += P[j];
		}
		ans = max(ans , anstmp);
	}
	cout << ans <<  endl;
	return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main(){
    int n,t;
    scanf("%d%d",&n,&t);
    int res=0;
    int remain=0;
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        res+=(x+t);
        res-=max(x,remain);
        remain=x+t;
    }
    printf("%d\n",res);
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[100];
    for(int i=0;i<n;i++)cin >>a[i];
    for(int i=0;i<n;i++){
        cout << a[n-i-1];
        if(n-1-i!=0)cout << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>

#define MAXN 100000

typedef long long ll;

using namespace std;

ll A[MAXN];

int main()
{
  int N;
  int ans = 0;
  int cnt = 0;
  ll pre;

  cin >> N;
  for ( int i = 0; i < N; ++i ) scanf("%ld", &A[i]);

  sort ( A,A+N);

  pre = A[0];
  for ( int i = 0; i < N; ++i ) {
    if ( A[i] == pre ) {
      ++cnt;
    } else {
      if ( cnt % 2 == 1 ) ++ans;
      pre = A[i];
      cnt = 1;
    }
  }
  if ( cnt % 2 == 1 ) ++ans;

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


Measured memory_bytes: 1280
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string s,t;cin>>s>>t;

  V<ll> res(siz(s)-siz(t)+1,0);

  rep(i,0,siz(s)){
    rep(j,0,min(siz(t),i+1)){
      if(i-j>=siz(res))continue;
      
      if(s[i]!=t[j]) res[i-j]++;
    }
  }

  ll ans=INF;
  rep(i,0,siz(res))chmin(ans,res[i]);
  cout<<ans<<ENDL;


}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3644
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


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

    if min(A) != 1:
        print(-1)
        return

    c = 1
    ans = 0

    for a in A:
        if a == c:
            c += 1
        else:
            ans += 1
    
    print(ans)

main()


Measured memory_bytes: 26520
let m=1000000open Array;;let a,b=make m 1,make m 0;;a.(0)<-0;;let rec($)i j=if i*j<m then(a.(i*j)<-0;i$(j+1))and g i=if i<m then(if a.(i)=1then i$2;b.(i)<-b.(i-1)+a.(i);g(i+1))in g 2;;let rec f()=f(Printf.printf"%d
"b.(read_int()));;try f()with _->()

Measured memory_bytes: 18268
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[310][310], chk[310][310];
long long res;
int main() {
	int i, j, k;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			scanf("%d", &w[i][j]);
		}
	}
	for (k = 1; k <= n; k++) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				if (w[i][j] > w[i][k] + w[k][j]) {
					puts("-1");
					return 0;
				}
				if (w[i][j] == w[i][k] + w[k][j] && i != k && k != j)chk[i][j] = 1;
			}
		}
	}
	for (i = 1; i <= n; i++)for (j = i + 1; j <= n; j++)if (!chk[i][j])res += w[i][j];
	printf("%lld\n", res);
}

Measured memory_bytes: 896
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

ll mod=pow(10,9)+7;

struct Combination{
    vec n,n_rev;

    Combination(int N){
        n.resize(N+1);
        n_rev.resize(N+1);
        n[0]=1;n_rev[1]=1;
        for(int i=1;i<=N;i++){
            n[i]=((ll)i*n[i-1])%mod;
        }
        for(int i=2;i<=N;i++){
            n_rev[i]=matpow(n[i],mod-2);
        }
    }

    //累乗(aのk乗)
    ll matpow(ll a,int k){
        ll dp=1,mt=a;
        while(k>0){
            if(k & 1)dp=(dp*mt)%mod;
            mt=(mt*mt)%mod;
            k/=2;
        }
        return dp;
    }

    int comb(ll N,ll r){  
        if(r==0 || N==r)return 1;
        return (((n[N]*n_rev[r])%mod)*n_rev[N-r])%mod;
    }
};

int main(){
    ll X,Y;cin>>X>>Y;
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    else{
        int m,n;
        m=(2*Y-X)/3;
        n=(2*X-Y)/3;
        if(m<0 || n<0){
            cout<<0<<endl;
            return 0;
        }
        else{
            Combination Comb(m+n);
            cout<<Comb.comb(m+n,m)<<endl;
            return 0;
        }
    }
}

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

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

    int temp =stoi(a+b);
    //cout << temp << endl;
    int rt = (int)sqrt(temp);
    if(rt * rt == temp) {
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
//IOI 2021

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const double pi = 3.14159265359;

double a, b, x;
double ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a >> b >> x;
	if (x <= (a * a * b) / 2) {
		double alpha = 2 * x / (b * a);
		ans = atan((1. * b / alpha)) * 180 / pi;
	}
	else {
		double alpha = 2. * x / (a * a) - b;
		double t = (alpha * a) / (b - alpha);
		ans = atan(1. * b / (a + t)) * 180 / pi;
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 256