akhauriyash/Code-Regression huggingface dataset:
program double_factorial
  implicit none
  integer(8) :: n, x = 0
  read(*,*) n
  if (mod(n,2) == 1) then
    write(*,'(i0)') 0
    stop
  end if
  n = n/2
  do while (n > 0)
    x = x+n/5
    n = n/5
  end do
  write(*,'(i0)') x
end program double_factorial

Measured memory_bytes: 640
# input
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
  w[i], v[i] = map(int, input().split())

V = 1000 * N

# DP
dp = [[float('inf')] * (V + 1) for i in range(N + 1)]
dp[0][0] = 0

for i in range(N):
  for j in range(V + 1):
    if j - v[i] >= 0:
      dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
    else:
      dp[i + 1][j] = dp[i][j]

ans = 0
for i in range(V + 1):
  if dp[N][i] <= W:
    ans = i

print(ans)

Measured memory_bytes: 311448
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        try(Scanner sc = new Scanner(System.in)){
            int i=0;
            int w=sc.nextInt();
            int n=sc.nextInt();
            int[] values = new int[w];
            for(i=0;i<w;i++){
                values[i]=i+1;
            }
            for(i=0;i<n;i++){
                String str = sc.next();
                String[] ab =str.split(",");
                int a = Integer.parseInt(ab[0]);
                int b = Integer.parseInt(ab[1]);
                int c = values[a-1];
                values[a-1] = values[b-1];
                values[b-1] = c;
            }
            for(i=0;i<w;i++){
                System.out.println(values[i]);
            }
        }
    }
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> a(3*n); rep(i, 3*n) cin >> a[i];
    priority_queue<int, vector<int>, greater<int>> pql;
    priority_queue<int> pqr;

    vector<ll> suml(3*n+1, 0);
    vector<ll> sumr(3*n+1, 0);
    ll numl = 0;
    rep(i, n) {
        pql.push(a[i]);
        numl += a[i];
    }
    for (int i = n; i <= 2*n; i++) {
        suml[i] = numl;
        pql.push(a[i]);
        numl = numl + (ll)a[i] - (ll)pql.top();
        pql.pop();
    }

    ll numr = 0;
    for (int i = 3*n-1; i >= 2*n; i--) {
        pqr.push(a[i]);
        numr += a[i];
    }
    for (int i = 2*n; i >= n; i--) {
        sumr[i] = numr;
        pqr.push(a[i-1]);
        numr = numr + (ll)a[i-1] - (ll)pqr.top();
        pqr.pop();
    }

    ll ans = -LINF;
    for (int i = n; i <= 2*n; i++) {
        ans = max(ans, suml[i]-sumr[i]);
    }
    cout << ans << endl;


    return 0;
}


    


Measured memory_bytes: 7288
#include <stdio.h>

static long n, k;
static long i, sum;

int main(void) {
    scanf("%ld%ld", &n, &k);
    sum = k;
    for (i = 1; i < n; ++i)
        sum *= k - 1;
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n, m, i, c = 0;
	cin >> n;
	vector<long> vN(n, 0);
	for(i = 0; i < n; ++i) cin >> vN[i];
	cin >> m;
	vector<long> vM(m, 0);
	for(i = 0; i < m; ++i) cin >> vM[i];
	for(i = 0; i < m; ++i){
		if(std::binary_search(vN.begin(), vN.end(), vM[i]))
			++c;
	}

	cout << c << "\n";

	return 0;
}

Measured memory_bytes: 2324
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#include <queue>
#include<map>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define PI 3.14159265358979323846264338327950


int main() {
	ll a, b, c, d, mod = 1000000007, x = 0, flagx = 0, flagy = 0, ans = -1000000000000000000;

	cin >> a >> b >> c >> d;

	if (ans < a*c)	ans = a*c;
	if (ans < a*d)	ans = a*d;
	if (ans < b*c)	ans = b*c;
	if (ans < b*d)	ans = b*d;


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

Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
const int mx = 200;
int main()
{
    int n, k;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >>k;
    int a,res = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        res += a >= k;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[] p=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int a=0,b=0,c=0;
		for(int i=0;i<n;i++){
			if(p[i]<=s[0]){a++;}
			else if(p[i]<=s[1]){b++;}
			else{c++;}
		}
		Console.WriteLine("{0}",Math.Min(c,Math.Min(a,b)));
	}
}

Measured memory_bytes: 13140
def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ?????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ????????????§?????????????????????-> ??°?????????????????????¶???????????????????
    3. 2?????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)
 
    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])
 
    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))
 
if __name__ == "__main__":
    first = True
    while (True):
        total_fee = int(input(''))
        if total_fee == 0:
            break
        if first:
            first = False
        else:
            print('')
        coins = input('')
        coins = coins.split(' ')  # 10, 50, 100, 500?????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)

Measured memory_bytes: 7776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-8;
////////////////////////////////////////



int main(){
    ll n,m;cin>>n>>m;
    ll x[n][3];rep(i,0,n-1)rep(j,0,2)cin>>x[i][j];
    ll ans=0;
    rep(i,0,7){
        vector<ll>v;
        rep(j,0,n-1){
            ll c=0;
            if(i%2<=0)c+=x[j][0];
            else c-=x[j][0];
            if(i%4<=1)c+=x[j][1];
            else c-=x[j][1];
            if(i%8<=3)c+=x[j][2];
            else c-=x[j][2];
            v.pb(c);
        }
        sort(v.begin(),v.end());
        ll sum=0;
        rep(i,0,m-1){
            sum+=v[n-1-i];
        }
        Max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    int n; cin >> n;
    if(n % 2 == 0) {
        cout << n / 2;
    }
    else{
        cout << (n/ 2) + 1;
    }
    return 0;
}

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

const int N = 9;
int l[N];
int n,a,b,c;

int dfs(int cur, int ca,int cb, int cc ){
    if(cur == n){
        if(ca*cb*cc)return abs(a-ca)+ abs(b - cb)+abs(c-cc) - 30;
        else return 1e9;
    }
    int ret0 = dfs(cur+1, ca, cb, cc);
    int ret1 = dfs(cur+1, ca+l[cur], cb, cc) + 10;
    int ret2 = dfs(cur+1, ca, cb+l[cur], cc) + 10;
    int ret3 = dfs(cur+1, ca, cb, cc+l[cur]) + 10;
    return min(min(ret0, ret1),min(ret2, ret3));
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin>>n>>a>>b>>c;
    for(int i = 0; i< n; i++)cin>>l[i];
    
    
    cout<<dfs(0,0,0,0)<<endl;
    

    return 0;
}





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

int main() {
  vector<int> a(5, 0);
  for (int i = 0; i < 5; ++i) {
    cin >> a[i];
  }
  
  int k = 0;
  cin >> k;
  
  bool flag = false;
  for (int i = 0; i < 5; ++i) {
    for (int j = i + 1; j < 5; ++j) {
      if (abs(a[i] - a[j]) > k) {
        flag = true;
      }
    }
  }
  
  if (flag == true) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  
  return 0;
}

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

namespace Test
{
    class ForStudy
    {
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();
            for (int i = 0; i < str.Length; i++)
            {
                if (char.IsLower(str[i]))
                {
                    Console.Write(char.ToUpper(str[i]));
                }
                else if (char.IsUpper(str[i]))
                {
                    Console.Write(char.ToLower(str[i]));
                }
                else
                {
                    Console.Write(str[i]);
                }
            }
            Console.WriteLine();
        }
    }
}




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

using namespace std;

template<typename T>
class Dijkstra {
 public:
  int n;
  T INF = numeric_limits<T>::max();
  vector< vector< pair<int,T> > > g;
  vector<T> dis;
  vector<int> prev;
  
  Dijkstra(int _n) : n(_n) {
    g.resize(n);
  }

  void add_edge(int u, int v, T w) {
    assert(0 <= u && u < n && 0 <= v && v < n);
    assert(w >= 0);
    g[u].emplace_back(v, w);
  }

  vector<T> short_path(int s) {
    dis = vector<T>(n, INF);
    prev = vector<int>(n, -1);

    set< tuple<T,int,int> > bag; // cost, vertex, prev
    bag.insert(make_tuple(0, s, -1));
    while (bag.size()) {
      int u, v, p;
      T w, cost;
      tie(cost, u, p) = *bag.begin();
      bag.erase(bag.begin());
      if (dis[u] > cost) {
        dis[u] = cost;
        prev[u] = p;
        for (auto i : g[u]) {
          tie(v, w) = i;
          bag.insert(make_tuple(w + cost, v, u));
        }
      }
    }
    return dis;
  }
};

int main() {
  ios_base::sync_with_stdio(false);

  const int MAXC = 1e6 + 5;
  int n, m, u, v, w;
  cin >> n >> m;
  vector<vector<pair<int,int>>> edges(MAXC);
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    u--; v--;
    edges[w].emplace_back(u, v);
  }

  vector<vector<int>> g(n);
  vector<int> color(n, -1), touched;
  function<void(int,int)> dfs = [&](int u, int c) {
    color[u] = c;
    for (auto v : g[u]) {
      if (color[v] == -1) {
        dfs(v, c);
      }
    }
  };

  Dijkstra<int> dijk(n + MAXC);
  int iter = 0;

  for (auto s : edges) {
    for (auto e : s) {
      tie(u, v) = e;
      g[u].push_back(v);
      g[v].push_back(u);
      touched.push_back(u);
      touched.push_back(v);
    }
    for (auto i : touched) {
      if (color[i] == -1) {
        dfs(i, iter);
        iter++;
      }
    }
    // undo and build dijkstra
    for (auto e : s) {
      tie(u, v) = e;
      dijk.add_edge(u, color[u] + n, 1);
      dijk.add_edge(v, color[v] + n, 1);
      dijk.add_edge(color[u] + n, u, 0);
      dijk.add_edge(color[v] + n, v, 0);
    }
    for (auto i : touched) {
      color[i] = -1;
      g[i].clear();
    }
    touched.clear();
  }

  auto dis = dijk.short_path(0);
  int ans = dis[n - 1];
  if (ans == dijk.INF) ans = -1;
  cout << ans << '\n';

  return 0;
}
 


Measured memory_bytes: 101176
let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s1 (s2 :: acc)
  in
  doit str []

let () =
  let open Queue in
  let (que : (string * int) Queue.t) = create () in
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> begin
      let rec read i =
        if i < n then begin
          match split (read_line ()) ' ' with
          | [s; t] -> (add (s, int_of_string t) que; read (i + 1))
          | _ -> exit 1
        end
      in
      read 0;
      let rec doit cnt =
        if not (is_empty que) then begin
          let s, t = take que in
          let rest = t - q in
          if rest <= 0 then (let x = cnt + t in print_string s; print_char ' '; print_int x; print_char '\n'; doit x)
          else (add (s, rest) que; doit (cnt + q))
        end
      in
      doit 0
    end
  | _ -> exit 1

Measured memory_bytes: 10608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  A, B, a, b, d, e, count;
  cin >> A >> B;
      
   for (;A < B+1 ;A++){
    a = A / 10000;
    b = A % 10000 /1000;
    d = A % 100 / 10;
    e = A % 10;
    if(a == e && b == d){
      count++;
    }
   }
  cout << count <<endl;
}
    

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>
#include <stack>
#include <functional>

// AtCoder
#include <atcoder/all>
using namespace atcoder;

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    scc_graph graph(n);
    rep (_, m) {
        int a, b; cin >> a >> b;
        graph.add_edge(a, b);
    }
    auto ans = graph.scc();
    cout << ans.size() << "\n";
    for (auto v : ans) {
        cout << v.size();
        for (auto x : v) cout << " " << x;
        cout << "\n";
    }
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<a.size(); i++){
      cin >> a.at(i);
  }
  int64_t sum=0;
  int ma=a.at(0), mi=a.at(0);
  for(int x : a){
      sum+=x;
      ma=max(ma,x);
      mi=min(mi,x);
  }
  printf("%d %d %ld\n",mi, ma, sum);
  return 0;
}



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

using namespace std;

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

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

//#define int long long

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

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


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

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

    int N; cin >> N;
    map<int,int> mp;
    VL a(N), b(N);
    REP(i,N) {
        int tmp;
        cin >> tmp;
        a[i] = tmp;
        b[i] = tmp;
        mp[tmp]++;
    }
    sort(b.begin(),b.end());

    b.erase(unique(b.begin(),b.end()),b.end());

    int l = b.size();
    if(N%3 == 0){
        dump(l)
        if(l > 3){
            cout << "No" << endl;
            return 0;
        }
        else if(l == 3){
            LL x,y,z;
            x = b[0];
            y = b[1];
            z = b[2];

            if((x ^ y) == z){
                if(mp[x] == mp[y] && mp[y] == mp[z]){

                    cout << "Yes" << endl;
                }
                else{
                    cout << "No" << endl;
                }
            }
            else{
                cout << "No" << endl;
            }
        }
        else if(l == 1){
            if(b[0] == 0){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }

        }
        else{
            LL x,y;
            x = b[0];
            y = b[1];
            if(x == 0){
                if(mp[y] == 2 * mp[x]){
                    cout << "Yes" << endl;
                }
                else{
                    cout << "No" << endl;
                }
            }
            else{
                cout << "No" << endl;
            }
        }


    }
    else{
        if(l == 1){
            if(b[0] == 0){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
        else{
            cout << "No" << endl;
        }
    }


}


Measured memory_bytes: 5120
/*
 * test.cpp
 *
 *
 *      Author: Fireworks
 */

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
#include<bitset>
#include<set>
#include<iomanip>
#include<fstream>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<list>
#include<sstream>

using namespace std;

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;



int main(){
	int n;
	cin>>n;
	vector<long long> a(3*n,0);
	for(int i=0;i<3*n;i++) cin>>a[i];

	vector<long long> pre(3*n,0);
	long long s = 0;
	priority_queue<long long,vector<long long>,greater<long long> > pq;
	for(int i=0;i<n;i++){
		pq.push(a[i]);
	}
	for(int i=n;i<=2*n;i++){
		pre[i]=s;
		pq.push(a[i]);
		s+=pq.top();
		pq.pop();
	}

	priority_queue<long long> pq2;
	for(int i=2*n;i<3*n;i++){
		pq2.push(a[i]);
	}
	s=0;
	vector<long long> suf(3*n,0);
	for(int i=2*n-1;i>=n;i--){
		pq2.push(a[i]);
		s+=pq2.top();
		pq2.pop();
		suf[i]=s;
	}
	vector<long long> presum = a,sufsum = a;
	for(int i=1;i<3*n;i++) presum[i]+=presum[i-1];
	for(int i=3*n-2;i>=0;i--) sufsum[i]+=sufsum[i+1];
	long long ans = -large;
	for(int i=n;i<=2*n;i++){
		ans=max(ans,presum[i-1]-pre[i]-sufsum[i]+suf[i]);
	}
	cout<<ans<<endl;



	/*int totalcase;
	int testcase=0;
	cin>>totalcase;
	ofstream out;
	out.open("result.txt");

	while(totalcase--){
		testcase++;
		out<<"Case #"<<testcase<<": ";
		cout<<testcase<<": "<<endl;

		//GOGOGO


		//END
	}
	out.close();*/

	return 0;
}


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

ll visit[4000000],ar[5000500],len=0;
map<string , int>mp;
string s,ss[100000];


int main()
{

    ll i,j,k,n,mx=-19999999999,tc,a,b,c,ans=0,m1,m2;
    cin>>n;
    for(i=0;i<n-1;i++){
        cin>>ar[i];
        ans+=ar[i];
    }
    ans+=ar[0];
    for(i=0;i<n-2;i++)
    {
        if(ar[i]>ar[i+1])
            ans-=ar[i]-ar[i+1];
    }
    cout<<ans<<endl;






    return 0;
}


Measured memory_bytes: 1024
a,b,c,d=map(int,input().split())
e=list(map(int,input().split()))
f=list(map(int,input().split()))
#print(f)
e.sort()
f.sort()
if e[-1]<f[0]:
	if c<(e[-1]+f[0])/2<=d:
		print("No War")
	else:
		print("War")
else:
	print("War")


Measured memory_bytes: 3060
//BISMILLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,c,k,sum=0,flag,humty,div;
   cin>>a>>b>>c>>k;

   if(k>=a)
   {
       sum+=a*1;
       k=k-a;
   }
   else
   {
       sum+=k*1;
       k=0;
   }

   if(k>=b)
   {
      sum+=b*0;
      k=k-b;
   }
   else if(k>0)
   {
       sum+=k*0;
       k=0;
   }
   //cout<<sum<<endl;

   sum=sum+(-k);
   //else sum+=c*(-1);


  cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 3636
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
    }

    if n==1 {
        match m {
            1 => println!("1"),
            _ => println!("{}", m-2),
        }
        return;
    }

    if m==1 {
        println!("{}", n-2);
        return;
    }

    println!("{}", (n-2)*(m-2));

}


Measured memory_bytes: 2184
#include<stdio.h>        
int main() {
       
int a[3000], b[3000], i, t = 0;
          
for (i = 0; i < 3000; i ++)
 scanf ("%d" "%d", &a[i], &b[i]);
      
while (a[t] != 0 || b[t] != 0) {
      
if(a[t] <= b[t])
printf ("%d %d\n",a[t],b[t]);
      
if(b[t] < a[t])
 printf("%d %d\n",b[t],a[t]);
      
t = t + 1;
  
}
         
return 0;
          
}

Measured memory_bytes: 620
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        s: chars,
        k: usize,
    }

    let mut burst = None;

    for i in 0..s.len() {
        if s[i] != '1' {
            burst = Some(i + 1);
            break;
        }
    }

    if let Some(index) = burst {
        if index <= k {
            println!("{}", s[index - 1]);
        } else {
            println!("1");
        }
    } else {
        println!("1");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main(){
    int A, B, C; cin >> A >> B >> C;
    cout << min(C, B/A) << endl;
    return 0;
}


Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 8e5+5;

string s;
char act[N];

int q;

int main(){
    string s;
    cin >> s;
    int q , l , r , turn = 0;
    cin >> q;
    for(int i = 3e5; i < s.size() + 3e5; i++){
        act[i] = s[i - 3e5];
    }
    l = 3e5;
    r = 3e5 + s.size() - 1;
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            turn++;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(turn % 2 == 0){
                if(f == 1){
                    l--;
                    act[l] = c;
                } else {
                    r++;
                    act[r] = c;
                }
            } else {
                if(f == 1){
                    r++;
                    act[r] = c;
                } else {
                    l--;
                    act[l] = c;
                }
            }
        }
    }
    if(turn & 1){
        int L = l;
        int R = r;
        while(L < R){
            swap(act[L] , act[R]);
            L++;
            R--;
        }
    }
    for(int i = l; i <= r; i++){
        cout << act[i];
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
  	string s,t;
    int count = 0;

    cin >> s;
  	cin >> t;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]){
            count++;
        }
    }
  	
	cout << count << endl;
    return 0;
}


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

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;


map<ll, string> st;
int main() {

    ll N,M;
    cin >> N >> M;

    //p県
    vector <pair<ll,ll>> py(M);


    REP(i,M)
    {
        cin >> py[i].first >> py[i].second;
    }

    vector <pair<ll,ll>> moto(M);

    moto = py;

    sort(py.begin(),py.end());

    //同じ県なら振り直す
    ll ken = -1;
    ll cnt = 1;

    REP(i,M)
    {
        if(ken == py[i].first)
        {
            cnt++;
        }
        else
        {
            cnt = 1;
            ken = py[i].first;

        }

        //年で紐付け
        std::ostringstream sout;
        sout << std::setfill('0') << std::right << std::setw(6) << py[i].first; // "000000"
        sout << std::setfill('0') << std::right << std::setw(6) << cnt; // "000000"
        string tmp = sout.str();

        st[py[i].second] = tmp;
    }

    REP(i,M)
    {  
        cout << st[moto[i].second] << endl;
    }



    return 0;

}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

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

    bool flag = true;
    map<int, int> list;
    rep(i, n){
        int a; cin >> a;
        if(list.count(a)){
            OP("NO");
            flag = false;
            break;
        }else{
            list[a] += 1;
        }
    }
    if(flag) OP("YES");
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if ((a<c&&c<b) || (b<c&&c<a)) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
int vmax = 100000;
vint ae(vmax+1,0);
vint ao(vmax+1,0);
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int o,e;
    int me1[2]={0,0};
  	int me2[2]={0,0};
  	int mo1[2]={0,0};
  	int mo2[2]={0,0};
    REP(i,n){
        int v;
        cin >> v;
        if(i%2==0){
            ae[v]++;
            if(me1[0]==v){
                me1[1]++;
            }else if(ae[v]>me1[1]){
                me2[0]=me1[0];
                me2[1]=me1[1];
                me1[0]=v;
                me1[1]=ae[v];
            }else if(me2[0]==v){
                me2[1]++;
            }else if(ae[v]>me2[1]){
                me2[0]=v;
                me2[1]=ae[v];
            }
        }else{
            ao[v]++;
            if(mo1[0]==v){
                mo1[1]++;
            }else if(ao[v]>mo1[1]){
                mo2[0]=mo1[0];
                mo2[1]=mo1[1];
                mo1[0]=v;
                mo1[1]=ao[v];
            }else if(mo2[0]==v){
                mo2[1]++;
            }else if(ao[v]>mo2[1]){
                mo2[0]=v;
                mo2[1]=ao[v];
            }
        }
    }
    int ne = n/2;
    int no = n/2;
  	//cout << ne << endl;
  	//cout << me1[1] << endl;
  	//me1[1] +=0;
  	//me2[1] +=0;
  	//mo1[1]+=0;
  	//mo2[1]+=0;
  	//cout << mo2[1] << endl;
    me1[1]=ne-me1[1];
    mo1[1]=no-mo1[1];
    me2[1]=ne-me2[1];
    mo2[1]=no-mo2[1];
  	//cout << me1[1] << " "<<me2[1] <<" " << mo1[1] <<" " <<mo2[1]<< endl;
    if(me1[0]==mo1[0]){
        cout << min(me1[1]+mo2[1],mo1[1]+me2[1]) << endl;       
    }else{
        cout << me1[1]+mo1[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
    ll n,m;cin>>n>>m;
    vector<ll> s(n),t(m);

    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];

    vector<vector<ll>> dp(2010,vector<ll>(2010,0));
    vector<vector<ll>> sum(2010,vector<ll>(2010,0));
    
    //基本的にはTLE解と同じ
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=sum[i-1][j-1]+1;
                dp[i][j]%=mod;
            }

            sum[i][j]=(sum[i][j]+sum[i-1][j]);
            if(sum[i][j]>=mod) sum[i][j]-=mod;
            sum[i][j]=(sum[i][j]+sum[i][j-1]);
            if(sum[i][j]>=mod) sum[i][j]-=mod;
            sum[i][j]=(sum[i][j]-sum[i-1][j-1]);
            if(sum[i][j]<0) sum[i][j]+=mod;
            sum[i][j]=(sum[i][j]+dp[i][j]);
            if(sum[i][j]>=mod) sum[i][j]-=mod;
        }
    }

    ll ans=1;
    rep(i,n+1){
        rep(j,m+1){
            ans+=dp[i][j];
            ans%=mod;
        }
    }

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

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

int main()
{
    long N, ap;
    int temp;
    string result = "YES";
    vector<long long> lst;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> ap;
        lst.push_back(ap);
    }

    sort(lst.begin(), lst.end());
    temp = lst.size();
    lst.erase(unique(lst.begin(), lst.end()), lst.end());

    if (temp != lst.size())
        result = "NO";

    cout << result << endl;
    return 0;
}


Measured memory_bytes: 2420
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long[10 ^^ 5] dp;
    dp[] = long.max;
    dp[0] = 0;
    long N, K;
    scan(N, K);
    auto h = aryread();
    foreach (i; 0 .. N)
    {
        foreach (j; 1 .. K + 1)
        {
            if (i + j < N)
            {
                dp[i + j].minAssign(dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }
    dp[N - 1].writeln();
}


Measured memory_bytes: 5020
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

bool isPrime(ll n){
    if(n == 1) return true;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(ll i = 3; i * i <= n; i+=2)
    {
        if(n % i == 0) return false;
    }
    return true;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    vl temp;
    vl memo;
    for(ll i = 1; i * i <= a; i++)
    {
        if(a % i == 0)
        {
            temp.push_back(i);
            if(a / i != i) temp.push_back(a / i);
        }
    }
    rep(i, temp.size()) {
        if(b % temp[i] == 0) memo.push_back(temp[i]);
    }
    sort(memo.begin(), memo.end());
    int count = 1;
    for(int i = 1; i < memo.size(); i++)
    {
        if(memo[i - 1] != memo[i] && isPrime(memo[i])) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

n = int(input()) 
list_music = [input().split() for i in range(n)]
x = input()

#-----
flag=""
sum=0
for L in list_music:
  if flag == "true":
    sum += int(L[1])
    
  if L[0] == x:
    flag="true"

print(sum)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string s;
    cin >> s;
    vector<int> ppair(s.size(),-1);
    stack<int> st;
    rep(i,s.size()){
        if(s[i]=='_') continue;
        else if(s[i]=='\\'){
            st.push(i);
        }else{
            if(st.empty()) continue;
            else{
                ppair[i] = st.top();
                ppair[st.top()] = i;
                st.pop();
            }
        }
    }

    vector<ll> area;
    ll now_area = 0;
    ll AREA = 0;
    int bound = -1;
    rep(i,s.size()){
        if(ppair[i] == -1) continue;
        if(bound == -1){
            bound = ppair[i];
            now_area = ppair[i] - i;
        }else if(i < bound){
            if(i < ppair[i]) now_area += ppair[i] - i;
        }else if(i == bound){
            if(i < ppair[i]) now_area += ppair[i] - i;
            area.push_back(now_area);
            AREA += now_area;
            now_area = 0;
            bound = -1;
        }
    }

    cout << AREA << endl;
    cout << area.size() ;
    rep(i,area.size()) cout << " " <<  area[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 3264
inp = list(map(int,input().split()))
N = inp[0]
A = inp[1]
B = inp[2]
l=list()
for i in range(N+1):
    n0 = i % 10
    n1 = (i % 100 - n0) // 10
    n2 = (i % 1000 - n0 - n1*10) // 100
    n3 = (i % 10000 - n0 - n1*10 - n2*100) // 1000
    n4 = (i % 100000 - n0 - n1*10 - n2*100 - n3*1000) // 10000
    if A <= n0+n1+n2+n3+n4 <= B:
        l.append(i)
print(sum(l))

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

int data[10];

int solve(int i, int a, int b){

  if(i == 10) return 1;

  int ans = 0;
  if(data[i] > a) ans += solve(i+1, data[i], b);
  if(data[i] > b) ans += solve(i+1, a, data[i]);

  return ans;
}

int main(){

  int n;

  cin >> n;
  while(n--){

    for(int i=0;i<10;i++) cin >> data[i];

    if(solve(0, 0, 0)) cout << "YES\n";
    else cout << "NO\n";

  }

}

Measured memory_bytes: 1120
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  ll res[100];
  res[0]=2LL;res[1]=1LL;
  rep(i,98)
  {
    res[i+2]=res[i+1]+res[i];
  }
  cout<<res[n]<<endl;

  return 0;

}


Measured memory_bytes: 256
N = int(input())
def check():
    for h in range(1,3500):
        for n in range(1,3500):
            div = 4 * n * h - N * h - N * n
            if div > 0 and N * h * n % div == 0:
                print(h, n, N * h * n // div)
                return 0
check()

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll> hash(110000);
  for(i=0;i<n;i++){
    cin>>buf;
    hash[buf]++;
  }
  for(i=1;i<=100000;i++){
    chmax(res1,hash[i-1]+hash[i]+hash[i+1]);
  }
  cout<<res1<<endl;



  return 0;
}

Measured memory_bytes: 1152
using System;
using System.Linq;

namespace EDPC
{
    class B
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int K = input[1];
            int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] DP = new int[N].Select(x => x = int.MaxValue).ToArray();

            DP[0] = 0;
            DP[1] = Math.Abs(h[1] - h[0]);

            for (int i = 2; i < N; i++)
            {
                for (int j = 1; j <= K; j++)
                {
                    if (j <= i) DP[i] = Math.Min(DP[i], DP[i - j] + Math.Abs(h[i] - h[i - j]));
                }
            }
            Console.WriteLine(DP[N - 1]);
        }
    }
}


Measured memory_bytes: 21600
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    int K, X;
    cin >> K >> X;
    cout << (K * 500 >= X ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
H,W,K = map(int,input().split())
S = [input() for i in range(H)]

imos = [[0]*(W+1) for i in range(H)]
for i,row in enumerate(S):
    for j,c in enumerate(row):
        imos[i][j+1] += int(c=='#')

for i in range(H):
    for j in range(W):
        imos[i][j+1] += imos[i][j]

ans = [[0]*W for i in range(H)]
k = 1
for i,row in enumerate(S):
    if imos[i][-1]==0: continue
    for j,c in enumerate(row):
        ans[i][j] = k
        if c=='#' and imos[i][j+1] < imos[i][-1]:
            k += 1
    k += 1

for i in range(H-1):
    if ans[i][0] and ans[i+1][0]==0:
        for j in range(W):
            ans[i+1][j] = ans[i][j]
for i in reversed(range(H-1)):
    if ans[i+1][0] and ans[i][0]==0:
        for j in range(W):
            ans[i][j] = ans[i+1][j]

for row in ans:
    print(*row)

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

bool judge(int N, vector<int> &A){

  bool even = false;

  for(int i = 0; i < N; i++){
    if(A.at(i) % 2 == 1 ){
      even = false;
      break;
    }
      even = true;
  }    
    
  return even;
}
  
 int main(){
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
   
  int count = 0;
   while(judge(N, A)){     
      for(int i = 0; i < N; i++){
        A.at(i) /= 2;
      }
     count++;
   }
   
   cout << count << endl;
 }
     
  
    
    
    
    
    
    
    
    
    
    

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    int n, y;
    cin >> n >> y;
    int s1 = 10000;
    int s2 = 5000;
    int s3 = 1000;

    rep(i, n + 1) rep(j, n + 1) {
        int k = n - (i + j);
        if (k < 0)
            continue;
        int s = i * s1 + j * s2 + k * s3;
        if (s == y) {
            cout << i << " " << j << " " << k;
            return 0;
        }
    }

    cout << -1 << " " << -1 << " " << -1;
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
i = 0
ans = []
#26^{i}がNを越えるまで以下の操作を繰り返す
while N != 0:
  s = N%26
  if s == 0:
    s = 26
  N -= s
  N //= 26
  ans.append(chr(s + 96))

print(''.join(list(reversed(ans))))

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n,a,b;
	cin>>a>>b>>n;
	vector<int> va,vb;
	for(int i=0;i<a;i++){
		int x;
		cin>>x;
		va.pb(x);
	}
	for(int i=0;i<b;i++){
		int x;
		cin>>x;
		vb.pb(x);
	}
	int ma=inf,mb=inf;
	for(int i=0;i<a;i++){ ma = min( ma, va[i] );}
	for(int i=0;i<b;i++){ mb = min( mb, vb[i] );}
	int ans = ma+mb;
	for(int i=0;i<n;i++){
		int x,y,c;
		cin>>x>>y>>c;
		ans = min( ans, va[x-1]+vb[y-1]-c );
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2548
import sys
import math
import numpy as np
import copy

def main():
    s = input()
    ret = True
    for i in range(len(s)):
        c = s[i]
        if i % 2 == 0 and c == 'L':
            ret = False
        if i % 2 == 1 and c == 'R':
            ret = False

    print("Yes" if ret else "No")
    return 0

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 12508