akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define YESNO(n) cout << ( (n) ? "Yes":"No") << endl;
using ll = long long;
using ull = unsigned long long;

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

    bool ans = true;
    bool down = false;
    int prev = 0;
    REP(i,n) {
        int x;
        cin >> x;
        if (x  == prev-1) {
            if (down) {
                ans = false;
            } else {
                down = true;
            }
        } else if (x < prev) {
            ans = false;

        } else if (x > prev) {
            down = false;
        }
        
        prev = x;
        
    }

    YESNO(ans)

    return 0;
}

Measured memory_bytes: 256
// Train Ticket
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

char ope(int x) {
    if (x == 1) return '+';
    else return '-';
}

int main() {
    int ABCD;
    int x[4] = {0};
    cin >> ABCD;
    for (int i = 0; ABCD > 0; i++) {
        x[4 - i - 1] = ABCD % 10;
        ABCD /= 10;
    }

    int su = 0;
    int bit_ope[3] = {0};
    for (int i = 0; i < 1 << 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (i & 1 << j) bit_ope[j] = 1;
            else bit_ope[j] = 0;
        }
        su = x[0];
        for (int j = 1; j < 4; j++) {
            if (bit_ope[j - 1] == 1) su += x[j];
            else su -= x[j];
        }
        if (su == 7) break;
    }
    cout << x[0] << ope(bit_ope[0]) << x[1] << ope(bit_ope[1]) << x[2] << ope(bit_ope[2]) << x[3] << "=7" << endl;
}

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

int main() {
    int A, B, K; cin >> A >> B >> K;

    int num = 0;
    for (int i = A; i > 0; i--) {
        if (A%i == 0 && B%i == 0) {
            num++;
            if (num == K) {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#C - Traveling Plan
N = int(input())
A = list(map(int, input().split()))
DP = []
ans = []
DP.append(abs(0-A[0]))
for i in range(1,N):
    DP.append(abs(A[i]-A[i-1]))

sum_DP = sum(DP)

for j in range(N):
    if j == 0:
        tmp = sum_DP-DP[0]-DP[1]+abs(A[1])+abs(A[N - 1])
    elif j == N-1:
        tmp = sum_DP-DP[N-1]+abs(A[N - 2])
    else:
        tmp = sum_DP + abs(A[N - 1])-DP[j]-DP[j+1]+abs(A[j+1]-A[j-1])
    ans.append(tmp)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 58604
#include <bits/stdc++.h>
#define le 10
#define ll long long int
using namespace std;
int n[le], m[le], nn[le], mm[le], sz;
bool fnc(){
  for(int i = 0; i < sz; i++){
    if(nn[i] != n[i]) return false;
  }
  return true;
}
bool fnc1(){
  for(int i = 0; i < sz; i++){
    if(mm[i] != m[i]) return false;
  }
  return true;
}
int main(){
  //freopen("input.txt", "r", stdin);
  int len;
  scanf("%d", &len);
  sz = len;
  for(int i = 0; i < len; scanf("%d", &n[i]), nn[i] = n[i], i++);
  for(int i = 0; i < len; scanf("%d", &m[i]), mm[i] = m[i], i++);
  sort(n, n + len);
  sort(m, m + len);
  ll a = 0, b = 0;
  do{
    a++;
    if(fnc()) break;
  }while(next_permutation(n, n + len));
  do{
    b++;
    if(fnc1()) break;
  }while(next_permutation(m, m + len));
  printf("%lld\n", abs(a - b));
  return 0;
}


Measured memory_bytes: 256
/*
ID: iCoder0020
PROG: Longest Path
LANG: C++                  
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define INF 1e9

template <typename T> void max_self(T &a, T b)
{
	a = max(a, b);
}

void dfs(int s, vector<vector<int>> &adj, vector<int> &in_deg, vector<int> &dp, vector<bool> &vis)
{
	vis[s] = true;
	for(auto v: adj[s])
	{
		max_self(dp[v], dp[s]+1);
		in_deg[v]--;
		if(in_deg[v] == 0 && !vis[v])
			dfs(v, adj, in_deg, dp, vis);
	}
}

int32_t main()
{
	int N,M;
	cin>>N>>M;
	vector<vector<int>> adj(N+1);
	vector<int> in_deg(N+1);
	for(int m = 0; m<M; m++)
	{
		int u, v;
		cin>>u>>v;
		adj[u].push_back(v);
		in_deg[v]++;
	}
	vector<int>dp(N+1, 0);
	vector<bool>vis(N+1, false);
	for(int n = 1; n<=N; n++)
		if(in_deg[n] == 0 && !vis[n])
			dfs(n, adj, in_deg, dp, vis);
	cout<<*max_element(dp.begin(), dp.end())<<endl;
	return 0;	
}

Measured memory_bytes: 16640
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int cntDiv(int n){
	int ans = 0;
	for (int i= 1;i*i<=n;i+=2){
		if(n%i==0){
			if(i*i==n)ans++;
			else ans +=2;
		}
	}
	return ans;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,ans=1;
	scanf("%d",&n);
	vector<int> a(n),b(n);
	REP(i,n){
		scanf("%d",&a[i]);
		b[i] = abs(i-(n-i-1));
	}

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if(a!=b){
		cout << 0 << endl;
		return 0;
	}
	REP(i,n/2){
		ans = ans*2%1000000007;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define mp make_pair
using namespace std;

using ll = long long;
using ii = pair<int, int>;
const int INF = (int)10e9;
int dp[3][100005];

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int N;
    cin>>N;
    vector<int> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) {
        cin>>a[i]>>b[i]>>c[i];
    }

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i < N; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][N-1], dp[1][N-1]), dp[2][N-1]) <<endl;

    return 0;
}

Measured memory_bytes: 5568
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <functional>
#include <cmath>
#include <cstring>
#include <numeric>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <complex>
#include <list>
#include <cassert>
#include <deque>

#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

/*
struct UnionFind {
    // union tree
    // used for tracking a set of elements partitioned into a number of disjoint subsets
    // rankなしでの実装

    vector<int> par;
    // par[i] means i's parent
    // (ex) par[3] = 2 means 2 is a parent of 3

    UnionFind(int N) : par(N) {
      //used for initialization
      for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
      // データxが属する木の根を再帰で得る
      // root(x) = {xの木の根}
      if (par[x] == x) return x;
      return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
      // xとyのtreeのmerge
      int rx = root(x); //xの根をrx
      int ry = root(y); //yの根をry
      if (rx == ry) return; //同じ時はそのままに
      par[rx] = ry; //xの根rxをyの根ryにつける
    }

    bool same(int x, int y) {
      // 2つのデータx, yが属する木が同じならtrueを返す
      int rx = root(x);
      int ry = root(y);
      return rx == ry;
    }
};

template<typename T>
struct SegTree {
  //segment tree

  //木は配列で表現
  vector<T> seg;
  //木の1/2の大きさ
  int size;
  //単位元
  const T unit;
  //比較関数の型
  using F = function<T(T,T)>;
  //mergeする関数
  const F f;

  //単位元がaで大きさnのsegtreeの初期化を行う
  //大きさnとはすなわち葉の数がnであることをいう
  SegTree(int n, const T a, const F f) : unit(a), f(f) {
    size = 1;
    while(size < n) size <<= 1;
    seg.assign(2*size, unit);
    size--;
  }

  //k番目にtを代入する
  void set(int k, const T& t) {
    seg[k + size] = t;
  }

  //関数fによって木を構築する
  void build(){
    for (int i = size - 1; i >=0; i--){
      seg[i] = f(seg[i*2+1],seg[i*2+2]);
    }
  }

  //i番目の要素を返す
  T operator[](const int i){
    return seg[i + size];
  }

  //k番目の値をaに更新する
  void update(int k, T a){
    k = k + size;
    //必要ならばここを変えても良い
    seg[k] = a;
    //自分の親の情報を再帰的に更新していく
    while(k>0){
      k = ((k-1) >> 1);
      seg[k] = f(seg[k*2+1],seg[k*2+2]);
    }
  }

  //[a,b)についてfをした結果を返す
  //例えば、fがminだったらどうなるかを考えるとわかりやすい
  //unitについては足し算なら0,掛け算なら1,minならinf,どんな値が来てもその値を返すもの
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) {
      return unit;
    } else if (a <= l && r <= b) {
      return seg[k];
    } else {
      T lch = query(a, b, k * 2 + 1, l, (l + r) / 2);
      T rch = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return f(lch, rch);
    }
  }
  T query(int a, int b) { return query(a, b, 0, 0, size+1); }
};
*/

/* --- ここからコード --- */

int main(){
  int N,R;
  cin >> N >> R;
  if(N>=10) cout << R << endl;
  else cout << R + 100 * (10 - N) << endl;
  return 0;
}

Measured memory_bytes: 256
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
div = make_divisors(n)
ans = 0
for i in range(len(div)): #約数列挙
    m = (n//div[i])-1
    if m != 0 and n%m == n//m:
        ans += m
print(ans)

Measured memory_bytes: 3288
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    n=length(s)
    ans=0
    res=0
    for i in 1:n
        if s[i] in ['A','C','G','T']
            res+=1
        else
            ans=max(ans,res)
            res=0
        end
    end
    ans=max(ans,res)
    println(ans)
end
main()

Measured memory_bytes: 167588
#include <bits/stdc++.h>
#define N 1100
#define M 21000
using namespace std;
int H,f[M],i,j,n,a[N],b[N],p,m,ans;
int main()
{
	scanf("%d%d",&H,&n);
	for (i=1;i<=n;i++)
	{
	scanf("%d%d",&a[i],&b[i]);
	p=max(a[i],p);
    }
	m=H+p;
	memset(f,0x7f/3,sizeof f);
	f[0]=0;
	for (i=1;i<=n;i++)
	 for (j=a[i];j<=m;j++) 
	  f[j]=min(f[j],f[j-a[i]]+b[i]);
	ans=f[H];
	for (i=H+1;i<=m;i++)
	 ans=min(ans,f[i]);
	printf("%d",ans);
}

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


int N;
long A[300][300];
long d[300][300];


int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> A[i][j];
            d[i][j] = A[i][j];
        }
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                if(A[i][j] > A[i][k] + A[k][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if((i != k && j != k) && A[i][j] == A[i][k] + A[k][j]) {
                    d[i][j] = 0;
                }
            }
        }
    }

    long sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i; j < N; j++) {
            sum += d[i][j];
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdlib>
#include <string>

int main()
{
    int a, b, c, x;
    std::cin >> a >> b >> c >> x;  
    int count = 0;
    for(int i = 0;i <= a;i++) {
        for(int j = 0;j <= b;j++) {
            for(int k = 0;k <= c;k++) {
                if(i * 500 + j * 100 + k * 50 == x) {
                    count++;
                }
            }
        }
    }
    
    std::cout << count << std::endl;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  int N; cin >> N;
  ll M = -1, m = 1010;
  rep(i, N){
    int a; cin >> a;
    M = max(a, M), m = min(a, m);
  }
  cout << M - m << endl;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int k, int[] a) {
    long ans = long.max;
    for (int i = 0; i < a.length; i++) {
        if (i + k - 1 >= a.length) break;

        int lo = i;
        int hi = i + k - 1;

        // 0 -> lo -> hi の順に火をつける
        ans = min(ans, abs(a[lo]) + abs(a[hi] - a[lo]));

        // 0 -> hi -> lo の順に火をつける
        ans = min(ans, abs(a[hi]) + abs(a[hi] - a[lo]));
    }
    return ans;
}

void main() {
    auto nk = readints;
    int k = nk[1];
    auto a = readints;
    writeln(calc(k, a));

    /*
    int n = nk[0], k = nk[1];
    auto xs = readints;

    int[] pos, neg;
    foreach (x; xs) {
        if (x >= 0) pos ~= x;
        else neg ~= x;
    }
    neg.reverse();

    long ans = long.max;
    for (int i = 0; i < pos.length; i++) {
        long p = pos[i];

        int rest = k - i - 1;
        if (rest == 0) ans = min(ans, pos[i]);
        if (rest < 0) break;
        if (0 < rest && rest <= neg.length) {
            ans = min(ans, 2 * pos[i] + neg[rest-1] * -1);
        }
    }

    for (int i = 0; i < neg.length; i++) {
        int rest = k - i - 1;
        if (rest == 0) ans = min(ans, -neg[i]);
        if (rest < 0) break;
        if (0 < rest && rest <= pos.length) {
            ans = min(ans, 2 * -neg[i] + pos[rest-1]);
        }
    }

    writeln(ans);
    */
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    REP(i, n) cin >> vec[i];
    sort(vec.begin(), vec.end());
    int ans = 0;

    REP(i, n) REPN(j, i+1, n) {
        /* 最後の一個の範囲は */
        /* vec[j] < c < vec[i] + vec[j] */
        int max = vec[i] + vec[j];

        auto max_index = lower_bound(vec.begin(), vec.end(), max);

        ans += (max_index - vec.begin()) - 1 - j;
    }    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include "vector"
using namespace std;

typedef long long ll;
int main(){
  string s, t;
  cin >> s >> t;
  int answer = int(1e9);
  for(int i = 0; i - 1 + t.size() < s.size(); i++)
  {
      int cans = 0;
      for(int j = 0; j < t.size(); j++) {
          if(s[i + j] != t[j])
              cans ++;
      } answer = min(cans, answer);
  } cout << answer;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);

    bool ok = false;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 1) ok = true;
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }

    int x = 1;
    int ans = 0;
    rep(i, n) {
        if (a[i] == x) x++;
        else ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
map<int,int>ma;
int a[100010]={0};
int main()
{
    int n;
    int num=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        num^=a[i];
    }
    if(num==0){
        printf("Yes\n");
    }
    else
        printf("No\n");
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
 
    vvl dp(n+1, vl(m+1));  // dp[i+1][j+1] : sのi文字目までとtのj文字目までのLCSの長さ 
    rep(i, n) {
        rep(j, m) {
            if(s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    string ans = "";
    ll i = n-1;
    ll j = m-1;
    while(i >= 0 && j >= 0) {
        if(dp[i+1][j+1] == dp[i][j+1]) {
            i--;
        }
        else if(dp[i+1][j+1] == dp[i+1][j]) {
             j--;
        }
        else {
            ans = s[i] + ans;
            i--;  j--;
        }
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 70912
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0

    for i in range(N-1):
        dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1]-H[i]))
        if i != N-2:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2]-H[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 52028
n = int(input())
x, y = [], []
for i in range(n):
    s = int(input())
    if s % 10 == 0:
        x.append(s)
    else:
        y.append(s)
y = sorted(y)
if len(y) == 0:
    print(0)
elif sum(y) % 10 == 0:
    print(sum(x) + sum(y[1:len(y)]))
else:
    print(sum(x) + sum(y))


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

bool is_prime(ll v)
{
	if(v<2) return false;
	if(v%2==0)
	{
		return (v==2);
	}

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

using pf=vector<pair<ll,int> >;
pf prime_factorization(ll v)
{
	pf p;

	for(ll i=2;i*i<=v;i++)
	{
		if(v%i==0)
		{
			p.push_back(make_pair(i, 1));
			for(v/=i;v%i==0;v/=i)
			{
				p.back().second++;
			}
		}
	}
	if(v>1) p.push_back(make_pair(v, 1));

	return p;
}


int calc_divisor(vll&ret, ll v)
{
	auto p=prime_factorization(v);

	ret.clear();
	ret.push_back(1);
	for(auto&mp:p)
	{
		int n=ret.size();
		for(int i=0;i<n;i++)
		{
			ll t=ret[i];
			for(int j=mp.second;j>0;j--)
			{
				ret.push_back(t*=mp.first);
			}
		}
	}
	sort(ret.begin(), ret.end());

	return ret.size();
}




int main(void)
{
	ll n;
	while(scanf("%lld", &n)==1)
	{
		pf p=prime_factorization(n);

		int ans=0;
		for(auto m:p)
		{
			for(int i=1;m.second>0;i++)
			{
				if(m.second>=i) ans++;
				m.second-=i;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3228
<?php
$num = trim(fgets(STDIN));
$input=explode(' ',trim(fgets(STDIN))); // // 1 2 3 ……
//print_r($input);

//Yがある→4、ない→3
foreach ($input as $letter) {
    if ($letter==="Y") {
        echo("Four");
        exit();
    }
}

    echo("Three");
?>


Measured memory_bytes: 3828
n = int(input())

ab = []

for _ in range(n):

	ab.append(list(map(int, input().split())))
	

ab.sort(key = lambda x: x[1])

# print(ab)


limit = 0

work = 0

fail = 0


for i in range(n):

	limit = ab[i][1]

	work += ab[i][0]

	if work > limit:

		fail = 1

		break


if fail == 1:

	print("No")

else:

	print("Yes")

Measured memory_bytes: 53720
#include <bits/stdc++.h>
using namespace std;
     
int main() {
	
	int a,b,c;
	
	cin >> a >> b;
	
	if((a+b)%2==0){
		c=(a+b)/2;
	}
	else{
		c=(a+b+1)/2;
	}
		
	
	cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#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 max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll calc(int n, int m) {
    ll ret = 0;
    rep3(i, 1, m) {
        ll tmp = (ll)i * (m - i) % inf; // 1次元
        
        // 2次元
        (tmp *= n) %= inf;
        (tmp *= n) %= inf; // * n^2を分割
        (ret += tmp) %= inf;
    }
    return ret;
}

int main() {
    
    int n, m, k;
    cin >> n >> m >> k;
    
    ll ans = calc(n, m); // x
    (ans += calc(m, n)) %= inf; // y
    
    
    
    
    COMinit();
    (ans *= COM(n * m - 2, k - 2)) %= inf;
    
    
    out(ans);
}


Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

using int64 = long long;

const int64 INF = (1LL<<60);

int64 N, E, T;

vector<int64> pref;
vector<int64> dp;
vector<int64> x;

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

    pref.resize(N + 1);
    x.resize(N + 1);

    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    x[N] = E;

    for (int i = N - 1; i >= 0; i--) {
        pref[i] = pref[i + 1] + (x[i + 1] - x[i]);
    }

    dp.resize(N + 1);

    int j = N;

    int64 suf_min = INF;

    set<pair<int64, int64>> heap;

    heap.insert(make_pair(dp[N] + T, N));

    for (int i = N - 1; i >= 0; i--) {
        // Query max T
        // Query max distance
        // Update

        dp[i] = (1LL<<60);

        while (j > i && 2 * (pref[i] - pref[j-1]) > T) {
            suf_min = min(suf_min, - 2 * pref[j - 1] - pref[j] + dp[j]);
            j--;
        }

        dp[i] = min(dp[i], 3 * pref[i] + suf_min);

        while(!heap.empty()) {
            auto el = *heap.begin();
            if (2 * (pref[i] - pref[el.second - 1]) > T) {
                heap.erase(heap.begin());
            } else {
                dp[i] = min(dp[i], pref[i] + el.first);
                break;
            }
        }        

        heap.insert(make_pair(-pref[i] + dp[i] + T, i));

        // int64 d = pref[i] - pref[j-1];
        // int64 l = pref[i] - pref[j];

        // if (2 * d <= T) {
        //     dp[i] = min(dp[i], T + l + dp[j]);
        // } else {
        //     dp[i] = min(dp[i], 2 * d + l + dp[j]);
        // }

        //}
    }

    cout << dp[0] + x[0] << "\n";

    return 0;
}

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

int main() {
    int a, b;

    cin >> a >> b;
    int x = 2 * a - b / 2;
    int y = -a + b / 2;

    if (x>=0 && y>= 0 && x+y==a && 2*x+4*y==b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
const long long INF = 1e18;
const int mod = 1e9 + 7;//1e9 + 7;//786433;//998244353;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
int psum[100005], psum2[100005];
string a, b;

signed main()
{
	Fastio();
	cin >> a >> b;
	for(int i = 0; i < (int)a.length(); i++)
	{
		psum[i + 1] = psum[i] + (a[i] == 'A');	
	}
	for(int i = 0; i < (int)b.length(); i++)
	{
		psum2[i + 1] = psum2[i] + (b[i] == 'A');
	}
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int l, r, l2, r2;
		cin >> l >> r >> l2 >> r2;
		int temp = psum[r] - psum[l - 1], temp2 = psum2[r2] - psum2[l2 - 1];
		if((temp + 2 * (r - l + 1 - temp) - temp2 - 2 * (r2 - l2 + 1 - temp2)) % 3 == 0)
		{
			cout << "YES\n";
		}
		else
		{
			cout << "NO\n";
		}
	}
}

Measured memory_bytes: 4532
n=int(input())

li={}
an=[]
ma=0

for i in range(n):
    t=input()
    if t in li:
        li[t]+=1
    else:
        li[t]=1

li2=sorted(li.items(), key=lambda x:x[1],reverse=True)

ma=li2[0][1]

for j in range(n):
    if li2[j][1]==ma:
        an.append(li2[j][0])
        
        if len(li2)==j+1:
            break
    else:
        break

an.sort()
 
for k in range(len(an)):
    print(an[k])

Measured memory_bytes: 45780
#include<iostream>
 #include<vector>
 #include<string>
 #include<algorithm>
 #include<map>
 #include<cmath>
 #include<queue>
 #include<stack>
 #include<list>
 
 #define endl "\n"
 using namespace std;
 using ll = long long;
 const ll MOD = 1e9+7;
 const ll INF = 1e18;
 #define REP(i, n) for(int i = 0; i < n; i++)
 using Graph = vector<vector<int>>;
 
 int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<pair<bool,ll>> use(100010);
    ll sum = 0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
        use[a[i]].first = true;
        use[a[i]].second++;
    }
    ll q;
    cin>>q;
    vector<ll> b(q),c(q);
    vector<ll> ans;
    for(ll i=0;i<q;i++){
        cin>>b[i]>>c[i];
        if(use[b[i]].first){
            sum += c[i] * use[b[i]].second;
            sum -= b[i] * use[b[i]].second;
            use[c[i]].first = true;
            use[c[i]].second += use[b[i]].second;
            use[b[i]].second = 0;
            use[b[i]].first = false;
        }
        ans.push_back(sum);
    }

    for(ll i=0;i<q;i++){
        cout<<ans[i]<<endl;
    }
 }

Measured memory_bytes: 8232
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll N, M;
    cin >> N >> M;
    vector<vl> adj(N);
    FOR(i, 0, M) {
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        adj[u].push_back(v);
    }
    ll S, T;
    cin >> S >> T;
    S--;
    T--;
    ll bfs[N][3];
    FOR(i, 0, N) {
        FOR(j, 0, 3) {
            bfs[i][j] = -1;
        }
    }
    bfs[S][0] = 0;
    queue<pair<int, int>> que;
    que.push(make_pair(S, 0));
    while (que.size()) {
        ll f = que.front().first;
        ll s = que.front().second;
        que.pop();
        for (auto to : adj[f]) {
            if (bfs[to][(s + 1) % 3] == -1) {
                bfs[to][(s + 1) % 3] = bfs[f][s] + 1;
                que.push(make_pair(to, (s + 1) % 3));
            }
        }
    }
    cout << (bfs[T][0] != -1 ? bfs[T][0] / 3 : -1) << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	char c;
	cin>>c;

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

	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
struct P{
	ll s,e;
	bool operator<(P a){
		return e<a.e;
	}
}p[N];


int main(){
	int n;
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,l;
		cin>>x>>l;
		p[i].s=x-l;p[i].e=x+l;
	}
	sort(p+1,p+1+n);
	int ans=1,end=p[1].e;
	for(int i=2;i<=n;i++){
		if(p[i].s>=end){//=
			ans++;
			end=p[i].e;
		}
	}
	cout<<ans;
	return 0;
	
}

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

struct StarrySkyTree {
    int sz;
    vector<int> sum, mn;
    StarrySkyTree(int n) {
        for(sz = 1; sz < n;)
            sz <<= 1;
        sum.assign(sz << 1, 0);
        mn.assign(sz << 1, 0);
    }

    void add(int a, int b, int x) {
        a += sz;
        b += sz - 1;
        for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if(l & 1) sum[l++] += x;
            if(r & 1) sum[--r] += x;
        }
        while(a >>= 1)
            mn[a] =
                min(mn[a << 1] + sum[a << 1], mn[a << 1 | 1] + sum[a << 1 | 1]);
        while(b >>= 1)
            mn[b] =
                min(mn[b << 1] + sum[b << 1], mn[b << 1 | 1] + sum[b << 1 | 1]);
    }

    // [a, b) の最大値を取得
    int getmin(int a, int b, int k, int l, int r) {
        if(b <= l || r <= a) return INT_MAX;
        if(a <= l && r <= b) return mn[k] + sum[k];
        int mid = (l + r) >> 1;
        int vl = getmin(a, b, k << 1, l, mid);
        int vr = getmin(a, b, k << 1 | 1, mid, r);
        return min(vl, vr) + sum[k];
    }
    int getmin(int a, int b) { return getmin(a, b, 1, 0, sz); }
};

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

    int N, Q;
    cin >> N >> Q;

    StarrySkyTree seg(N);

    int a, b, c, d;
    while(Q--) {
        cin >> a;
        if(a) {
            cin >> b >> c;
            cout << seg.getmin(b, c + 1) << "\n";
        } else {
            cin >> b >> c >> d;
            seg.add(b, c + 1, d);
        }
    }
}



Measured memory_bytes: 4964
#include<stdio.h>
typedef long long ll;
ll abs(ll x){return x>0?x:-x;}
const int go[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int x[1010],y[1010],c[2],m;
char s[40];
void work(ll x,ll y){
	int i,j;
	ll tx,ty;
	for(i=m-1;i>=0;i--){
		for(j=0;j<4;j++){
			tx=x+go[j][0]*(1<<i);
			ty=y+go[j][1]*(1<<i);
			if(abs(tx)+abs(ty)<=(1<<i)-1){
				s[i]="DULR"[j];
				x=tx;
				y=ty;
				break;
			}
		}
	}
	printf("%s",s);
}
int main(){
	int n,i,ad;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d%d",x+i,y+i);
		c[(x[i]^y[i])&1]++;
	}
	if(c[0]&&c[1]){
		puts("-1");
		return 0;
	}
	ad=0;
	if(c[0]){
		for(i=1;i<=n;i++)x[i]++;
		ad=1;
	}
	m=31;
	printf("%d\n",m+ad);
	for(i=1;i<=m;i++)printf("%d ",1<<(i-1));
	if(ad)putchar('1');
	putchar('\n');
	for(i=1;i<=n;i++){
		work(x[i],y[i]);
		if(ad)putchar('L');
		putchar('\n');
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(5);
    rep(i,5) cin>>a[i];
    vint res(5,0);
    rep(i,5){
        res[i]=(ll)ceil((ld)n/a[i]);
    }
    
    cout<<MAX(res)+4<<endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <algorithm>
#define R register
using namespace std;
const int mod=1000000007;
const int MAXN=410;
int a[MAXN],b[MAXN],po[MAXN][MAXN];
int dp[MAXN][MAXN];

int add(int x,int y)
{return (x+y)%mod;}
int sub(int x,int y)
{return (x-y+mod)%mod;}
int mul(int x,int y)
{return 1LL*x*y%mod;}

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(R int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(R int i=1;i<=n;++i)scanf("%d",&b[i]);
	for(R int i=1;i<=400;++i)
	{
		int t=1;
		po[i][0]=i;
		for(R int j=1;j<=m;++j)
		{
			t=mul(t,i);
			po[i][j]=add(po[i-1][j],t);
		}
	}
	dp[0][0]=1;
	for(R int i=1;i<=n;++i)
	  for(R int j=0;j<=m;++j)
		for(R int k=0;k<=m;++k)
		{
			if(j+k>m)break;
			dp[i][k+j]=add(dp[i][k+j],mul(dp[i-1][k],sub(po[b[i]][j],po[a[i]-1][j])));
		}
	printf("%d\n",dp[n][m]);
	return 0;
}

Measured memory_bytes: 1408
loop do
  h = gets.chomp.to_i

  if h == 0
    break
  end
  
  cells = Array.new(h)

  h.times do |i|
    cells[i] = gets.chomp.split(" ").map(&:to_i)
  end

  ans = 0
  loop do
    flg = false

    for i in 0...h
      for j in 0...5
        if cells[i][j] == -1
          next
        end
        cnt = 0
        for k in j...5
          if cells[i][j] != cells[i][k]
            break
          end
          cnt += 1
        end
        if cnt < 3
          next
        end
        ans += cells[i][j] * cnt
        for k in 0...cnt
          cells[i][j + k] = -1
        end
        flg = true
      end
    end
    
    if !flg
      break
    end

    for j in 0...5
      for i in 0...h
        idx = h - i - 1
        if cells[idx][j] == -1
          next
        end
        while idx + 1 < h && cells[idx + 1][j] == -1 do
          cells[idx][j], cells[idx + 1][j] = cells[idx + 1][j], cells[idx][j]
          idx += 1
        end
      end
    end
  end

  puts ans
end
  

Measured memory_bytes: 6136
#include <bits/stdc++.h>
// aya_seは起床のプロ
using namespace std;

//@ebi's definition

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;

struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<ll>>;

// xxpoxx's definition
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L << 60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/

// aya_se's definition
vl fac, finv, inv;
void COMinit(ll N)
{
    fac.resize(N);
    finv.resize(N);
    inv.resize(N);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < N; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

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()
{
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string t, p;
    cin >> t >> p;
    ll pite = 0;
    string now = "";
    REP(i, t.size())
    {
        if (t.substr(i, 1) == now && p.substr(pite, 1) != t.substr(i, 1))
        {
            cout << "no" << endl;
            return 0;
        }
        if (p.substr(pite, 1) != t.substr(i, 1))
        {
            continue;
        }
        now = t.substr(i, 1);
        pite++;
    }
    if (pite == p.size())
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}



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

int main() {
  string T;
  cin >> T;
  for(int i = 0; i < T.size();i++){
    if(T.at(i) == '?'){
      T.at(i) = 'D';
    }
  }
  cout << T;
}

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dx[]={1, -1, 0, 0, 0};
int dy[]={0, 0, 1, -1, 0};

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int a, b;
    cin >> a >> b;

    int high = 0;
    for(int i = 1; i <= 999; ++i){
        high += i;
        if(i == b - a){
            high -= b;
            break;
        }
    }

    cout << high << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        var s = Console.ReadLine();
        var t = "CODEFESTIVAL2016";
        var count = 0;
        for(var i = 0;i < s.Length;i++){
            if(s[i] != t[i]){
                count++;
            }
        }
        
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

const ll p = 998244353LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n,k;
	cin>>n>>k;

	vector<pair<int,int>> V;

	for(int i=0; i<k; i++)
	{
		int l,r;
		cin>>l>>r;
		V.push_back({l,r});
	}

	vector<ll> dp(n+1);
	dp[1]=1LL;

	for(int i=2; i<=n; i++)
	{
		for(auto v:V)
		{
			if(i-v.ff < 0) continue;

			int curl = v.ff;
			int curr = v.ss;

			if(i-v.ss < 0) curr = i;
		
			dp[i] += dp[i - curl];
			dp[i] %= p;
			if(i - curr - 1 >= 0) dp[i] += p - dp[i - curr - 1];
			dp[i] %= p;

			// cout << i - curl << " " << i - curr - 1 << endl;
		}

		// cout << i << " " << dp[i] << " watcha got" << endl;
		dp[i] += dp[i-1];
		dp[i] %= p;
	}

	ll ans = dp[n];
	ans += p - dp[n-1];
	ans %= p;

	cout << ans << endl;
}

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

int main()
{
	long long int n;
	cin>>n;
	long long int w[n+1],c[n+1];
	long long int i,j,k,l,m;
	cin>>m;
	for(i=1;i<=n;i++)
	{
		cin>>w[i]>>c[i];
	}
	long long int dp[n+1][m+3];
	
	for(i=0;i<=n;i++)
	{   
	for(j=0;j<=m;j++)
		dp[i][j]=0;
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(j-w[i]>=0)
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+c[i]);
			}
			else dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][m];
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
const int N = 312;
int n,a[100001],h,w,ans[N][N];
int main()
{
	cin>>h>>w>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	int tmp=1;
	for(int i=1;i<=h;++i)
	for(int t=1;t<=w;++t)
	{
		a[tmp]--;
		ans[i][t]=tmp;
		if(a[tmp]==0)tmp++;
	}
	for(int i=1;i<=h;++i)
	{
		if(i%2)
		for(int t=1;t<=w;++t)
		cout<<ans[i][t]<<" ";
		else
		for(int t=w;t>=1;--t)
		cout<<ans[i][t]<<" ";
		
		cout<<endl;
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,k;
  cin >> n >> k;
  vl a(n);
  vl cnt(n+1);
  rep(i,n){
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(cnt.begin(),cnt.end());
  ll ans=0;
  rep(i,k){
    ans+=cnt[n-i];
  }
  cout << n-ans << endl;
}

Measured memory_bytes: 3328