akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,string> pis;
 
bool cmp(pis x, pis y){
  return x.first < y.first;
}
 
int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N, m;
  cin >> N >> m;
    
  int p;
  string S;
  vector<pis> data(m);
  //map<int,string> data;
  for(int i=0;i<m;++i) {
      cin >> p >> S;
      data[i] = make_pair(p, S);
      
     // data[i].insert(pair<int, string>(p,S));
   }
  // for (int i = 0; i < m; ++i)
  // {
  //   cout<<data[i].first<<" "<<data[i].second<<endl;
  // }
  // cout<<endl;
  stable_sort(data.begin(), data.end(),cmp);
  // for (int i = 0; i < m; ++i)
  // {
  //   cout<<data[i].first<<" "<<data[i].second<<endl;
  // }
  // cout<<endl;

  // for (auto it=mymap.begin(); it!=mymap.end(); ++it)
  //   std::cout << it->first << " => " << it->second << '\n';

  ll temp = 0;
  ll penalty = 0;
  ll ans = 0;
  int flag = 0;   
  for(int i=0;i<m;i++){
    if(data[i].first > N)
  	        continue;
    if(i != 0 && data[i-1].first != data[i].first) {
          flag = 0;
          temp = 0;
          //cout<<"TESTING"<<endl;
      }
      if(flag == 0 && data[i].second != "AC"){
          temp++;
          //cout<<temp<<endl;
      }
      else if(flag == 0 && data[i].second == "AC") {
          flag = 1;
          penalty += temp;
          ans++;
      }
      //cout<<temp<<endl;
      // if(temp!=0 && penalty==0)
      //   penalty+=temp;
  }
  
  cout << ans << " " << penalty << endl;
  return 0;
}
 

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int a;
  scanf("%d", &a);
  printf("%d\n", a + a * a + a * a * a);

  return 0;
}

Measured memory_bytes: 3832
#include<cstdio>

int main(){
	int h,w;
	scanf("%d %d", &h, &w);
	while(h && h){
		for(int i = 0; i < h ; i++){
			for(int j = 0; j < w; j++){
				if(i * j && ((i - h + 1) * (j - w + 1)))
				{
					printf(".");
				}else{
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s=Console.ReadLine().Split(' ');
            var x = int.Parse(s[0]);
            var y = int.Parse(s[1]);
            var a = int.Parse(s[2]);
            var b = int.Parse(s[3]);
            var c = int.Parse(s[4]);

            var p = new int[a];
            s = Console.ReadLine().Split(' ');
            for(int i = 0; i < a; i++)
            {
                p[i] = int.Parse(s[i]);
            }

            var q = new int[b];
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < b; i++)
            {
                q[i] = int.Parse(s[i]);
            }

            var r = new int[c];
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < c; i++)
            {
                r[i] = int.Parse(s[i]);
            }

            p = p.OrderByDescending(e => e).ToArray();
            q = q.OrderByDescending(e => e).ToArray();
            r = r.OrderByDescending(e => e).ToArray();

            var z = x + y;

            var pn = 0;
            var qn = 0;
            var rn = 0;

            long ans = 0;

            for(int i = 0; i < z; i++) { 
                int pg = pn < x? p[pn] : 0;
                int qg = qn < y? q[qn] : 0;
                int rg = rn < c? r[rn] : 0;
                if( pg >= qg &&  pg >= rg)
                {
                    ans += pg;
                    pn++;
                }
                else if(qg >= rg)
                {
                    ans += qg;
                    qn++;
                }
                else
                {
                    ans += rg;
                    rn++;
                }
            }

            Console.WriteLine(ans);

        }
    }
}


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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>

#include <queue>
#include <map>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;
const int INF = 1 << 30;
int main()
{
   
    int n, m;
    cin >> n;
    cin >> m;

    string s;
    cin >> s;

    vector<int> dp(n + 1, INF);
    dp[n] = 0;
    queue<int> q;
    q.push(0);

    for (int i = n - 1; i >= 0; --i)
    {
        while (1)
        {
            if (q.size() == 0)
            {
                puts("-1");
                return 0;
            }

            if (q.front() != INF && q.size() <= m)
                break;
            q.pop();
        }
        if (s[i] == '0')
            dp[i] = q.front() + 1;
        q.push(dp[i]);
    }
    vector<int> ans;
    int x = 0;
    int rest = dp[0];
    while (x < n)
    {
        --rest;
        int i = 1;
        while (dp[x + i] != rest)
            ++i;
        ans.push_back(i);
        x += i;
    }

    REP(i, ans.size())
    {
        printf("%d%c", ans[i], i == int(ans.size()) - 1 ? '\n' : ' ');
    }
    return 0;
}

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

constexpr int MAX_N = 10;
constexpr int MAX_D = 10;

int X[MAX_N][MAX_D];

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

  for (int i{}; i < N; ++i) {
    for (int j{}; j < D; ++j) {
      cin >> X[i][j];
    }
  }

  int ans{};
  for (int i{}; i < N-1; ++i) {
    for (int j{i+1}; j < N; ++j) {
      double sum{};
      for (int k{}; k < D; ++k) {
        sum += pow(X[i][k] - X[j][k], 2);
      }
      sum = sqrt(sum);
      if (sum == static_cast<int>(sum))
        ++ans;
    }
  }

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


Measured memory_bytes: 256
import java.util.*;
 
public class Main { 
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long twoCount = 0;
		long fiveCount = 0;
		long tmp = n;
		if(n%2 == 1){
			System.out.println(0);
			return;
		}
		while(tmp > 0){
			twoCount += tmp/2;
			tmp = tmp/2;
		}
		tmp = n;
		fiveCount += tmp/(5*2);
		tmp = tmp/(5*2);
		while(tmp > 0){
			fiveCount += tmp/5;
			tmp = tmp/5;
		}
		System.out.println(Math.min(twoCount, fiveCount));
	}
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))
b = list( map(int, input().split()))
d = [0]*n

for i in range(n):
    d[i] = a[i]-b[i]

d.sort()

if sum(d)<0:
    print(-1)
    exit()

cnt_neg = 0
for i in range(n):
    if d[i]<0:cnt_neg+=1

if cnt_neg==0:
    print(0)
    exit()
else:
    ans = cnt_neg

last=n-1
for neg in range(n):
    if d[neg]>=0:break

    while d[neg]<0:
        tmp = min(-d[neg], d[last])
        d[neg] += tmp
        d[last] -= tmp
        if d[last] == 0:
            last-=1
            ans+=1

if d[last] != a[last]-b[last] and d[last]!=0 : ans+=1

print(ans)


Measured memory_bytes: 18356
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8,i8[:],i8[:])", cache=True)
def binary_search(K, A, F):
    """Meguru type binary search"""
    ng = -1
    ok = 10 ** 12

    def is_ok(A, F, K, x):
        count = 0
        for a, f in zip(A, F):
            count += max(0, a - x // f)
        return count <= K

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(A, F, K, mid):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)

    A.sort()
    F[::-1].sort()

    ans = binary_search(K, A, F)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 131472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
  ll N, M, K; cin >> N >> M >> K;
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);
  vector<int> B(M);
  rep(i, M) cin >> B.at(i);

  ll t = 0;
  ll sum = 0;
  while(sum < N){
    if(t+A.at(sum)<=K){
      t += A.at(sum);
      sum++;
    }
    else break;
  }
  ll sum2 = 0;
  while(sum2 < M){
    if(t+B.at(sum2)<=K){
      t += B.at(sum2);
      sum2++;
    }
    else break;
  }

  ll ans = sum + sum2;
  while(sum>0){
    sum--;
    t -= A.at(sum);
    while(sum2 < M){
      if(t+B.at(sum2)<=K){
        t += B.at(sum2);
        sum2++;
      }
      else break;
    }
    ans = max(ans, sum + sum2);
  }
  cout << ans << endl;
}

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

int main() {
  int a,b,c,ans;
  cin >> a >> b >> c;
  vector<int> num(3);
   num[0] =a;
   num[1] =b;
   num[2] =c;

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

  ans = num[2] - num[0];

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
 
ll n,a,b,c,d;
map<ll,ll> m;

ll solve(ll n)
{
    if(m[n]!=0 || n==0)
        return m[n];
    ll ans=C;
    if(d<C/n)
        ans=n*d;
    ll x,y;
    x=2*((n+1ll)/2);
    y=2*(n/2);
    ans=min(ans,solve(x/2)+a-(d*(n-(x))));
    ans=min(ans,solve(y/2)+a-(d*((y)-n)));
    x=3*((n+2ll)/3);
    y=3*(n/3);
    ans=min(ans,solve(x/3)+b-(d*(n-(x))));
    ans=min(ans,solve(y/3)+b-(d*((y)-n)));
    x=5*((n+4ll)/5);
    y=5*(n/5);
    ans=min(ans,solve(x/5)+c-(d*(n-(x))));
    ans=min(ans,solve(y/5)+c-(d*((y)-n)));
    m[n]=ans;
    return ans;
}

int main() 
{
    FAST;
    ll t;
    cin>>t;
    while(t-->0)
    {
        m.clear();
        cin>>n>>a>>b>>c>>d;
        m[1]=d;
        cout<<solve(n)<<'\n';
    }
    subt;
    return 0;
}

Measured memory_bytes: 4640
import java.util.Scanner;

public class Main implements Runnable {

	public static void main(String[] args) {
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[A];
		int[] b = new int[B];
		int minA = Integer.MAX_VALUE;
		for(int i = 0; i < A; i++) {
			a[i] = sc.nextInt();
			if(minA > a[i]) minA = a[i];
		}
		int minB = Integer.MAX_VALUE;
		for(int i = 0; i < B; i++) {
			b[i] = sc.nextInt();
			if(minB > b[i]) minB = b[i];
		}
		int min = minA + minB;
		for(int i = 0; i < M; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int c = sc.nextInt();
			int m = a[x - 1] + b[y - 1] - c;
			if(min > m) min = m;
		}
		sc.close();
		System.out.println(min);
	}
}

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

using namespace std;

const int Nmax = 2e5 + 5;
const int Mod = 1e9 + 7;
const int oo = 2e9;

int a, b, c, d;

int main()
{
/**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/

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

    int ok = 0, turn = 1;
    while(!ok)
    {
        if(turn == 1)
        {
            c -= b;
            turn = 2;

            if(c <= 0) ok = 1;
        }
        else
        {
            a -= d;
            turn = 1;

            if(a <= 0) ok = 2;
        }
    }

    cout << (ok == 1 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

class UnionFind {
    int cnt;
    vector<int> par, rank, size;
public:
    UnionFind() {}
    UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) {
        for (int i = 0; i<_n; ++i) par[i] = i;
    }
    int find(int k) {
        return (k == par[k]) ? k : (par[k] = find(par[k]));
    }
    int operator[](int k) {
        return find(k);
    }
    int getSize(int k) {
        return size[find(k)];
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        --cnt;
        if (rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if (rank[y] == rank[x]) ++rank[x];
        }
    }
    int count() {
        return cnt;
    }
};

void solve() {
    const int MA = (int)1e5 + 1;
    int N;
    cin >> N;
    vi X(N), Y(N);
    vector<vi> G(MA), H(MA);
    rep(i, N) {
        cin >> X[i] >> Y[i];
        G[X[i]].push_back(Y[i]);
        H[Y[i]].push_back(X[i]);
    }

    UnionFind uf(MA * 2 + 10);
    rep(i, MA) {
        each(y, G[i])uf.unite(MA+y, MA+G[i][0]);
        each(x, H[i])uf.unite(x, H[i][0]);
    }

    ll ans = -N;
    vi vis(MA);
    rep(i, N) {
        int x = uf[X[i]];
        if (vis[x]++)continue;
        ans += (ll)uf.getSize(X[i])*uf.getSize(MA+Y[i]);
    }
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 11648
N, M, C = map(int, raw_input().split())
B = map(int, raw_input().split())
cnt = 0
for i in range(0, N):
	A = map(int, raw_input().split())
	sum = C
	for j in range(0, M):
		sum += A[j]*B[j]
	if sum > 0: cnt += 1

print cnt

Measured memory_bytes: 2568
// atcoder/abc170/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int x, n;
  while (cin >> x >> n) {
    vec<int> v(n);
    cin >> v;

    set<int> vis;
    each (i, v) vis.insert(i);

    sort(v.begin(), v.end());
    int diff = 1 << 29;
    int mn;
    for (int i = -10; i <= 110; ++i) {
      if (!vis.count(i)) {
        if (abs(x - i) < diff) {
          diff = abs(x - i);
          mn = i;
        }
      }
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

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

  int64_t K, N;

  cin >> K >> N;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int64_t m = 0;
  int64_t start = -1;
  for (int64_t i = 1; i < N; i++) {
    if (m < A.at(i) - A.at(i - 1)) {
      m = A.at(i) - A.at(i - 1);
    }
  }
  if (m < A.at(0) + K - A.at(N - 1)) {
    m = A.at(0) + K - A.at(N - 1);
  }
  cout << K - m;

  return 0;
}


Measured memory_bytes: 4752
#include <stdio.h>

char S1[55];
char S2[55];

typedef long long ll;

ll mod=1000000007ll;

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
	scanf(" %c",&S1[i]);
	}
	for(i=0;i<N;i++){
	scanf(" %c",&S2[i]);
	}

	int pos=0;
	int prev;

	ll ans=1ll;

	while(1){

		if(pos>=N){break;}

		if(pos==0){
			if(S1[pos]==S2[pos]){
			ans*=3ll;
			prev=0;
			pos++;
			}
			else{
			ans*=6ll;
			prev=1;
			pos+=2;
			}
		}
		else{
			if(prev==0){
				if(S1[pos]==S2[pos]){
				ans*=2ll;
				ans%=mod;
				prev=0;
				pos++;
				}
				else{
				ans*=2ll;
				ans%=mod;
				prev=1;
				pos+=2;
				}
			}
			else{
				if(S1[pos]==S2[pos]){
				prev=0;
				pos++;
				}
				else{
				ans*=3ll;
				ans%=mod;
				prev=1;
				pos+=2;
				}
			}
		}
	
	}

	printf("%lld\n",ans);

	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  int cnt = 1;
  
  rep(i, N-1){
    if(S.at(i) != S.at(i+1)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
  for j in range(a[i]):
    c.append(i+1)
for i in range(h):
  if i % 2 == 0:
    print(" ".join(map(str, c[i*w:(i+1)*w])))
  else:
    print(" ".join(map(str, c[(i+1)*w-1:i*w-1:-1])))

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int count1 = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1') count1++;
    }
    int count0 = s.size() - count1;

    //cout << "test" << endl << "0:" << count0 << endl << "1:" << count1 << endl;
    cout << s.size() - abs(count0 - count1) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
long long ans;
string str;
int main()
{
	ios::sync_with_stdio(false);
	cin>>str;
	for(int i=0;i<str.size();)
	{
		if(str[i]=='S'&&str[i+1]=='T')
		{
			str.erase(i,2);
			if(i!=0)
				i--;
		}
		else	i++;
	}
	ans=str.size();
	printf("%lld",ans); 
	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N, K;
  	cin>>N>>K;
  	vector<int> h(N);
  	for(int i = 0;i<N;i++){
    	cin>>h[i];
    }

    vector<int> dp(N, 1e9);
    dp[0] = 0;
    for(int i = 1 ;i<N;i++){
      for(int j = 1;j<=min(K, i);j++){
      	dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
      }
    }
  
  	cout<<dp[N-1]<<endl;
}
	

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000


int main(){
	
	long long N,M,V,P;
	cin>>N>>M>>V>>P;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	sort(A.begin(),A.end(),greater<long long>());
	
	long long ok = 10000000000;
	long long ng = -1;
	
	while(ok-ng>1){
		long long mid = (ok+ng)/2;
		long long K = V*M;
		if(A[P-1] > mid){
			ng = mid;
			continue;
		}
		for(int i=0;i<P-1;i++){
			K -= M;
		}
		K -= min(M,mid-A[P-1]);
		if(K<0){
			ok = mid;
			continue;
		}
		
		for(int i=P;i<N;i++){
			K -= min(M,mid - A[i]);
		}
		if(K<=0){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	
	int ans = 0;
	for(int i=0;i<N;i++){
		if(A[i] + M >= ok)ans++;
	}
	
	cout<<ans<<endl;

    return 0;
}

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

void solve()
{
	long long d, t, s;
	cin >> d >> t >> s;

	if(d <= s*t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	solve();
	return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N];
        int[] F = new int[N];
        long sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            sum += A[i];
        }
        for (int i = 0; i < N; i++) {
            F[i] = sc.nextInt();
        }
        Arrays.sort(A);
        Arrays.sort(F);
        if (sum <= K) {
            System.out.println(0);
            return;
        }
        long lo = 0;
        long hi = Long.MAX_VALUE / 3;
        while (hi - lo > 1) {
            long mid = (hi + lo) / 2;
            long need = 0;
            for (int i = 0; i < N; i++) {
                if ((long)A[i] * F[N - 1 - i] > mid) {
                    need += A[i] - mid / F[N - 1 - i];
                }
            }
            if (need <= K) {
                hi = mid;
            } else {
                lo = mid;
            }
        }
        System.out.println(hi);
    }
}


Measured memory_bytes: 102540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    long long a = 0, b = 0, M;
    for(int i = 1; i < N; i++){
        if(A[i - 1] == A[i]){
            a = A[i];
            M = i + 2;
            break;
        }
    }
    for(int i = M; i < N; i++){
        if(A[i - 1] == A[i]){
            b = A[i];
            break;
        }
    }
    
    long long ans = a * b;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    pair<int64_t,int64_t> a[n];
    for(int i=0;i<n;i++){
        a[i].first = i+1;
        cin >> a[i].second;
    }

    for(int i=0;i<n;i++) swap(a[i].first,a[i].second);//2番目の値でソート開始
    sort(a,a+n);
    for(int i=0;i<n;i++) swap(a[i].first,a[i].second);//ソート終了

    int64_t c[n];
    for(int i=0;i<n;i++) c[i]=0;
    c[a[0].second-1]=1;
    for(int i=1;i<n;i++) {
        if(a[i-1].second==a[i].second) {
            c[a[i-1].second-1]++;
        }else{
            c[a[i].second-1]++;
        }
    }

    //cout << endl;
    //for(int i=0;i<n;i++) cout << c[i];

    int64_t d[n];
    for(int i=0;i<n;i++) d[i]=0;
    for(int i=0;i<n;i++){
        if(c[i]>=2) d[i]=c[i]*(c[i]-1)/2;
    }

    //cout << endl;
    //for(int i=0;i<n;i++) cout << d[i];

    int64_t sumcon=0;
    for(int i=0;i<n;i++) sumcon += d[i];

    //cout << endl;
    //cout << sumcon << endl;
    //cout << endl;

    int64_t s[n];
    for(int i=0;i<n;i++) s[i]=0;
    for(int i=0;i<n;i++){
        //cout << c[a[i].second-1] << endl;
        if(c[a[i].second-1]<=1) {
            s[a[i].first-1]=sumcon;
        }else{
            s[a[i].first-1]=sumcon-(c[a[i].second-1]-1);
        }   
    }
    //cout << endl;

    for(int i=0;i<n;i++) cout << s[i] << endl;
}

Measured memory_bytes: 11388
a=list(map(int,input().split()))
if a[0]==0 and a[1]!=100:
    print(a[1])
elif a[0]==0 and a[1]==100:
    print(101)
elif a[0]==1 and a[1]!=100:
    print(str(a[1])+"00")
elif a[0]==1 and a[1]==100:
    print(10100)
elif a[0]==2 and a[1]!=100:
    print(str(a[1])+"0000")
elif a[0]==2 and a[1]==100:
    print(1010000)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int h,w;
  cin>>h>>w;
  char a[h][w];
  rep(i,h){
    rep(j,w){
      cin>>a[i][j];
    }
  }
  vector<bool>ex1(h,false);
  vector<bool>ex2(w,false);
  rep(i,h){
    rep(j,w){
      if(a[i][j]=='#'){
        ex1[i]=true;
        ex2[j]=true;
      }
    }
  }
  rep(i,h){
    if(ex1[i]==true){
      rep(j,w){
        if(ex2[j]==true)
          cout<<a[i][j];
      }
      cout<<endl;
    }
  }
}
  
  

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

int n;
int ax[50],bx[50];
int ay[50],by[50];
int az[50],bz[50];

int input(){
  int fi,se;
  cin>>fi>>se;
  return fi*60+se;
}

int main(){
  cin>>n;
  vector<int> X,Y,Z;
  for(int i=0;i<n;i++){
    ax[i]=input();
    bx[i]=input();
    ay[i]=input();
    by[i]=input();
    az[i]=input();
    bz[i]=input();
    X.push_back(ax[i]);
    Y.push_back(ay[i]);
    Z.push_back(az[i]);
  }
  
  typedef pair<int,int> P;
  P t[100];
  
  int maxm=0;
  for(int I=0;I<(int)X.size();I++){
    int p=X[I];
    for(int J=0;J<(int)Y.size();J++){
      int q=Y[J];
      int cnt=0;
      for(int i=0;i<n;i++){
        if(ax[i]<=p&&p<=bx[i]){
          if(ay[i]<=q&&q<=by[i]){
            t[cnt++]=P(az[i],1);
            t[cnt++]=P(bz[i]+1,-1);
          }
        }
      }
      sort(t,t+cnt);
      int v=0,sum=0;
      for(int i=0;i<cnt;i++){
        sum+=t[i].second;
        v=max(v,sum);
      }
      maxm=max(maxm,v);
    }
  }
  cout<<maxm<<endl;
  return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

/*
Range Sum Query by FenwickTree(Binary Indexed Tree)

total number: n
queries:
    1. add(i, val): bit[i] += val 
    2. sum(n): sum(bit[0] + ... + bit[n-1])
time complexity: O(log n)
space complexity: O(N)

Self-balancing binary search tree or Segment Tree can do the same, it takes longer to program and complexity also increases.

Thanks: http://hos.ac/slides/20140319_bit.pdf
    
used in ARC031 C, indeednow finalB E, DSL2B(AOJ), ARC033 C, yukicoder No.59
*/

template<typename T> struct RangeSumQuery {
  int N;
  vector<T> dat;

  RangeSumQuery(int N) : N(N) {
    assert(N > 0);
    dat.resize(N, 0);
  }

  void add(int k, T val) {
    assert(0 <= k && k < N);
    for (int x = k; x < N; x |= x + 1) {
      dat[x] += val;
    }
  }

  // [0, k)
  T sum(int k) {
    assert(k >= 0);
    T ret = 0;
    for (int x = k - 1; x >= 0; x = (x & (x + 1)) - 1) {
      ret += dat[x];
    }
    return ret;
  }
  // [l, r)
  T sum(int l, int r) {
    assert(0 <= l && l < r && r <= N);
    return sum(r) - sum(l);
  }

  T index(int k) {
    assert(0 <= k && k < N);
    return sum(k+1) - sum(k);
  }
};

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

  int n, q;
  cin >> n >> q;

  RangeSumQuery<int> bit(n);

  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      bit.add(x-1, y);
    } else if (com == 1) {
      cout << bit.sum(x-1, y) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1524
n=int(input())
a=[]
b=[]
for i in range(n):
    na,nb=map(int,input().split())
    a.append(na)
    b.append(nb)
ans=0
num=0
for i in range(n):
    num1=(num+a[-i-1])%b[-1-i]
    if num1!=0:
        num+=b[-1-i]-num1
        ans+=b[-1-i]-num1
print(ans)


Measured memory_bytes: 16904
unittest
{
	assert( [ "8", "1 4", "10 5", "3 3", "4 11", "8 9", "22 40", "8 36", "314159265 358979323" ].parse.expand.solve == "1\n12\n4\n11\n14\n57\n31\n671644785" );
	
	assert( [ "1", "1 1" ].parse.expand.solve == "0" );		// 追加ケース
	assert( [ "1", "882949352 686531654" ].parse.expand.solve == "1557141839" );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto q = input.front.to!( long );
	auto abs = new long[ 2 ][ q ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( abs );
}

auto solve( long[ 2 ][] abs )
{
	auto anss = new long[ abs.length ];
	foreach( ref ans, ab; lockstep( anss, abs ) )
	{
		auto m = ab[ 0 ] * ab[ 1 ] - 1;
		auto s = cast( long ) m ^^ 0.5L;
		if( s == 0 ) continue;
		
		// 高橋君よりスコアが小さくなる順位のパターンの最大数を計算
		ans = s * 2;		// x,yのパターンとy,xのパターンで二倍になる
		
		// x,yとy,xが同じになるパターンがあったら二重カウントされているので除外
		if( s == m / s ) ans--;
		
		// 高橋君と順位が重複するパターンを除外
		if( ab[ 0 ] <= s || ab[ 1 ] <= s ) ans--;
	}
	return anss.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	string s;
	cin >> s;
	int a = s[0]-'0';
	int b = s[1]-'0';
	int c = s[2]-'0';
	int d = s[3]-'0';

	if (a + b + c + d == 7) cout << a << '+' << b << '+' << c << '+' << d;
	else if (a + b + c - d == 7) cout << a << '+' << b << '+' << c << '-' << d;
	else if (a + b - c + d == 7) cout << a << '+' << b << '-' << c << '+' << d;
	else if (a + b - c - d == 7) cout << a << '+' << b << '-' << c << '-' << d;
	else if (a - b + c + d == 7) cout << a << '-' << b << '+' << c << '+' << d;
	else if (a - b + c - d == 7) cout << a << '-' << b << '+' << c << '-' << d;
	else if (a - b - c + d == 7) cout << a << '-' << b << '-' << c << '+' << d;
	else cout << a << '-' << b << '-' << c << '-' << d;

	cout << "=7" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll C[26] = {},inf = 1e9+7;
string S;
int main(){
    cin >> N;
    cin >> S;
    for(int i=0;i<N;i++) C[S[i]-'a']++;
    ll ans = 1;
    for(int i=0;i<26;i++){
        (ans *= C[i]+1)%=inf;
    }
    cout << (ans-1+inf)%inf << endl;
}

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

public class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var piramids = new int[n][];
        var xs = new int[n];
        var ys = new int[n];
        var hs = new int[n];
        for (int i = 0; i < n; i++)
        {
            var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            xs[i] = input[0];
            ys[i] = input[1];
            hs[i] = input[2];
        }

        for (int cy = 0; cy <= 100; cy++)
        {
            for (int cx = 0; cx <= 100; cx++)
            {
                var flag = true;
                var ch = -1;
                var hMax = int.MaxValue;
                for (int i = 0; i < n; i++)
                {
                    var x = xs[i];
                    var y = ys[i];
                    var h = hs[i];
                    var d = Math.Abs(cx - x) + Math.Abs(cy - y);
                    if (h > 0)
                    {
                        var buf = h + d;
                        if (ch > 0 && ch != buf)
                        {
                            flag = false;
                            break;
                        }
                        else
                        {
                            ch = buf;
                        }
                    }
                    else
                    {
                        hMax = Math.Min(hMax, d);
                    }
                }

                if (flag && ch <= hMax)
                {
                    Console.WriteLine($"{cx} {cy} {ch}");
                }
            }
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;
int a[105];
int main()
{
    ft
    int t,i,j,n,m,l,r=0,s=0;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
        a[i]*=(4*m);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>=s)
        {
            r++;
        }
    }
    if(r>=m)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 100100;

int L[MAX];

int sum(int x) {
  int r = 0;
  for (++x; x > 0; x -= x & -x) {
    r += L[x];
  }
  return r;
}

void add(int x) {
  for (++x; x < MAX; x += x & -x) {
    L[x]++;
  }
}

int countInvMod2(vector<int>& a) {
  REP(i, MAX) L[i] = 0;
  int ret = 0;
  REP(i, (int)a.size()) {
    ret ^= (i - sum(a[i])) % 2;
    add(a[i]);
  }
  return ret;
}

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

  int N;
  cin >> N;
  vector<vector<int>> a(3, vector<int>(N));
  REP(i, 3) REP(j, N) { cin >> a[i][j]; }

  vector<int> v(N);
  REP(i, N) {
    vector<int> x = {a[0][i], a[1][i], a[2][i]};
    if (x[0] % 3 == 0 && x[1] == x[0] - 1 && x[2] == x[0] - 2) {
      v[i] = -x[0] / 3;
    } else if (x[2] % 3 == 0 && x[1] == x[2] - 1 && x[0] == x[2] - 2) {
      v[i] = x[2] / 3;
    } else {
      cout << "No\n";
      return 0;
    }
  }

  int c[2] = {0, 0};
  vector<int> w[2];
  REP(i, N) {
    int orig_idx = abs(v[i]) - 1;
    int slot = i % 2;

    if ((i - orig_idx) % 2) {
      cout << "No\n";
      return 0;
    }

    w[slot].push_back(abs(v[i]) - 1);

    if (v[i] < 0) {
      c[slot] ^= 1;
    }
  }

  c[0] ^= countInvMod2(w[1]);
  c[1] ^= countInvMod2(w[0]);

  if (c[0] % 2 || c[1] % 2) {
    cout << "No\n";
    return 0;
  }

  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 2948
#include "bits/stdc++.h"
using namespace std;
int w[10002];
int e[10002];
int main()
{
	int n,m;
	string d[100];
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>d[i];
	fill(e,e+10002,0);
	fill(w,w+10002,0);
	//累積和
	for(int i=1;i<n+1;i++)
	{
		w[i]=w[i-1];
		e[i]=e[i-1];
		for(int j=0;j<m;j++)
		{
			if(d[j][i-1]=='E')
				e[i]++;
			if(d[j][i-1]=='W')
				w[i]++;
		}
	}
	w[n+1]=w[n];
	e[n+1]=e[n];
	//境界の探索
	int err=1e8-1;
	int ans=-1;
	for(int i=0;i<n+1;i++)
	{
		//cerr<<w[i]<<" "<<e[i]<<endl;
		if(err>e[i]+w[n+1]-w[i])
		{
			err=e[i]+w[n+1]-w[i];
			ans=i;
		}
	}
	cout<<ans<<" "<<ans+1<<endl;
	return 0;
}


Measured memory_bytes: 4624
/**< 🤣🤣🤣 */
#include<bits/stdc++.h>
using namespace  std ;
typedef long long  ll;
typedef pair<ll, ll> Pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define deb(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define all(x) x.begin(),x.end()
#define deb1(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << #z << " " << z << endl;
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define RFOR(I,B,A) for(ll I = (B); I >=(A); I--)
#define Time cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "sec \n"
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define SORT(c) (sort(c.begin(),c.end()))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define IOS  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int mx = 32000;
vector<ll>a1,b1,c1;
map<ll,ll>m1,m2,m3;
bool isPrime[mx];

ll POWER(ll y,ll z){ll res=1;while(z){if(z%2==1){res=(res*y)%mod;}y=(y*y)%mod;z>>=1LL;}return res;}
void sieve(){for(ll i=2; i<=mx; i++)isPrime[i]=true;for(ll i=3; i<=mx; i+=2){if(isPrime[i]==true)
{for(ll J=i*i; J<=mx; J+=i)isPrime[J]=false;}}}

/************************************************/

void Execute()
{
      ll n, nb, val, q, a, b, c, l, r, d, x, y, p, m;
      cin >> n;

      FOR(i,1,12){
        x = i*1000;
        if(x>=n){
          deb(x-n);
          break;
        }
      }



}

int32_t main()
{
  //  #ifndef ONLINE_JUDGE
    //freopen("atomm.txt", "r", stdin);
    //#endif

    IOS
    //CASES
    //{
        Execute();
      //  Time;
  //  }
}
/**< 🤣🤣🤣 */


Measured memory_bytes: 3648
import numpy as np
mod = 10 ** 9 + 7

n = int(input())
a = np.asarray(list(map(int, input().split())))
ans = 0
bit = 1
for i in range(60):
  n_one = np.count_nonzero(a & 1)
  ans += n_one * (n - n_one) * bit
  a >>= 1
  bit *= 2
  ans %= mod
  bit %= mod
print(ans)

Measured memory_bytes: 48824
#include<iostream>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;


int main()
{
  map<int,bool> exist;
  int a,b;
  cin >> a >> b;
  vector<int> A,B;
  vector<vector<int> > men;
  men.resize(2);
  men[0].resize(b),men[1].resize(b);
  A.resize(a),B.resize(b);
  for(int i=0;i<a;i++)
    scanf("%d",&A[i]);
  for(int i=0;i<b;i++)
    scanf("%d",&B[i]),men[0][i] = men[1][i] = 0,exist[B[i]] = true;

  

  int mex = 0;
  for(int i=0;i<a;i++)
    {
      if(!exist[A[i]])
	continue;
     
      for(int j=0;j<b;j++)
	{
	  if(A[i] == B[j])
	    {
	      men[1][j] = max(men[0][j],j-1>=0?men[0][j-1]+1:0);
	      if(!men[1][j])
		men[1][j] = 1;
	      mex = max(men[1][j],mex);
	    }
	}
      men[0] = men[1];
    }
 
  cout << mex << endl;
  return 0;
}

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

int main()
{
  int a,b,ab;
  cin >> a >> b >> ab;
  
  int x,y;
  cin >> x >> y;
  
  ll ans = x*a + y*b;
  if(ab*max(x,y)*2 < ans)
  {
    ans = ab * max(x,y) * 2;
  }
  
  if(ab*min(x,y)*2 + a*(x-min(x,y)) + b*(y-min(x,y)) < ans)
  {
    ans = ab * min(x,y) * 2 + a*(x-min(x,y)) + b*(y-min(x,y));
  }
  
  
  cout << ans << endl;
}

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

int n;
int arr[100100];
int dp[100100];
bool vis[100100];

int func( int pos ) {
  if (pos == n) return 0;
  if (vis[pos]) return dp[pos];
  vis[pos] = 1;

  int x = INT_MAX, y = INT_MAX;
  if (pos + 1 <= n) x = func(pos + 1) + abs(arr[pos] - arr[pos + 1]);
  if (pos + 2 <= n) y = func(pos + 2) + abs(arr[pos] - arr[pos + 2]);
  return dp[pos] = min(x, y);
}

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

  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> arr[i];

  cout << func(1) << endl;

  
  return 0;
}


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


using namespace std;

int main() {
    string s;

    cin >> s;

    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int k, a, b;
    cin >> k >> a >> b;

    if(a % k == 0 || b % k ==0){
        cout << "OK" << endl;
    }else{
        int n = a/k, m = b/k;
        if(n != m){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3652
object Main {
  def main(args: Array[String]): Unit ={
    A.answer()
  }
}

object A {
  import scala.io.StdIn.readLine
  def input[A](change: String => A) = readLine.split(" ").map(change(_))
  def answer(): Unit = {
    val k = input((a=>a.toArray.foldLeft("")((acc, c) => {
      acc + (c match {
        case '1' => "9"
        case '9' => "1"
        case _ => c.toString
      })
    }))).head
    println(k)
  }
}

Measured memory_bytes: 27448
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 2019;
    int[] child,color,count;
    long[] res;
    ArrayList<Integer>[] tree;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        out.println(main.solve());
        out.flush();
    }
    long solve(){
        String s = sc.next();
        char[] arr = s.toCharArray(); // arr[i] is '1'-'9'
        int n = arr.length;
        if(n<4) return 0;
        HashMap<Long,Integer> map = new HashMap<>(2020);
        long base = 1;
        long[] num = new long[n+1];
        for(int i=n-1;i>=0;i--){
            long cur = arr[i]-'0';
            num[i] = (num[i+1]+cur*base%mod)%mod;
            base = base*10%mod;
        }
        long ans = 0;
        for(int i=n-4;i>=0;i--){
            map.put(num[i+4], map.getOrDefault(num[i+4],0)+1);
            ans += map.getOrDefault(num[i],0);
        }
        return ans;
    }

}



Measured memory_bytes: 57432
#include<stdio.h>
int mx(int a,int b){
  if(a<b)return b;
  else   return a;
}
int main(){
  int N,W,c=1,mi,max,i,j;
  int k[1001],w[1001];
  while(1){
    scanf("%d",&W);
    if(!W)break;
    scanf("%d",&N);
    int dp[1001][1001]={0};
    for(i=0;i<N;i++){
      scanf("%d,%d",&k[i],&w[i]);
    }
    for(i=N-1;i>=0;i--){
      for(j=0;j<=W;j++){
	if(j<w[i])dp[i][j]=dp[i+1][j];
	else{
	  dp[i][j]=mx(dp[i+1][j],dp[i+1][j-w[i]]+k[i]);
	}
      }
    }
    max=0;
    mi=0;
    for(i=0;i<=W;i++){
      if(max<dp[0][i]){
	max=dp[0][i];
	mi=i;
      }
    }
    printf("Case %d:\n%d\n%d\n",c++,max,mi);
  }
  return 0;
}

Measured memory_bytes: 4532
#include<stdio.h>
#include<stdlib.h>


int cmp( const void *a ,const void *b )
{
	return *( int* )a - *( int* )b ;
}

#define N_MAX 100000
int times[ N_MAX + 1 ] ;


int main( void )
{
	int N ,K ;
	scanf( "%d %d" ,&N ,&K ) ;
	int i ;
	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%d" ,times + i ) ;

		if( i > 0 )
		{
			times[ i - 1 ] = times[ i ] - times[ i - 1 ] - 1 ;
		}
	}
	
	qsort( times ,N - 1 ,sizeof( int ) ,cmp ) ;
	
	int sum = N ;	N -= K ;
	for( i = 0 ; i < N ; ++i )
	{
		sum += times[ i ] ;
	}

	printf( "%d\n" ,sum ) ;

	return 0 ;
}


Measured memory_bytes: 2368
#include<iostream>

using namespace std;

int a[(int)1e5];
int n;

int main(){
	cin >> n;
	if(n==1){
		cout << "1\n";
		return 0;
	}

	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	int ans=0;
	for(int i=1;i<=n;i++){
		ans++;
		while(i<n && a[i]==a[i-1]) i++;
		if(i==n) break;
		if(a[i-1] < a[i]) while(i<n && a[i-1] <= a[i])i++;
		else			while(i<n && a[i-1] >= a[i])i++;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N;
   cin>>N;
   int m=0;
   for(int i=1;i<10;i++){
       if(N==10*i+9||N==90+(i-1)){
           cout<<"Yes"<<endl;
           m++;
           break;
       }
   }
   if(m==0){
       cout<<"No"<<endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003, M = N << 1;

int n, k;
int a[N], b[N];
char s[N];

int main()
{
    n = gi(), k = gi();
    for (int i = 1; i <= k; i+=1)
    {
        int d = gi();
        for (int j = 1; j <= d; j+=1)
            a[j] = gi(), ++b[a[j]];
    }
    int cnt = 0;
    for (int i = 1; i <= n; i+=1) cnt += (b[i] == 0);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3644