akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
ll h[110000];
ll dp[110000];

int main () {
  cin >> N;
  rep(i, N) {
    cin >> h[i];
    dp[i] = LINF;
  }

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);

  for (int k=3;k<=N;++k) {
    //cout << dp[k-2] << "\n";
    //cout << h[k] - h[k-2] << "\n";
    //cout << dp[k-1] << "\n";
    //cout << h[k] - h[k-1] << "\n";
    chmin(dp[k], dp[k-2] + abs(h[k] - h[k-2]));
    chmin(dp[k], dp[k-1] + abs(h[k] - h[k-1]));
  }

  cout << dp[N] << "\n";

}

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

typedef vector<int> vi ;
typedef pair<int,int> ii ;
typedef pair<ii,int> ill;
typedef tuple<int,int,int> tt;
const int maxN = 1e5+7;
const int INF = 1e18;

int ps[maxN] , pt[maxN];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s , t;
    int q;
    cin >> s >> t;
    pt[0] = ps[0] = 0;
    for(int i = 0 ; i< s.size() ; i++)
      ps[i+1] = ps[i] + ((s[i]=='A') ? 1 : -1);
    for(int i = 0 ; i< t.size() ; i++)
      pt[i+1] = pt[i] + ((t[i]=='A') ? 1 : -1);
    cin >> q;
    while(q--)
    {
        int u , v , l , r;
        cin >> l >> r >> u >> v;
        int cur_s =ps[r] - ps[l-1] ;
        int cur_t = pt[v] -pt[u-1] ;
        if ( cur_s % 3 == -2 ) cur_s = 1;
        if ( cur_s % 3 == -1) cur_s = 2;
        if ( cur_t % 3 == -2 ) cur_t = 1;
        if ( cur_t % 3 == -1) cur_t = 2;
        if ( cur_s %3 == cur_t % 3 )
            cout<<"YES";
        else cout<<"NO";
        cout<<"\n";
    }

    return 0;
}


Measured memory_bytes: 5352
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, k; cin>>n>>k;
    vector<int> h(n);
    loop(n) cin>>h[i];

    vector<ll> dp(n, 9999999999);
    dp[0] = 0;
    for(int i = 0; i<n; i++){
        for(int j = 1; i+j<n && j<=k; j++){
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
        }
    }

    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
map<int,set<int> > m;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int h,w;
bool ok[1111][1111];
bool in(int y,int x){
  return (0<=y&&y<h&&0<=x&&x<w);
}
int main(){ 
  cin>>h>>w;
  int s[h][w];
  priority_queue<PP> q;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
      q.push(PP(-s[i][j],P(i,j)));
    }
  }
  int ans=0;
  int ax[]={1,-1,0,0};
  int ay[]={0,0,1,-1};
  while(!q.empty()){
    PP pp=q.top();q.pop();
    P p=pp.second;
    int t=-pp.first,y=p.first,x=p.second;
    for(int k=0;k<4;k++){
      if(!in(y+ay[k],x+ax[k])) continue;
      int z=s[y+ay[k]][x+ax[k]];
      if(z>t) continue;
      if(m.find(z)!=m.end()){
	if(m[z].size()==1) m[t].insert(*m[z].begin()); 
	else ok[y][x]=1;
      }else m[t].insert(z);
    }
    if(m.find(t)!=m.end()) ok[y][x]|=m[t].size()>1;
    if(ok[y][x]){
      ans++;
      m[t].clear();
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 159768
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    char[] c = s.toCharArray();
    String before = "";
    String After = "";
    
    for(int i=0; i<n/2; i++){
      before += c[i];
    }
    
    for(int i=n/2; i<n; i++){
      After += c[i];
    }
    
    if(before.equals(After)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 22996
/// time is tough.....so don't stop ...keep learning ...keep growing :)

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
const int N = 1e5+5 ;
const int K = 50 ;
const ll mod =  1e9+7 ;
#define pb push_back
#define ft first 
#define sd second 
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll poww(ll a,ll b){ll res=1;while(b){if(b&1){res*=a;}a=a*a;b>>=1;}return res;}
ll poww(ll a,ll b,ll mod){ll res=1;while(b){if(b&1){res*=a;res%=mod;}a=a*a;a%=mod;b>>=1;}return res;}
const int INF = 2e9 ;
int n, m, u, v, k;
ll dp[3005][3005];// pre[105][N];
ll a[3005];
ll f(int i, int j){
    if(i > j) return 0;
    ll &res = dp[i][j] ;
    if(~res) return res;
    if((j - i + 1) % 2 == n % 2) res = max(a[i] + f(i + 1, j), a[j] + f(i, j-1));
    else res = min(f(i + 1, j) - a[i], f(i, j - 1) - a[j]);
    return res;
}
int main(){
    cin >> n ;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
    }
    memset(dp, -1, sizeof dp);
    cout << f(1, n) << '\n';
    return 0;
}
 

Measured memory_bytes: 71040
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    stack<char> st;

    rep(i, n) {
        char c = s[i];
        if (!st.empty()) {
            if (c != st.top()) {
                st.pop();
            }
            else {
                st.push(c);
            }
        }
        else {
            st.push(c);
        }
    }

    cout << n - st.size() << endl;
    return 0;
}

Measured memory_bytes: 512
//https://atcoder.jp/contests/dp/tasks/dp_a
//1d memorization - dp
#include<bits/stdc++.h>
using namespace std;
#define pr printf
#define fi first
#define se second
#define sc(n) scanf("%d",&n)
#define scl(a,b) scanf("%d %d",&a,&b)
#define fo(i,n) for(int i=0;i<n;i++)
#define PR pair<int,pair<int,int>>
#define INF 1e12
long long a[100005],n;
long long dp[100005];
const int N = (int)(1*1e6+10);
long long fib(long long i)
{
    //cout<<i<<endl;
    if(i==(n-1))
        return 0;
    if(i>=n)
        return INT_MAX;

    if(dp[i]!=-1)
        return dp[i];
    long long i1,i2;
    i1=abs(a[i+1]-a[i])+fib(i+1);
    i2=INT_MAX;
    if((i+2)<n)
        i2=abs(a[i+2]-a[i])+fib(i+2);
    dp[i]=min(i1,i2);
    return dp[i];
}
int main()
{
    long long t=1;
    //sc(t);
    while(t--)
    {
        memset(dp,-1,sizeof(dp));// 100005*8
        sc(n);
        fo(i,n)
         {
             sc(a[i]);
         }
        cout<<fib(0)<<endl;








    }

    return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;

namespace Energy_Drink_Collector
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dic = new SortedList<int, int>();
            for (int i = 0; i < nm[0]; i++)
            {
                var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (dic.ContainsKey(input[0]))
                {
                    dic[input[0]] += input[1];
                }
                else { dic[input[0]] = input[1]; }
            }

            var result = 0L;
            int index = 0;
            var key = dic.Keys[index];
            while (0 != nm[1]--)
            {
                if (0 == dic[key]) { key = dic.Keys[++index]; }

                result += key;
                dic[key]--;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 18516
package main

import (
    "fmt"
)

const MOD = 1000000007

func main() {
    var s string
    fmt.Scan(&s)
    
    n := len(s)
    dp := make([][]int, n)
    for i := 0; i < n; i++ {
        dp[i] = make([]int, 13)
    }

    if s[n-1] == '?' {
        for i := 0; i < 13; i++ {
            if i < 10 {
                dp[n-1][i] = 1
            } else {
                dp[n-1][i] = 0
            }
        }
    } else {
        c := int(s[n-1] - '0')
        for i := 0; i < 13; i++ {
            if i == c {
                dp[n-1][i] = 1
            } else {
                dp[n-1][i] = 0
            }
        }
    }
    
    digit := 10
    for i := n - 2; i >= 0; i-- {
        if s[i] == '?' {
            for m := 0; m < 10; m++ {
                for mod, cnt := range dp[i+1] {
                    shifted := (mod + m * digit) % 13
                    dp[i][shifted] += cnt
                }
            }
        } else {
            m := int(s[i] - '0')
            for mod, cnt := range dp[i+1] {
                shifted := (mod + m * digit) % 13
                dp[i][shifted] += cnt
            }
        }
        
        for j := 0; j < 13; j++ {
            dp[i][j] %= MOD
        }
        digit = (digit * 10) % 13
    }

    fmt.Println(dp[0][5])
}

Measured memory_bytes: 14592
#include <bits/stdc++.h> 
using namespace std; 
int main() {
 int c, d; 
  cin >> c >> d; 
  int y = (d-(2*c))/2;
  int x = (d-(4*y))/2; 
  if (((x*2 + 4*y) == d) && (x + y == c) && (x >= 0) && (y >= 0))
    cout << "Yes"; 
  else
    cout << "No"; 
  
}

Measured memory_bytes: 3632
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");

#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << "\n";
    err(++it, args...);
}

typedef long long ll;
typedef long double ld;

void solve(){
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > a(n);
    map<ll, ll> mp;
    for(ll i = 0; i < n; i++){
        cin >> a[i].first;
        a[i].second = i;
        mp[i + 1] = a[i].first;
    }
    vector<int> adj[n + 1];
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    vector<int> vis(n + 1);
    int res = 0;
    sort(a.rbegin(), a.rend());
    for(int i = 1; i <= n; i++){
        int root = a[i - 1].second + 1;
        int flag = 0;
        if(vis[root] == 0){
            vis[root] = 1;
            for(auto u : adj[root]){
                vis[u] = 1;
                if(mp[u] >= mp[root]){
                    flag = 1;
                }
            }
            if(flag == 0){
                res++;
            }
        }
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

ll solve(ll a, ll b) {
  if (a > b) {
    swap(a, b);
  }

  ll ans = 0;
  ll max_cand = a * b - 1;
  ll sq = sqrt((ld)max_cand);

  if (max_cand == 0) {
    return 0;
  }

  ans = 2 * sq;
  if (sq * (sq + 1) > max_cand) {
    ans--;
  }

  ans--;
  ll tmp = max_cand / (max_cand / a);
  if (tmp != a) {
    ans++;
  }

  return ans;
}

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

  ll q;
  cin >> q;
  rep(i, q) {
    ll a, b;
    cin >> a >> b;
    cout << solve(a, b) << endl;
  }

  return 0;
}


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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;

  if (U == S){
    A = A - 1;
  }
  if (U == T){
    B = B - 1;
  }

  cout << A << " " << B << endl;
}

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


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

  int n, a; cin >> n >> a;
  int coin = n % 500;
  if(coin <= a) cout << "Yes" << '\n';
  else cout << "No" << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

struct edge {
    ll to, cost, tim;
    edge(int t, int c, int ti) : to(t), cost(c), tim(ti) {}
};

using pil = pair<int, ll>;
void dijkstra(int s, vector<ll> &d, vector<vector<edge>> &G) {
    priority_queue<pil, vector<pil>, greater<pil>> que;
    fill(All(d), INF);
    d[s] = 0;
    que.push(make_pair(0, s));

    while(!que.empty()) {
        pil p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first)
            continue;
        for(auto e : G[v]) {
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M, S;
    cin >> N >> M >> S;
    vector<vector<edge>> G(N, vector<edge>());
    rep(i, M) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        G[u].pb(edge(v, a, b));
        G[v].pb(edge(u, a, b));
    }
    vector<ll> C(N), D(N);
    rep(i, N) { cin >> C[i] >> D[i]; }

    vector<vector<ll>> dist(N, vector<ll>(3001, LINF));
    using plii = pair<ll, pii>;
    priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>>
        que;
    dist[0][min(S, 3000)] = 0;
    que.push(MP(0, MP(0, min(S, 3000))));
    while(!que.empty()) {
        plii p = que.top();
        que.pop();
        int v = p.second.first;
        int s = p.second.second;
        if(dist[v][s] < p.first)
            continue;
        for(auto e : G[v]) {
            if(s - e.cost >= 0 && dist[e.to][s - e.cost] > dist[v][s] + e.tim) {
                dist[e.to][s - e.cost] = dist[v][s] + e.tim;
                que.push(
                    make_pair(dist[e.to][s - e.cost], MP(e.to, s - e.cost)));
            }
        }
        for(int i = 1; s + i * C[v] <= 3000; i++) {
            if(dist[v][s + i * C[v]] > dist[v][s] + i * D[v]) {
                dist[v][s + i * C[v]] = dist[v][s] + i * D[v];
                que.push(make_pair(dist[v][s + i * C[v]], MP(v, s + i * C[v])));
            }
        }
    }
    for(int i = 1; i < N; i++) {
        ll res = LINF;
        rep(j, 3001) { res = min(dist[i][j], res); }
        cout << res << endl;
    }
    return 0;
}

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


def main():
    q, h, s, d = list(map(int, input().split()))
    n = int(input())

    # See:
    # https://www.youtube.com/watch?v=9OiB8ot3a0w
    x = min(4 * q, h * 2, s)
    print(min(n * x, d * (n // 2) + n % 2 * x))


if __name__ == '__main__':
    main()


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

using namespace std;

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

void run();

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

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

void run(){
    string s;
    cin>>s;
    string t;
    rep(i,s.length()){
        if(i<s.length()-1&&s[i]=='B'&&s[i+1]=='C')t+="D",i++;
        else t+=s[i];
    }
    int ans=0;
    int cnt=0;
    rep(i,t.length()){
        if(t[i]=='A')cnt++;
        else if(t[i]=='D')ans+=cnt;
        else cnt=0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 916
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

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

    int n {};
    cin >> n;
    vector<int> A (n);
    vector<int> B (n);
    vector<int> C (n-1);
    for (auto &val: A) cin >> val;
    for (auto &val: B) cin >> val;
    for (auto &val: C) cin >> val;

    int ans {};
    int prev {INT_MAX};
    for (int i {}; i < n; ++i) {
        ans += B.at(A.at(i) - 1);
        if (A.at(i) - prev == 1) {
            ans += C.at(A.at(i) - 2);
        }
        prev = A.at(i);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin>>x;
	cout<<1-x;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;

int h,w,d,q;
int a[301][301];
ll cost[100000];
map<int,pair<int,int> > mp;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>h>>w>>d;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin>>a[i][j];
        a[i][j]--;
        mp[a[i][j]]=make_pair(i,j);
      }
    }
    for(int i=0;i<h*w;i++){
      if(i-d<0)cost[i]=0;
      else{
        cost[i]=cost[i-d]+abs(mp[i].fi-mp[i-d].fi)+abs(mp[i].se-mp[i-d].se);
      }
    }
    cin>>q;
    for(int i=0;i<q;i++){
      int l,r;cin>>l>>r;
      l--;r--;
      cout<<cost[r]-cost[l]<<endl;
    }
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}

Measured memory_bytes: 7808
#define DigLim  1000000000 //10 digit (10^9)
#include<stdio.h>
int main(){
    int n, a, i=1, j, k, min, max, sum[3]={0};
    max=-1000000; min=-max;
    scanf("%d\n", &n);
    for(;i<=n;i++){
        scanf("%d ", &a);
        if(a>max)max=a;
        if(a<min)min=a;
        if(sum[0]+a>=DigLim){
            sum[0] += a - DigLim;
            sum[1]++;
            if(sum[1]>=DigLim){
                sum[1] -= DigLim;
                sum[2]++;
            }
        }
        else sum[0]+=a;
        if(i>8500 && 0){
            printf("[%d]\ta:<%d>\tmin:%d\tmax:%d\tsum:", i, a, min, max);
            if(sum[2]>0){
                printf("%d", sum[2]);
                j=sum[1];
                for(k=1;j/10>0;k++)j/=10;
                for(j=0;j<9-k;j++)putchar('0');
            }
            if(sum[1]>0){
                printf("%d", sum[1]);
                j=sum[0];
                for(k=1;j/10>0;k++)j/=10;
                for(j=0;j<9-k;j++)putchar('0');
            }
            printf("%d\n", sum[0]);
        }
    }
    
    
    printf("%d %d ", min, max);
    if(sum[2]>0){
        printf("%d", sum[2]);
        j=sum[1];
        for(k=1;j/10>0;k++)j/=10;
        for(j=0;j<9-k;j++)putchar('0');
    }
    if(sum[1]>0){
        printf("%d", sum[1]);
        j=sum[0];
        for(k=1;j/10>0;k++)j/=10;
        for(j=0;j<9-k;j++)putchar('0');
    }
    printf("%d\n", sum[0]);
    return 0;
}


Measured memory_bytes: 2704
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    V<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    V< V<int> > edges(n);
    for (int i = 1; i < n; i++) edges[a[i]].emplace_back(i);
    
    int ans = 0;
    auto dfs = [&](auto && self, int i) -> int {
        int d = 0;
        for (int e: edges[i]) {
            int chd = self(self, e);
            if (chd == k && i != 0) ans++;
            else chmax(d, chd);
        }
        return d + 1;
    };
    dfs(dfs, 0);
    if (a[0] != 0) ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 15304
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<vector>
using namespace std;
template<typename T>void scan(T &x)
{
	char ch;
	bool f=1;
	x=0;
	ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') f=0,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(f==0) x=-x; 
}
int l,n,m,ans;
double tot,now=0x7fffffff;
int main()
{
	scan(l),scan(n),scan(m);
	for(register int i=1;i<=l;i++)
	{
		int x;
		scan(x);
		tot=n-x*0.006;
		//cout<<tot<<endl;
		if(abs(tot-m)<now) ans=i,now=abs(tot-m);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        if(a % 2 == 1) continue;
        if(a % 3 == 0 || a % 5 == 0) continue;
        cout << "DENIED" << endl;
        return 0;
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 3668
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int[] dx = new int[] { 0, 0, 1, -1 };
    static int[] dy = new int[] { 1, -1, 0, 0 };

    static void Solve()
    {
        int a = sc.Int();
        int b = sc.Int();
        int c = sc.Int();

        if (a + b >= c)
            pr.WriteLine("Yes");
        else
            pr.WriteLine("No");
    }

    class Node {
        public Node Prev;
        public Node[] To;

        public int cost;
    }

    static double F(double prev, double next, double t)
    {
        return Math.Pow(Math.Exp((next - prev) / t), 2);
    }

    static int[,] Mul(int[,] a, int[,] b)
    {
        var ret = new int[a.GetLength(0), b.GetLength(1)];
        for (int i = 0; i < a.GetLength(0); i++)
            for (int j = 0; j < b.GetLength(1); j++)
                for (int k = 0; k < a.GetLength(1); k++)
                    ret[i, j] += a[i, k] * b[k, j];

        return ret;
    }

    static int[,] Pow(int[,] a, int n)
    {
        var b = new int[a.GetLength(1), a.GetLength(0)];

        var f = n % 2 == 1;

        for (int i = 0; i < a.GetLength(0); i++)
            b[i, i] = 1;

        while (n > 0)
        {
            if (n % 2 == 1)
                b = Mul(a, b);


            n >>= 1;
        }

        return b;
    }

    class Coord
    {
        public int x;
        public int y;
    }

    static void Main(string[] args)
    {
        // pr.AutoFlush = true;
        Solve();
        pr.Flush();
        // Console.ReadKey();
    }

    static Scanner sc = new Scanner();
    static Printer pr = new Printer();
}

#region IO
class Scanner
{
    private int _i = 0;
    private string[] line = new string[0];

    private T[] Enumerate<T>(int n, Func<T> f)
    {
        T[] ret = new T[n];
        for (int i = 0; i < n; i++)
            ret[i] = f();
        return ret;
    }

    public string Str()
    {
        if (line.Length <= _i)
        {
            line = Console.ReadLine().Split(' ');
            _i = 0;
        }

        return line[_i++];
    }

    public int Int() => int.Parse(Str());
    public long Long() => long.Parse(Str());
    public double Double() => double.Parse(Str());
    public int[] Int(int n) => Enumerate(n, Int);
    public long[] Long(int n) => Enumerate(n, Long);
    public double[] Double(int n) => Enumerate(n, Double);
    public string[] Str(int n) => Enumerate(n, Str);
}

class Printer : StreamWriter
{
    public Printer() : base(Console.OpenStandardOutput())
    {
        AutoFlush = false;
    }
}
#endregion

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
        int M = int.Parse(Console.ReadLine());

        var drinks = 
            Enumerable.Repeat(0, M).Select(n => Console.ReadLine().Split(' ').ToArray())
            .Select(itm => new { P = int.Parse(itm[0]), X = int.Parse(itm[1]) }).ToArray();

        var normalTotal = T.Sum();

        foreach(var drink in drinks)
        {
            Console.WriteLine(normalTotal + drink.X - T[drink.P - 1]);
        }
    }
}

Measured memory_bytes: 13524
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    ll n;
    cin>>n;
    vector<ll> v;
    rep(i,5){
        ll a;
        cin>>a;
        v.push_back(a);
    }

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

    ll aa=n/v[0]+4;
    if(n%v[0]!=0)aa++;

    cout<<aa<<endl;

    return 0;
}


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

namespace ITP1_3_B_PrintTestCases
{
    class Program
    {
        static void Main(string[] args)
        {
            ReadAll()
                .ToList()
                .Select((data, index) =>
                    String.Format("Case {0}: {1}", index + 1, data)
                )
                .ForEach(x => Console.WriteLine(x));
        }


        static IEnumerable<string> ReadAll()
        {
            string input;
            while((input = Console.ReadLine()) != "0")
            {
                yield return input;
            }
        }

    }


    static public class Ext
    {
        static public void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach(var item in source)
            {
                action(item);
            }
        }
    }
}

Measured memory_bytes: 6696
#include<stdio.h>

typedef struct{
  char suit;
  int number;
}Card;


void print(int N,Card A[]){
  for(int i = 0; i < N; i++){
    if(i < (N - 1) ){
      printf("%c%d ",A[i].suit,A[i].number);
    }else{
      printf("%c%d",A[i].suit,A[i].number);
    }
  }
  putchar('\n');
}


void bubble(int N,Card A[]){
  int flag = 1;
  while(flag==1){
    flag = 0;
    for(int j = N - 1; j > 0; j--){
      if(A[j].number < A[j - 1].number){
        Card temp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = temp;
        flag = 1;
      }
    }
  }
}

void selection(int N,Card A[]){
  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j].number < A[minj].number){
        minj = j;
      }
    }
    Card temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
  }
}

int isStable(Card C1[],Card C2[],int N){
  for(int i = 0; i < N; i++){
    if(C1[i].suit != C2[i].suit)return 0;
  }
  return 1;
}

int main(){
  Card C1[100],C2[100];
  int n;
  scanf("%d",&n);

  for(int i = 0; i < n; i++){
    scanf(" %c%d",&C1[i].suit ,&C1[i].number);//前に空白を入れないと読み込みがおかしくなる
  }
  
  for(int i = 0; i < n; i++){
    C2[i] = C1[i];
  }
  

  bubble(n,C1);
  selection(n,C2);

  print(n,C1);
  printf("Stable\n");

  print(n,C2);
  if(isStable(C1,C2,n)){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

}



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

vector<int> to[200005];
vector<int> res;

void dfs(int v, int p=-1) {
  for (auto nv : to[v]) {
    if (nv==p) continue;
    res[nv]+=res[v];
    dfs(nv, v);
  }
}


int main() {
  int n,q; cin>>n>>q;
  rep(i, n-1) {
    int a,b; cin>>a>>b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  res.resize(n, 0);
  rep(i, q) {
    int p,x; cin>>p>>x;
    p--;
    res[p]+=x;
  }
  dfs(0);
  rep(i, n) {
    if (i) cout<<" ";
    cout<<res[i];
  }
  cout<<endl;
}


Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s,ss;
ll ar[100009];
ll br[100009];
vector<char>v;
char ch;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n,ans,res,i,j,c=0,f=0,len1,len2,mx=0,m;
    double a,b;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>ar[i];
        if(i==0)continue;
       else if(ar[i-1]>=ar[i])c++;
        else {
           mx=max(c,mx);
            c=0;

        }
    }
    cout<<max(c,mx)<<endl;
   return 0;

}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
LL H[MAX];

LL w_H[MAX];
bool check(bool f) {
    REP(i, MAX) w_H[i] = H[i];

    if (f) w_H[0]--;
    REP(i, N - 1) {
        if (w_H[i] <= w_H[i + 1] - 1) {
            w_H[i + 1]--;
        }
    }

    REP(i, N - 1) if (w_H[i] > w_H[i + 1]) return false;
    return true;
}

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> H[i];
    }

    if (check(false) || check(true)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
    int r, d, xt;
    cin >> r >> d >> xt;
    int a[11];
    a[0] = xt;
    for(int i=0;i<10;i++){
        a[i+1] = (r*a[i]) - d;
        cout << a[i+1] << 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);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];
        long ans = 0;
        for (int i=0;i<=n;i++)a[i]=sc.nextInt();
        for (int i=0;i<n;i++)b[i]=sc.nextInt();
        for (int i=0;i<n;i++){
            int def1 = a[i];
            int def2 = a[i+1];
            a[i] = Math.max(0,a[i]-b[i]);
            a[i+1] = Math.max(0,Math.min(a[i+1],a[i+1]+def1-b[i]));
            ans+=def1-a[i]+def2-a[i+1];
        }
        System.out.println(ans);

    }
}


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

long long L, R;
long long dp[65][2][2][2][2];
long long mod = 1000000007;

long long solve(int pos, int bit1, int gir1, int gir2, int gir3) {
	// pos : 現在の桁数
	// bit1 : 大きい方の前のビット
	// gir1 : x がギリギリかどうか
	// gir2 : y がギリギリかどうか
	// gir3 : y <= 2x がギリギリかどうか

	if (pos == -1) {
		if (bit1 == 1 && gir3 == 1) return 0;
		return 1;
	}
	if (dp[pos][bit1][gir1][gir2][gir3] >= 1) return dp[pos][bit1][gir1][gir2][gir3] - 1LL;

	long long ret = 0;

	// ケース 1 : 両方 0 にするパターン
	if ((gir1 == 0 || (L & (1LL << pos)) == 0) && (gir3 == 0 || bit1 == 0)) {
		long long c1 = pos - 1;
		long long c2 = 0;
		long long c3 = gir1;
		long long c4 = gir2; if ((R & (1LL << pos)) != 0) c4 = 0;
		long long c5 = gir3;
		ret += solve(c1, c2, c3, c4, c5);
		ret %= mod;
	}

	// ケース 1 : 両方 1 にするパターン
	if ((gir2 == 0 || (R & (1LL << pos)) != 0)) {
		long long c1 = pos - 1;
		long long c2 = 1;
		long long c3 = gir1; if ((L & (1LL << pos)) == 0) c3 = 0;
		long long c4 = gir2;
		long long c5 = gir3; if (bit1 == 0) c5 = 0;
		ret += solve(c1, c2, c3, c4, c5);
		ret %= mod;
	}

	// ケース 3 : 小さい方を 0、大きい方を 1 にするパターン
	if ((gir1 == 0 || (L & (1LL << pos)) == 0) && (gir2 == 0 || (R & (1LL << pos)) != 0) && (gir3 == 0 || bit1 == 0)) {
		long long c1 = pos - 1;
		long long c2 = 1;
		long long c3 = gir1;
		long long c4 = gir2;
		long long c5 = gir3;
		ret += solve(c1, c2, c3, c4, c5);
		ret %= mod;
	}

	dp[pos][bit1][gir1][gir2][gir3] = ret + 1;
	return ret;
}

int main() {
	cin >> L >> R;
	long long ans = solve(60, 0, 1, 1, 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left, bisect

def query_max(bit, idx):
    max_val = 0
    while idx > 0:
        max_val = max(max_val, bit[idx])
        idx -= idx & -idx
    return max_val


def insert_max(bit, idx, value):
    """
    replace a[idx] with value.
    """
    while idx <= len(bit):
        bit[idx] = max(bit[idx], value)
        idx += idx & -idx


fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
A_list = sorted(int(elem) for elem in fin().split())
# A_bit = [0] * (4 * N)
# for i, A in enumerate(A_list, start=1):
#     insert_max(A_bit, i, A)

operations = [[int(elem) for elem in fin().split()] for _ in range(M)]
operations.sort(key=lambda x: (-x[1], -x[0]))
# operations.sort(key=lambda x: x[1])

unexchanged_idx = 0
for num_possible_exchanges, num in operations:
    while num_possible_exchanges and unexchanged_idx < N and A_list[unexchanged_idx] < num:
        A_list[unexchanged_idx] = num
        unexchanged_idx += 1
        num_possible_exchanges -= 1
print(sum(A_list))


Measured memory_bytes: 75072
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : September 13, 2020 6:00 PM
 *    Problem Name  : B - Product Max
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc178/tasks/abc178_b
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

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

    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll mx1 = a*c;
    ll mx2 = a*d;
    ll mx3 = b*c;
    ll mx4 = b*d;

    cout << max({mx1,mx2,mx3,mx4}) << endl;

    return 0 ;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
    if (!a) {*x = 0; *y = 1; return b;}
    ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd;
}
ll modI(ll b, ll m)      {ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m;}
typedef pair<ll, ll>      pii;
typedef vector<ll>         vi;
typedef vector<pii>         vii;
typedef set<ll>            si;
typedef map<string, ll>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(i,b,n)           for(ll i=b;i<n;i++)
#define loopv(i,b,n,a)         for(ll i=b;i<n;i+=a)
#define loopr(i,b,n)           for(ll i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() ll begtime = clock();
#define end_routine() ll endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(ll)(MOD+((a%MOD)-(b%MOD))%MOD):(ll)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (ll)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}

#define test int t;cin >>t;while(t--)
void solve()
{
    ll n;
    ll ans = 0;
    ll x, y;
    cin >> x >> y;
    if (y <= 4 * x && y >= 2 * x && y % 2 == 0)
        cout << "Yes";
    else

        cout << "No" << "\n";
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std ; 
const int inf = 1012345678;

int main(){
  int N = 5 ;  
  vector<int> A(N) ;  
  
  for(int i = 0 ; i < N ; i++){
    cin >> A.at(i) ;
  }
  
  vector<int> P = {0 , 1 , 2 , 3 , 4 } ; 
  int final_answer = inf ; 
  
do { 
  int ans= 0 ; 
  
  for(int i = 0 ; i < N ; i++){
    while( ans% 10 != 0 ) ans++ ; 
    ans += A.at(P.at(i)) ; 
  }
  
  final_answer = min(final_answer , ans) ;
} while (next_permutation(P.begin() , P.end())) ; 
  
  cout << final_answer << endl ; 
      
  
}

Measured memory_bytes: 3620
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int MAXN=105;
LL n,a,b,c,d;

int main(){
    while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&d)==5){
        bool flag=false;
        for(int i=0;i<=n-1;i++){
            if(c*(n-1-i)-d*i<=b-a&&(n-1-i)*d-c*i>=b-a){
                flag=true;
                break;
            }
        }
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int a,b,kumachan=0;
    cin>>a>>b;
    for(int i=a; i<=b; i++){
        string s=to_string(i);
        int cool_kumachan=0;
        for(int j=0; j<s.size(); j++){
            if(s[j]==s[s.size()-1-j]){
    
            cool_kumachan++;
            }
        }
    if(cool_kumachan==s.size()){
        kumachan++;
    }
    
}
cout<<kumachan<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[105];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	cout<<(*max_element(a,a+n))-(*min_element(a,a+n))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a_i = 0, b_i = 0, c_i = 0, i, next = 0, flag;
  char s[3][101];
  for (i = 0; i < 3; i++){
    scanf("%s", s[i]);
  }
  
  while(1){
    if(next == 0){
      if(s[0][a_i] == '\0'){
        flag = 0;
        break;
      }
      next = s[0][a_i++] - 'a';
    } else if(next == 1){
      if(s[1][b_i] == '\0'){
        flag = 1;
        break;
      }
      next = s[1][b_i++] - 'a';
    } else if(next == 2){
      if(s[2][c_i] == '\0'){
        flag = 2;
        break;
      }
      next = s[2][c_i++] - 'a';
    }
  }
  
  if(flag == 0){
    printf("A\n");
  } else if(flag == 1){
    printf("B\n");
  } else {
    printf("C\n");
  }
  
  return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

template <typename T> T gcd(T a, T b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

template <typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a = a - 1;

    ll e = lcm(c, d);
    ll f = b / c + b / d - b / e;
    ll x = b - f;
    ll g = a / c + a / d - a / e;
    ll y = a - g;

    cout << (x - y) << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fu(a,b) for(int i=a;i<b;i++)
#define fv(a,b) for(int j=a;j<b;j++)
#define ll long long
#define dl double
const ll INF= 1e18L+5;

using namespace std;
/*
3 8
3 30
4 50
5 60
*/

void min_s(int& a,int b)
{
	a=min(a,b);
}
void max_s(int& a,int b)
{
	a=max(a,b);
}

int main()
{
	int n,W;
	cin>>n>>W;
	int w[n+1];
	int val[n+1];
	
	ll sum=0;
	fu(1,n+1)
	{
		cin>>w[i]>>val[i];
		sum+=val[i];
	}
	int dp[sum+1];
	fu(0,sum+1)
	dp[i]=1e9+5;
	dp[0]=0;
	fu(1,n+1)
	{
		for(int j=sum-val[i];j>=0;--j)
		{
			min_s(dp[j+val[i]],dp[j]+w[i]);
		}
	}
	int x=0;
	fu(0,sum+1)
	{
		if(dp[i]<=W)
		{
			max_s(x,i);
		}
	}
	cout<<x;
}
/*
4 10
5 10
4 40
6 30
3 50
*/

Measured memory_bytes: 640
N, Y = map(int, input().split(" "))

s1, s2, s3 = 10, 5, 1
ok_flg = False

if Y % 1000 != 0 :
    print("-1 -1 -1")    
else :
    y_small = int(Y / 1000)
    for i in range(N + 1) :
        if y_small - i * s1 <= (N - i) * s2 :
            for j in range(N - i + 1) :
                if i + j <= N and i*s1 + j*s2 + (N - i - j)*s3 == y_small :
                    print(i, j, N - i - j)
                    ok_flg = True
                    break
                if ok_flg == True :
                    break
            if ok_flg == True :
                break
    if ok_flg == False :
        print("-1 -1 -1")

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

int n, m;
vector<int> s;
vector<int> p;

int dfs(int cur, int stat)
{
    if(cur==n)
    {
        rep(i,m)
        {
            int x = stat & s[i];
            int cnt = 0;
            while(x>0)
            {
                cnt += (x&1);
                x >>= 1;
            }

            if(cnt%2 != p[i]) return 0;
        }
        return 1;
    }

    return dfs(cur+1,stat) + dfs(cur+1,(stat|(1<<cur)));
}

int main()
{
    cin >> n >> m;
    s.assign(m,0);
    rep(i,m)
    {
        int k;
        cin >> k;
        rep(j,k)
        {
            int sj;
            cin >> sj;
            s[i] |= 1<<(sj-1);
        }
    }
    p.resize(m);
    rep(i,m) cin >> p[i];

    cout << dfs(0,0) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
using namespace std;
int  gcd(int a, int b) {
	if (a < b) gcd(b, a);
	int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a, a + 4);
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 892