akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int H, W, N, sr, sc;
string S, T;

bool solve() {
    // left, right
    int left = 0, right = W;
    if (S[N - 1] == 'L') ++left;
    if (S[N - 1] == 'R') --right;
    for (int i = N - 2; i >= 0; --i) {
        if (T[i] == 'L') right = min(right + 1, W);
        else if (T[i] == 'R') left = max(0, left - 1);
        if (S[i] == 'L') left = left + 1;
        else if (S[i] == 'R') right = right - 1;
        if (left >= right) return false;
    }
    if (sc < left || sc >= right) return false;

    // up, down
    left = 0, right = H;
    if (S[N - 1] == 'U') ++left;
    if (S[N - 1] == 'D') --right;
    for (int i = N - 2; i >= 0; --i) {
        if (T[i] == 'U') right = min(right + 1, H);
        else if (T[i] == 'D') left = max(0, left - 1);
        if (S[i] == 'U') left = left + 1;
        else if (S[i] == 'D') right = right - 1;
        if (left >= right) return false;
    }
    if (sr < left || sr >= right) return false;

    return true;
}

int main() {
    cin >> H >> W >> N >> sr >> sc >> S >> T;
    sr--;
    sc--;
    if (solve()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 776
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

A, B, C = ISI()
for i in range(1, B+1):
    if A*i%B == C:
        print("YES")
        break
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    queue<int> c;
    for (int i = 0; i < n; i++) {
        c.push(i);
    }

    ll r = 0;
    while (!c.empty()) {
        int i = c.front(); c.pop();
        int i1 = i - 1; if (i1 < 0) i1 += n;
        int i2 = i + 1; if (i2 >= n) i2 -= n;
        int s = b[i1] + b[i2];
        int t = b[i] - a[i];
        if (t >= s) {
            int x = t / s;
            b[i] -= x * s;
            r += x;
            c.push(i1);
            c.push(i2);
        }
    }

    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) r = -1;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include<vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<long long int> a(N+5,0);

    for (int i = 0; i < N;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(),greater<long long int>());

    long long int max1 = 0, max2 = 0;
    for (int i = 0; i < N-1;i++){
        if(max1!=0 && max2!=0)
            break;
            if(a[i]==a[i+1]){
                if(max1==0){
                    max1 = a[i];
                    i++;
                }else{
                    max2 = a[i];
                }
            }
    }
    cout << max1*max2 << endl;
    return 0;
}

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


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  string s;
  cin >> n >> k >> s;
  string ans;
  for(int i = 0;i < n;i++) {
      if(i == k-1) {
          ans += tolower(s[i]);
      } else {
          ans+= s[i];
      }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, p; cin >> n >> p;
    int q = 100 - p;
    vll w(n), b(n);
    using Elem = tuple<ll, int>;
    vector<Elem> tbl(n);
    ll sum_b = 0;
    rep(i, n) cin >> w[i] >> b[i], tbl[i] = Elem(q * w[i] + p * b[i], i), sum_b += b[i];
    sort(_all(tbl), greater<Elem>());

    ll cur = 0;
    int res = 0;
    for(auto& e : tbl){
        res++;
        cur += get<0>(e);
        if(cur >= p * sum_b){
            cout << res << endl;
            return 0;
        }
    }
    assert(false);

    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 103,K = 100003;
ll i,j,k,n;
ll a[N],dp[N][K],pre[N][K];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
    rep(i,1,n + 1) cin>>a[i];
    dp[0][0] = 1;
    rep(i,0,k + 1){
        pre[0][i] = dp[0][i];
        if(i)
            pre[0][i] = (pre[0][i] + pre[0][i - 1]) % mod;
    }
    rep(i,1,n + 1){
        rep(j,0,k + 1){
            if(j <= a[i])
                dp[i][j] = pre[i - 1][j];
            else
                dp[i][j] = (pre[i - 1][j] - pre[i - 1][j - a[i] - 1] + mod) % mod;
        }
        rep(j,0,k + 1){
            pre[i][j] = dp[i][j];
            if(j)
                pre[i][j] = (pre[i][j] + pre[i][j - 1]) % mod;
        }
    }
    cout<<dp[n][k];
    return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == -1) {
            break;
        }
        long long output = 0;
        for (int i = 0; n > 0; i++) {
            output += (n % 4) * pow(10, i);
            n /= 4;
        }
        cout << output << endl;
    }
}

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

int main(){
  int M1, M2;
  int D1, D2;
  cin >> M1 >> D1;
  cin >> M2 >> D2;
  if(M2!=M1){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

ll n, m;
ll a[1500000];
vector<ll> open[1500000];
vector<ll> close[1500000];
ll ans = 0;
ll optimize = 0;

int cld(int x, int y)
{
    if (x <= y) return y - x;
    else return m - x + y;
}

signed main()
{
    srand(time(NULL));
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 2; i <= n; i++)
    {
        ans += cld(a[i - 1], a[i]);
        if (a[i - 1] < a[i])
        {
            open[a[i - 1] + 1].push_back(0);
            close[a[i]].push_back(cld(a[i - 1], a[i]) - 1);
            
            open[a[i - 1] + 1 + m].push_back(0);
            close[a[i] + m].push_back(cld(a[i - 1], a[i]) - 1);
        }
        else
        {
            open[a[i - 1] + 1].push_back(0);
            close[a[i] + m].push_back(cld(a[i - 1], a[i]) - 1);
            
            open[a[i - 1] + 1 + m].push_back(0);
        }
    }
    ll cur = 0, elems = 0;
    for (int i = 1; i <= 2 * m; i++)
    {
        for (int j = 0; j < open[i].size(); j++)
        {
            cur += open[i][j];
            elems++;
        }
        optimize = max(optimize, cur);
        //cout << ans - cur << " " << i << "\n";
        for (int j = 0; j < close[i].size(); j++)
        {
            cur -= close[i][j];
            elems--;
        }
        cur += elems;
    }
    //cout << "\n";
    cout << ans - optimize;
}


Measured memory_bytes: 78976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k;
    cin>>a>>b>>k;
    rep(i,k){
      if(i%2==0){
        b+=(a/2);
        a/=2;
        //cout<<a<<' '<<b<<'\n';
      }else{
        a+=(b/2);
        b/=2;
        //cout<<a<<' '<<b<<'\n';
      }
    }
    cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    cout << a+b+c-max(a,max(b,c)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 

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

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

int H, W; cin >> H >> W;
VS s(H); invec(s);

VVI cnt(H, VI(W, INF)); // .と＃の変わる回数。
cnt[0][0] = (s[0][0] == '#');

rep(i, 0, H) rep(j, 0, W){
    if (i + 1 < H){
        if (s[i][j] == '.' && s[i+1][j] == '#') cnt[i+1][j] = min(cnt[i+1][j], cnt[i][j] + 1);
        else cnt[i+1][j] = min(cnt[i+1][j], cnt[i][j]);
    }
    if (j + 1 < W){
        if (s[i][j] == '.' && s[i][j+1] == '#') cnt[i][j+1] = min(cnt[i][j+1], cnt[i][j] + 1);
        else cnt[i][j+1] = min(cnt[i][j+1], cnt[i][j]);
    }
}


cout << cnt[H-1][W-1] << "\n";


return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 境界，出力文字列 チェック．行末にスペース入れない．
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
 
ans = sum(b)
for i in range(1,n):
    if a[i]-1==a[i-1]:
        ans+=c[a[i-1]-1]
print(ans)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      s = set([a[i],a[j],a[k]])
      if len(s) == 3:
        if (a[i]+a[j] > a[k]) and (a[i]+a[k] > a[j]) and (a[j]+a[k] > a[i]):
          ans += 1
print(ans)

Measured memory_bytes: 9212
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);
	
	int n;
	public void run() {
		while(sc.hasNext()){
			n=sc.nextInt();
			int d=0;boolean isFirst=true;
			while(n!=0){
				if(n%2==1){
					pr((isFirst?"":" ")+(1<<d));
					isFirst=false;
				}
				d++;
				n/=2;
			}
			ln();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
} 

Measured memory_bytes: 12000
inf = float('inf')
V,E = map(int,input().split())
edge = []
edge_rev = []
for i in range(E):
    A,B,C = map(int,input().split())
    edge_rev.append([B-1,A-1,-C])
    edge.append([A-1,B-1,-C])

d = [inf]*V
d[0] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break

d_rev = [inf]*V
d_rev[V-1] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge_rev[j]
        if d_rev[From] != inf and d_rev[To]>d_rev[From]+cost:
            d_rev[To]=d_rev[From]+cost
            update = True
    if not update:
        break

d_ = [x for x in d]
d_rev_ = [x for x in d_rev]



for j in range(E):
    From,To,cost = edge[j]
    if d[From] != inf and d_rev[From] != inf and d[To]>d[From]+cost:
        d[To]=d[From]+cost


for j in range(E):
    From,To,cost = edge_rev[j]
    if d[From] != inf and d_rev[From] != inf and d_rev[To]>d_rev[From]+cost:
        d_rev[To]=d_rev[From]+cost


loop = False
for i in range(V):
    if d[i] != 0 and d_rev[i] != 0:
        loop = (d[i]+d_rev[i] != d_[i]+d_rev_[i]) or loop

if loop:
    print('inf')

else:
    ans = -d[-1]
    print(ans)

Measured memory_bytes: 49112
void solve(){
}
void main(){
	int a, b, c, d;
	readf("%d %d %d %d\n", &a, &b, &c, &d);
	if( abs(a-c)<=d || ( abs(a-b)<=d && abs(b-c)<=d ) ){
		writeln("Yes");
	}else{
		writeln("No");
	}
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
alias instr = () => readln().chomp();
T inelm(T= int)(){ return to!(T)( readln().chomp() ); }
T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }



Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        A[i] = c - '0';
    }
    reverse(A.begin(), A.end());
    map<int, int> convert;
    int default_cnt = 0;
    for (int i = 0; i < N; i++) if (A[i] == 1) default_cnt++;
    convert[default_cnt - 1] = 0;
    convert[default_cnt] = 1;
    convert[default_cnt + 1] = 2;
    vector<vector<ll>> value(3, vector<ll>(N));
    for (int i = 0; i < 3; i++) value[i][0] = 1;
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            if (default_cnt + j - 1 <= 0) continue;
            value[j][i] = value[j][i - 1] * 2;
            value[j][i] %= (default_cnt + j - 1);
        }
    }
    vector<ll> sum_value(3);
    for (int i = 0; i < N; i++) {
        if (A[i] == 0) continue;
        for (int j = 0; j < 3; j++) sum_value[j] += value[j][i];
    }
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        int cnt = 1;
        ll popcnt = default_cnt;
        if (A[i] == 1) popcnt--;
        else popcnt++;
        if (popcnt == 0) {
            ans.push_back(0);
            continue;
        }
        ll now = sum_value[convert[popcnt]];
        if (A[i] == 1) now -= value[convert[popcnt]][i];
        else now += value[convert[popcnt]][i];
        now %= popcnt;
        while (now > 0) {
            cnt++;
            popcnt = __builtin_popcountll(now);
            now %= popcnt;
        }
        ans.push_back(cnt);
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 11212
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),
                dp[i-2] + abs(h[i] - h[i-2]))

print(dp[n-1])

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

using pll = pair<long long, long long>;

void normalize(vector<pll> &nums) {
    if (nums.size() > 1) {
        if (nums[nums.size()-1].first == nums[nums.size()-2].first) {
            nums[nums.size()-2].second += nums[nums.size()-1].second;
            nums.pop_back();
        }
    }
}

void zouka(vector<pll> &nums) {
    if (nums.back().second == 1) {
        nums.back().first += 1;
    }
    else {
        nums.back().second--;
        nums.push_back(pll(nums.back().first+1, 1));
    }
    normalize(nums);
}

int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    long long low = 0, high = N+1;
    while (high - low > 1) {
        long long mid = (low + high) / 2;
        
        vector<pll> nums;
        nums.push_back(pll(0, a[0]));
        bool ok = true;
        for (int i = 1; i < N; ++i) {
            if (a[i-1] < a[i]) nums.push_back(pll(0, a[i] - a[i-1]));
            else {
                long long sum = 0;
                while (nums.size() > 0 && sum + nums.back().second <= a[i-1] - a[i]) {
                    sum += nums.back().second;
                    nums.pop_back();
                }
                nums.back().second -= a[i-1] - a[i] - sum;

                if (nums.back().first == mid-1) {
                    if (nums.size() == 1) {
                        ok = false;
                        break;
                    }
                    long long num = nums.back().second;
                    nums.pop_back();
                    zouka(nums);
                    nums.push_back(pll(0, num));
                }
                else zouka(nums);
            }
            normalize(nums);
        }

        if (ok) high = mid;
        else low = mid;
    }
    cout << high << endl;
}

Measured memory_bytes: 1792
import * as fs from 'fs'
function main(input: string) {
  const lines = input.split('\n')

  const [k, x] = lines[0].split(' ').map(Number)
  const start = Math.min(x - k + 1, 1000000)
  const end = Math.max(x + k - 1, -1000000)
  const a = []
  for (let i = start; i <= end; i++) {
    a.push(i)
  }
  console.log(a.join(' '))
  // console.log({ a, b, c })
}

const path = process.argv[2]
if (!path) {
  main(fs.readFileSync('/dev/stdin', 'utf8'))
} else {
  const testPath = `${path}/tests`
  const files = fs.readdirSync(testPath)
  const qn = files.length / 2
  for (let i = 1; i <= qn; i++) {
    console.log(`${testPath}/sample-${i}.in`)
    console.log('-- res')
    main(fs.readFileSync(`${testPath}/sample-${i}.in`, 'utf8'))
    console.log('-- expected')
    console.log(fs.readFileSync(`${testPath}/sample-${i}.out`, 'utf8'))
  }
}


Measured memory_bytes: 7372
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    a,b,c,k = readInt()
    ans = 0
    if a>k:
        print(k)
        return
    else:
        ans += a
        k -= a
    if b>k:
        print(ans)
        return
    else:
        k -= b
    if c>k:
        ans -= k
    else:
        ans -= c
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9196
N = int(input())
E = [set() for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  E[a].add(b)
  E[b].add(a)
DF = [-1]*N
q = [0]
DF[0] = 0
while q:
  c = q.pop()
  ns = E[c]
  for n in ns:
    if DF[n] < 0:
      DF[n] = DF[c]+1
      q.append(n)
#print(DF)
DS = [-1]*N
q = [N-1]
DS[N-1] = 0
while q:
  c = q.pop()
  ns = E[c]
  for n in ns:
    if DS[n] < 0:
      DS[n] = DS[c]+1
      q.append(n)
NF = 0
NS = 0
for i in range(N):
  if DF[i] <= DS[i]:
    NF += 1
  else:
    NS += 1
#print(NF, NS)
if NF > NS:
  print("Fennec")
else:
  print("Snuke")


Measured memory_bytes: 40368
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outc(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(32);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
//Unaccepted
const int maxn = 1e6 + 5;
int sum[maxn];
int dp[2][maxn], f[2][maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    cout << 3 * n * n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
typedef pair<int, int> P;
vector<int> G[2000];


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

	int N, K;
	cin >> N >> K;

	vector<P> es;
	for(int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
		es.push_back(P(a, b));
	}

	int ans = 1000000;
	for(int i = 0; i < N; i++) {
		vector<int> d(N, -1);
		queue<int> q;
		if(K % 2 == 1) {
			if(i == N - 1) break;
			d[es[i].first] = d[es[i].second] = 0;
			q.push(es[i].first);
			q.push(es[i].second);
		}
		else {
			d[i] = 0;
			q.push(i);
		}

		while(!q.empty()) {
			int v = q.front();
			q.pop();
			for(int u : G[v]) {
				if(d[u] == -1) {
					d[u] = d[v] + 1;
					q.push(u);
				}
			}
		}

		int over = 0;
		for(int j = 0; j < N; j++) {
			if(d[j] > K / 2) over++;
		}
		ans = min(ans, over);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>n;--i)

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c;
    
    cin >> a >> b >> c ;
    if(a==b) 
    {
        if(a==c) cout << "No" << endl ;
        else cout << "Yes" << endl ;
    }
    else if(a==c||b==c)
    {
        cout << "Yes" << endl ;
    }
    else cout << "No" << endl ;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int n,a,b;
    int i;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    int ans = 0;
    int p[100];
    scanf("%d", &n);
    scanf("%d %d", &a,&b);

    for (i = 0; i<n; i++){
        scanf("%d", &p[i]);
        if(a>=p[i]){
          c1++;
        }if(a<p[i] && b>=p[i]){
          c2++;
        }if(b<p[i]){
          c3++;
        }
    }
    ans = c1;
    if(ans>c2){
      ans = c2;
    }
    if(ans>c3){
      ans = c3; 
    }
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = list(map(int, input().split()))
ans = [-1] * (2 *10 ** 5 + 1)
left = False
right = False
if n % 2 == 0:
    left = True
else:
    right = True
start = n // 2
ans[start] = a[0]
for i in range(1, n):
    if left:
        ans[start - i] = a[i]
        start -= i
        left = False
        right = True
    else:
        ans[start + i] = a[i]
        start += i
        left = True
        right = False
for i in range(n):
    print(ans[i], " ", sep="", end="")



Measured memory_bytes: 27604
# -*- coding: utf-8 -*-
from pprint import pprint as pp
N, M = map(int, input().split())
Xm = list(map(int, input().split()))

if N >= M:
    print(0)
    exit()

# center
Xm.sort()
subt = []
for i in range(M-1):
    subt.append(abs(Xm[i+1]-Xm[i]))

subt.sort(reverse=True)
print(sum(subt[N-1:]))


Measured memory_bytes: 14472
#include <stdio.h>

int main(void)
{
    char buffer[256];
    int a, b, c, i, counter=0;

    fgets(buffer, 256, stdin);
    sscanf(buffer, "%d %d %d", &a, &b, &c);
    for (i = a; i <= b; i++)
    {
        if (c % i == 0) counter++;
    }
    printf("%d\n", counter);
    return(0);
}


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

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

    for(int i = 0; i < n; i++ ){
        int h;
      cin >> h;
        if(h >= k){
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 888
r,g,b,n=map(int,input().split())

count=0
for ri in range(int(n/r)+1):
    for gi in range(int((n-ri*r)/g)+1):
        sumc=n-ri*r-gi*g
        if sumc<0:
            break
        if sumc%b==0:
            count+=1

print(count)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s1 = 0, s2 = 0;
        for (int i = 0; i < n; i++) {
            String[] a = new String[]{sc.next(), sc.next()};
            int z = a[0].compareTo(a[1]);
            if (z > 0) {
                s1 += 3;
            } else if (z < 0) {
                s2 += 3;
            } else {
                s1++;
                s2++;
            }
        }
        System.out.println(s1 + " " + s2);
    }
}

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

using namespace std;

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

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

  if (abs(x - a) < abs(x - b))
    cout << "A\n";
  else
    cout << "B\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8
int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define ll long long

using namespace std;

int main() {
  string s; cin >> s;
  if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3592
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 


#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

int main() {
    
    fastio;
    int n;
    cin >> n;
    int p[n];
    rep(i, n)
    cin >> p[i];
    int cnt = 0;
    fr(i, 1, n-2)
    {
        int x[3];
        x[0] = p[i-1];
        x[1] = p[i];
        x[2] = p[i+1];
        sort(x, x+3);
        if(x[1] == p[i])
            cnt++;
    }
    cout << cnt;
    return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main(void) {
  int a, b, c;

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

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

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    for i in range(N):
        A = int(next(tokens))
        if A%2==0 and A%3 != 0 and A%5 != 0:
            print("DENIED")
            return

    print("APPROVED")
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
int main(){
	long long int a;
	cin>>a;
	string s;
	for(long long int i=0;i<a;i++){
		cin>>s;
		sort(s.begin(),s.end());
		v.push_back(s);
	}
	
	long long int toplam=0;
	long long int cevap=0;
	long long int ek=0;
	sort(v.begin(),v.end());
	for(long long int i=0;i<v.size()-1;i++){
		if(v[i]==v[i+1]){
			if(ek==0){
				toplam++;
			}
			toplam++;
			ek=1;
		}
		else{
			//cout<<toplam;
			cevap=cevap+(toplam*(toplam-1))/2;
			toplam=0;
			ek=0;
		}
	}
	cevap=cevap+(toplam*(toplam-1))/2;
	cout<<cevap;
}

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

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

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

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

int main(){
	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	n --;
	
	ll t = 0;
	while(t < n && d*t-c*(n-t)<b-a)t ++;
	ll l = c*t-d*(n-t);
	ll r = d*t-c*(n-t);
	//cout << t << " " << l << " " << r << endl;
	if(l <= b-a && b-a <= r)puts("YES");
	else puts("NO");
}



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

int main()
{
    char ch[200010];
    int i=0,sum=0;
    scanf("%s",&ch);
    while(ch[i]!='\0')
    {
        sum=sum+ch[i]-48;
        i++;
    }
    if(sum%9==0)
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

#define MAX 500
int C[MAX],S[MAX],F[MAX];

int main(){
	int n;	cin>>n;
	for(int i=1;i<n;i++) cin>>C[i]>>S[i]>>F[i];

	for(int start=1; start<n; start++){
		int time=0;
		for(int x=start; x<n;x++){
			if(time<S[x]) time=S[x];

			if( time%F[x] ){
				time+= F[x]-(time%F[x]);
			}
			time+=C[x];
		}
		cout<<time<<endl;
	}
	cout<<0<<endl;

	return 0;
}


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



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);

        int ans = 0;
        for (int i = 1; i < N; i++)
        {
            if(A[i-1] == A[i])
            {
                ans++;
                i++;
            }
        }
        Console.WriteLine(ans);
    }


}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 11092
#include<stdio.h>
#include<utility>
#include<iostream>
#include<algorithm>
#include<vector>
 
using namespace std;
 
int main()
{
int a,b;
cin>>a>>b;
if(a+b>9)
cout<<"error"<<endl;
else cout<<a+b<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int c[26] = {0};
  char str[1000] = {0};
  cin >> str;
  for(int i = 0; str[i] != 0; i++){
    c[str[i] - 'a']++;
  }
  for(int i = 0; i < 26; i++){
    if(c[i] % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end
h,n = inp
t = inp.sort
puts (h<=sum(t))? "Yes" : "No"

Measured memory_bytes: 10784
#include <iostream> 
#include <algorithm>
#include <vector>

using namespace std; 

// It looks like this bullshit manual code doesn't work on some obscure cases

// Returns the exclusive lower bound index in sorted array 
int binary_search(vector<long long>& arr, long long val) {
  int lo = -1; // Lower bound exclusive
  int hi = arr.size(); // Upper search bound 
  
  while (hi - lo > 1) {
    int mid = lo + (hi - lo) / 2;
    if (arr[mid] <= val) lo = mid; 
    else hi = mid; 
  }
  return hi; // if it doesn't exist it returns arr.size() which is fine
}

// int main() {
//   int N; cin >> N;
//   vector<int> A(N);
//   for (int i = 0; i < N; i++) {
//     cin >> A[i];
//   }
//   vector<int> B(N);
//   for (int j = 0; j < N; j++) {
//     cin >> B[j];
//   }
//   vector<int> C(N);
//   for (int k = 0; k < N; k++) {
//     cin >> C[k];
//   }

//   sort(A.begin(), A.end());
//   sort(B.begin(), B.end());
//   sort(C.begin(), C.end());

//   long long ans = 0;

//   // O(NlogN)
//   int b_scores_cumulative[N+1];
//   b_scores_cumulative[N] = 0;
//   for (int i = N - 1; i >= 0; i--) {
//     int index = binary_search(C, B[i]);
//     b_scores_cumulative[i] = b_scores_cumulative[i+1] + N - index;
//   }

//   // O(NlogN)
//   for (int j = N - 1; j >= 0; j--) {
//     int index = binary_search(B, A[j]);
//     ans += b_scores_cumulative[index];
//   }

//   cout << ans << endl;
// }

// Hint instead of thinking A -> B and B -> C, think B -> A and B -> C
// Instead of taking time to build lower and upper bound searchers just use std::lower_bound and std::upper_bound 
// Moral of the lesson: just use stl whenever possible... and watch out for types 
int main() {
  int N; cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<long long> B(N);
  for (int j = 0; j < N; j++) {
    cin >> B[j];
  }
  vector<long long> C(N);
  for (int k = 0; k < N; k++) {
    cin >> C[k];
  }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  long long ans = 0;
  for (int j = 0; j < N; j++) {
    auto i = lower_bound(A.begin(), A.end(), B[j]); // Everything to the left of the inclusive lower bound -> exclusive
    long long a_score = i - A.begin(); // Iterator differences (and indices) can be taken from subtraction
    auto k = upper_bound(C.begin(), C.end(), B[j]); // Everything to the right of the exclusive lower bound -> inclusive
    long long c_score = C.end() - k;
    ans += a_score * c_score; // Lol this is the exact thing I did except with my own func... which once again is verified 
  }

  cout << ans << endl;
}

Measured memory_bytes: 2560
//此程序使用了qt专属名称，请勿模仿。侵权必究！！！
//我真是太菜了……
#include<bits/stdc++.h>
using namespace std;
#define us unsigned
#define ll long long
const int N=7000010,inf=0x3f3f3f3f;
int n,m,k,t=0,b[N<<3];
int dis[N<<2];
bool v[N<<2];
map<pair<int,int>,int> mp;
struct tq
{
	int y;
	int nxt;
	int v;
}a[N<<3];
inline void in(int x,int y,int z)
{
	a[++t].nxt=b[x];
	b[x]=t;
	a[t].y=y;
	a[t].v=z;
	return;
}
inline int read()
{
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
inline void SPFA(int S)
{
	queue<int> q;
	memset(dis,120,sizeof(dis));
	memset(v,0,sizeof(v));
	dis[S]=1;
	q.push(S);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		v[x]=0;
		for(int i=b[x];i;i=a[i].nxt)
		{
			int y=a[i].y;
			if(dis[y]>dis[x]+a[i].v)
			{
				dis[y]=dis[x]+a[i].v;
				if(!v[y])
				{
					q.push(y);
					v[y]=1;
				}
			}
		}
	}
}
inline int qt(int x,int y)
{
	if(mp.find({x,y})!=mp.end())
	{
		return mp[{x,y}];
	}
	return mp[{x,y}]=++k;
}
int main()
{
//	freopen("railway.in","r",stdin);
//	freopen("railway.out","w",stdout);
	n=read();
	k=n; 
	m=read();
	for(int i=1;i<=m;++i)
	{
		int x=read(),y=read(),z=read();
		int xx=qt(x,z),yy=qt(y,z);
		in(xx,yy,0);
		in(yy,xx,0);
		in(x,xx,1);
		in(xx,x,1);
		in(y,yy,1);
		in(yy,y,1);
	}
	SPFA(1);
	if(dis[n]>inf)
	{
		puts("-1");
	}
	else
	{
		printf("%d\n",dis[n]/2);
	}
	return 0;
}

Measured memory_bytes: 181376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    map<ll,ll> mp;
    mp[0] = 1;
    ll now = 0;
    rep(i, 0, N){
        ll a;
        cin >> a;
        now += a;
        mp[now]++;
    }
    ll ans = 0;
    for(auto p : mp){
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define NUM 1000000007
#define MAX 100001
#define INF LLONG_MAX
ll dp[2001];
ll dfs(ll sum){
    if(sum==0)
        return 1;
    if(dp[sum]!=-1)
        return dp[sum];
    ll ans = 0;
    for(int i=3;i<=sum;i++){
        if(sum>=i)
            ans+=dfs(sum-i)%NUM;
    }
    return dp[sum]=ans%NUM;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll s;
    cin>>s;
    memset(dp,-1,sizeof(dp));
    ll ans = dfs(s)%NUM;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3664
turn = int(input())

point_taro = point_hanako = 0

for i in range(turn):
    taro,hanako = input().split()

    if taro > hanako:
        point_taro += 3
    elif hanako > taro:
        point_hanako += 3
    else:
        point_taro += 1
        point_hanako += 1

print("{} {}".format(point_taro,point_hanako))


Measured memory_bytes: 5600
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int M = s.nextInt();
		long[] H = new long[N];
		for(int i = 0; i < N; i++) {
			H[i] = s.nextLong();
		}
		Map<Integer, Set<Integer>> map = new HashMap<>();
		int a,b;
		for(int i = 0; i< M; i++) {
			a = s.nextInt();
			b = s.nextInt();
			map.computeIfAbsent(a, set -> new HashSet<>()).add(b);
			map.computeIfAbsent(b, set -> new HashSet<>()).add(a);
		}
		
		int result = 0;
		for(int i = 0; i < N; i++) {
			Iterator<Integer> itr = map.getOrDefault(i + 1, Collections.emptySet()).iterator();
			if(!itr.hasNext()) {
				result++;
			}
			while(itr.hasNext()) {
				if(H[i] <= H[itr.next() - 1]) {
					break;
				}
				if(!itr.hasNext()) {
					result++;
				}
				
			}
		}
		System.out.println(result);
    }
}

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

int main(){
  int a,b;
  int p,m;
  cin >> a >> b;
  p = a * b;
  m = p % 2;
  if (m == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
  string s;
  cin>>s;
  ll len = s.length();
  ll count = 0;
  for(ll i=0;i<len/2;i++){
    if(s[i]!=s[len-i-1]) count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3572