akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vdouble = vector<double>;

int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}



int main(){
	ll N,sum=0;
	cin>>N;
	int A[10][10];
	REP(i,10){
	    REP(j,10){
	        A[i][j]=0;
	    }
	}
	
	REP(i,N){
		ll H,T;;
		//cout<<pow(10,(int)log10(i+1))<<endl;
		H=(i+1)/pow(10,(int)log10(i+1));
		T=(i+1)%10;
		//cout<<(i+1)<<":"<<H<<":"<<T<<endl;
		A[H][T]++;
	}
	
	REP(i,10){
		REP(j,10){
			sum+=A[i][j]*A[j][i];
		}
	}
	
	cout<<sum<<endl;
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, a;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a;
	cout << n * n - a << "\n";
	return 0;
}

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

using namespace std;

#define int long long
#define f(i, n) for(ll i=0;i<n;i++)
#define fr(i, n) for(ll i=n-1;i>=0;i--)
#define fa(i, a, n) for(ll i=a;i<n;i++)
#define fra(i, a, n) for(ll i=a-1;i>=n;i--)
#define MOD 998244353
#define pb push_back
#define lb lower_bound
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<long long> vi;
typedef pair<ll, ll> pii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<int, vi> miv;

class Solution {
public:
    void pre() {}

    bool ispal(string s) {
        //cout << s << endl;
        string t = s;
        reverse(all(t));
        if (s == t)return true;
        return false;
    }

    void solve() {
        string s;
        cin >> s;
        int n = s.length();
        string a = s.substr(0, (n - 1) /2);
        string b = s.substr(((n + 3)/ 2) - 1);
        if (ispal(a) && ispal(b) && ispal(s)) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
};

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    Solution solver;
    //solver.pre();
    for (int i = 0; i < t; i++) {
        //cout << "Case #" << i + 1 << ": ";
        solver.solve();
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans = [-1 for i in range(n)]
    for i in range(n):
        c = n//(n-i)
        if c<2:
            if a[n-1-i] == 1:
                ans[n-1-i] = 1
            else:
                ans[n-1-i] = 0
        else:
            s = 0
            for j in range(2,c+1):
                s += ans[j*(n-i)-1]
            ans[n-i-1] = (s+a[n-1-i])%2 
    a = []
    for i in range(n):
        if ans[i] == 1:
            a.append(i+1)
    if len(a)==0:
        print(0)
    else:
        print(len(a))
        print(' '.join(list(map(str,a))))

if __name__ == "__main__":
    main()


Measured memory_bytes: 25208
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; ll k; cin >> n >> k;
    VL a(n + 1);
    eFOR(i, 1, n) {
        cin >> a[i];
        (--a[i] += a[i - 1]) %= k;
    }

    unordered_map<ll, ll> cnt;
    ll ans = 0;
    int itr = 0;
    eFOR(i, 0, n) {
        --cnt[a[i]];
        while (itr <= n && itr < i + k)++cnt[a[itr++]];
        ans += cnt[a[i]];
    }

    cout << ans << "\n";

}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int A, B;
  cin >> A >> B;
  if (A <= 5) {
    B = 0;
  } else if (A<13) {
    B /= 2;
  }

  cout << B << endl;

  return 0;
}


Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
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 factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b 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 bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
  
n=inp[0]
a = inp
p a.max - a.min

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;


int main() {
    while (true) {
        ll n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) return 0;
        vector<ll> cs(m);
        rep(i, m) cin >> cs[i];
        vector<ll> xs(n);
        rep(i, n) cin >> xs[i];

        vector<vector<ll>> dp(n + 1, vector<ll>(256, INF));
        dp[0][128] = 0;
        rep(i, n) {
            rep(j, 256) {
                if (dp[i][j] == INF) continue;
                rep(a, m) {
                    int diff = cs[a];
                    int next = max(0, min(255, (int)j + diff));
                    ll dx = next - xs[i];
                    dx *= dx;
                    dp[i + 1][next] = min(dp[i + 1][next], dx + dp[i][j]);
                }
            }
        }
        ll u = INF;
        rep(j, 256) {
            u = min(u, dp[n][j]);
        }
        cout << u << endl;
    }
    return 0;
}


Measured memory_bytes: 43680
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll pwr[10000005];

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n;
	string s;
	cin >> s;

	i=0;j=n-1,x=0;

	while(j>=0 && s[j]!='R')j--;

	while(i<sz(s))
	{
		if(s[i]=='W' && j>i)
		{
			x++;
			swap(s[i],s[j]);
			while(j>=0 && s[j]!='R')j--;
		}
		i++;
	}
	cout<<x<<endl;
}

Measured memory_bytes: 3768
a,b,c,x,y=map(int,input().split())

mi=min([x,y])
ma=max([x,y])
g=ma-mi
ans,ab=0,0


if 2*c <= a+b:
  if x>=y:
    ans+=2*c*y + (x-y)*a
    ab=2*c*x
  else:
    ans+=2*c*x + (y-x)*b
    ab=2*c*y
else:
  ans+=a*x+b*y

if ab >= ans: 
  print(ans)
else:
  if ab!=0:
    print(ab)
  else:
    print(ans)
  

Measured memory_bytes: 9112
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static char buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10+'0';
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n;
int main()
{
    n=read();
    int cnt=0;
    for(int i=1;i<=n;i++){
        a[i]=read();
        cnt+=a[i]!=i;
    }
    puts(cnt<=2?"YES":"NO");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int N;
    cin >> N;
    int V[N], C[N];
    for (int i=0; i<N; i++) {
        cin >> V[i];
    }
    for (int i=0; i<N; i++) {
        cin >> C[i];
    }
    
    int ans=0;
    for (int i=0; i<N; i++) {
        if (V[i]-C[i]>0) {
            ans+=V[i]-C[i];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
signed main(){
    fast();
    int n;
    cin >> n;
    int num = 1000*ceil(1.0*n/1000);
    cout << num-n << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  string s;
  cin >> s;

  int mi = 1e9;
  for (int i = 0; i < s.length() - 2; ++i) {
    string t = s.substr(i, 3);
    int j = stoi(t);
    mi = min(mi, abs(753 - j));
  }
  p(mi);
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
typedef long long ll;

int main(){
  char x,y;
  cin >> x >> y;
  if(x<y)cout << "<" << endl;
  else if(x>y)cout << ">" << endl;
  else cout<< "=" << endl;
}


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

int main(){
  int N;
  cin >> N;
  map<string,int>M;
  rep(i,N){
    string x;
    cin >> x;
    M[x]=1;
  }
  cout << M.size() << endl;
    

}

Measured memory_bytes: 19228
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;

signed main(){
    int d,g;
    cin>>d>>g;
    pair<int,int> p[10];
    for(int i=0;i<d;i++){
        cin>>p[i].first>>p[i].second;
    }
    int ans=114514;
    for(int bit=0;bit<(1<<d);bit++){
        int c=0;
        int sum=0;
        bool canuse[10]={};
        for(int i=0;i<d;i++){
            if(bit&(1<<i)){
                sum+=p[i].first*(i+1)*100+p[i].second;
                c+=p[i].first;
                canuse[i]=false;
            }else{
                canuse[i]=true;
            }
        }
        int now=d-1;
        while(g-sum>0&&now>=0){
            if(canuse[now]==false){
                now--;
                continue;
            }
            if(sum+(p[now].first-1)*(now+1)*100<g){
                c+=p[now].first-1;
                sum+=(p[now].first-1)*(now+1)*100;
                now--;
                //if(now==-1){
                  //  c=114514;
                    //break;
                //}
            }else{
                c+=(g-sum+(now+1)*100-1)/((now+1)*100);
                sum+=(g-sum+(now+1)*100-1)/((now+1)*100)*((now+1)*100);
                break;
            }
        }
        if(sum>=g){
            ans=min(ans,c);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long value_type; //ここをint -> doubleなどと変更すればよい

long long A[100001],C[100001];
int B[100001],F[100001];

value_type med3(value_type x,value_type y,value_type z) {
  if (x < y) {
    if (y < z) {
      return y;
    } else if (z < x) {
      return x;
    } else {
      return z;
    }
  } else {
    if (z < y) {
      return y;
    } else if (x < z) {
      return x;
    } else {
      return z;
    }
  }
}

void quicksort(value_type a[], int f[], int l, int r) {
  if (l < r) {
    int i=l,j=r,tmp2;
    value_type tmp,pivot = med3(a[i], a[(i+j)/2], a[j]);
    while (1) {
      while (a[i] < pivot) {
        i++;
      }
      while (pivot < a[j]) {
        j--;
      }
      if (i>=j) {
        break;
      }
      tmp=a[i];
      a[i]=a[j];
      a[j]=tmp;
      tmp2=f[i];
      f[i]=f[j];
      f[j]=tmp2;
      i++;
      j--;
    }
    quicksort(a, f, l, i-1);
    quicksort(a, f, j+1, r);
  }
}

int main(){
  int i,N,M,t=0,u=0,v=0;
  long long S=0;
  cin >> N >> M;
  for (i=0;i<N;++i) {
    cin >> A[i];
    A[i] *= -1;
  }
  sort(A,A+N);
  for (i=0;i<M;++i) {
    cin >> B[i] >> C[i];
    C[i] *= -1;
    F[i]=i;
  }
  quicksort(C, F, 0, M-1);
  while (t<N) {
    if (A[u]<C[v] || v == M) {
      S-=A[u];
      u++;
      t++;
      continue;
    } else {
      if (B[F[v]]+t > N) {
        S-=C[v] * (N-t);
        t+=B[F[v]];
      } else {
        S-=C[v] * B[F[v]];
        t+=B[F[v]];
        v++;
      }
    }
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin >> n;
	n++;
	deque<int> ans;
	int cur=1;
	for (int i=62-__builtin_clzll(n);i>=0;i--)
	{
		ans.insert(ans.begin()+ans.size()/2,cur);
		ans.push_front(cur);
		cur++;
		if (n&(1LL<<i))
		{
			ans.push_front(cur);
			ans.push_back(cur);
			cur++;
		}
	}
	printf("%d\n",ans.size());
	for (int i:ans)
	printf("%d ",i);
}

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

vector<int> graph[200010];
vector<int> ans;

void dfs(int v, int p=-1) {
  for(int u: graph[v]) {
    if(u == p) continue;
    else {
      ans[u] += ans[v];
      dfs(u, v);
    }
  }
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, Q; cin >> N >> Q;
  for(int i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b; a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  ans.resize(N);
  for(int i = 0; i < Q; i++) {
    int q, x; cin >> q >> x; q--;
    ans[q] += x;
  }

  dfs(0);

  for(int i = 0; i < N; i++) {
    cout << ans[i];
    if(i != N-1) cout << " ";
    else cout << endl;
  }
  return 0;
}


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

int main() {
    long long n;
    cin >> n;
    long long t[n], a[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i] >> a[i];
    }
    long lt = 1, la = 1;
    for (int i = 0; i < n; i++) {
        long long k = max((lt + t[i] - 1) / t[i], (la + a[i] - 1) / a[i]);
        lt = k * t[i];
        la = k * a[i];
    }
    cout << lt + la << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int b[99];
	rep(i,n-1) scanf("%d",b+i);

	int ans=b[0]+b[n-2];
	rep(i,n-2) ans+=min(b[i],b[i+1]);
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fast_io {cin.sync_with_stdio(0); cout.sync_with_stdio(0);}
#define out(x,y) {cout<<x<<y;}
using ll = int;
using pa = pair<ll,ll>;
using vll = deque<ll>;
using vvll = vector<vll>;

ll a[50],b[50],c[50],d[50];
ll ans = 0;
ll n,m,q;

vvll rest;

void give(ll start,ll len){
	vvll final;
	if(len==0)return;
	for(ll j=start;j<=m;j++){
		give(j,len-1);
		if(rest.empty() && len==1){
			vll v;
			v.push_back(j);
			final.push_back(v);
			continue;
		}
		for(ll i=0;i<rest.size();i++){
			rest[i].push_front(j);
			final.push_back(rest[i]);
		}
		rest.clear();
	}
	for(ll i=0;i<final.size();i++){
		rest.push_back(final[i]);
	}
}

int main(){
	fast_io;
	cin>>n>>m>>q;
	for(ll i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--; b[i]--;
	}
	give(1,n);
	for(ll i=0;i<rest.size();i++){
		vll v = rest[i];
		ll sum = 0;
		for(ll j=0;j<q;j++){
			if(v[b[j]]-v[a[j]]==c[j])sum+=d[j];
		}
		ans = max(ans,sum);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 130940
<?php
  $str = trim(fgets(STDIN));
  $num = trim(fgets(STDIN));
  $check = "";
  for($i = 0; $i < $num; $i++) {
    $d = explode(" ", trim(fgets(STDIN)));
    if ($d[0] == "print") {
      if ($check == "break") {
        print "\n";
      }
      print(substr($str, $d[1], ($d[2]-$d[1]+1)));
      $check = "break";
    } else if ($d[0] == "reverse") {

      $x = substr($str, $d[1], ($d[2]-$d[1]+1));
      $y = strrev($x);
      $str = str_replace($x, $y, $str);
    } else if ($d[0] == "replace") {

      $str = substr_replace($str, $d[3], $d[1], ($d[2]-$d[1]+1));
    }
  }
?>

Measured memory_bytes: 6640
main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- (map read . words) <$> getLine :: IO [Int]
  let mul4 = length $ filter (\a -> a `mod` 4 == 0) as
      mul2 = length $ filter (\a -> a `mod` 2 == 0 && a `mod` 4 /= 0) as
  putStrLn $ if (n - 2 * mul4 - 1 <= 0) || (mul4 == 0 && n == mul2) || (n - 2 * mul4 - mul2 <= 0)
              then "Yes"
              else "No"


Measured memory_bytes: 33148
#include <iostream>
#include <queue>
using namespace std;
int main(){
	int n, q;
	int left, mid, right;
	int cnt = 0;
	cin >> n;
	int A[n];
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	cin >> q;
	int B[q];	
	for(int i = 0; i < q; i++){
		cin >> B[i];
		left = 0;
		right = n - 1;
		mid = (n-1)/2;
		while(left != right){
			if(left == right-1){
				if(B[i] == A[right] || B[i] == A[left])
					cnt++;
				break;
			}
			else if(B[i] == A[mid]){
				cnt++;
				break;
			}else if(B[i] > A[mid]){
				left = mid;
				mid = left + (right-left)/2;
			}else if(B[i] < A[mid]){
				right = mid;
				mid = left + (right-left)/2;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3604
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    writeln(readln.chomp.group.canFind!"a[1] >= 3" ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    ll ans = 700;
    REP(i, S.length()) {
        if(S[i] == 'o') { ans += 100; }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <functional>

using namespace std;

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

    vector<set<int>> E(N);
    vector<set<int>> R(N);

    for (int i=0; i<N+M-1; i++)
    {
        int A, B;
        cin>>A>>B;
        E[A-1].insert(B-1);
        R[B-1].insert(A-1);
    }

    int root;
    for (int i=0; i<N; i++)
        if (R[i].size()==0)
            root = i;

    vector<int> ans(N);
    set<int> A;

    function<void(int, int)> f = [&](int c, int p)
    {
        //cout<<c<<" "<<p<<endl;

        ans[c] = p;

        A.clear();
        for (int e: E[c])
            if ((int)R[e].size() > 1)
            {
                //cout<<e<<endl;
                A.insert(e);
                R[e].erase(c);
            }
        for (int a: A)
            E[c].erase(a);

        //cout<<"--"<<endl;
        //for (int a: A)
        //    cout<<a<<endl;

        for (int e: E[c])
            if (A.count(e)==0)
                f(e, c);
    };

    f(root, -1);
    for (int i=0; i<N; i++)
        cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 24704
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    ll k,s,c=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(s-i-j>=0 && s-i-j<=k) c++;
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 234566;
int a[maxn], n;
bool check(int m){
	struct interval { int l, r, v; };
	vector<interval> in;
       	in.push_back({0, a[0], 0});
	for(int i = 1; i < n; i++){
		if(a[i] > a[i - 1]){
			in.push_back({a[i - 1], a[i], 0});
			continue;
		}
		while(!in.empty() && in.back().l >= a[i]) in.pop_back();
	       	in.back().r = a[i];	
		while(!in.empty() && in.back().v == m - 1) in.pop_back();
		if(in.empty()) return false;
		interval cur = in.back(); in.pop_back();
		if(cur.l != cur.r - 1) in.push_back({cur.l, cur.r - 1, cur.v});
		in.push_back({cur.r - 1, cur.r, cur.v + 1});
	    	if(cur.r != a[i]) in.push_back({cur.r, a[i], 0});
	}
	return true;
}
int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int lo = 1, hi = 3 * n, ans = 0;
	while(lo <= hi){
		int mid = (lo + hi)>>1;
		if(check(mid)) hi = mid - 1, ans = mid;
		else lo = mid + 1;
	}
	return !printf("%d\n", ans);
}


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

int main()
{
    int n;
    cin>>n;
    int i,t;
    int a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>t;
        a[t]=i;
    }
    for(i=1;i<=n;i++)
        cout<<a[i]<<" ";
    return 0;
}



Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>

using namespace std;

int main ()
{
    long long n;
    scanf ("%lld", &n);

    long long cn = n;
    int sum = 0, nr = 0, lst;

    for (; cn > 0; cn /= 10, ++nr)
        sum += (lst = cn % 10);

    sum = max (sum, lst - 1 + (nr - 1) * 9);

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

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,q;
    cin>>n>>k>>q;
    vector<int>vec(n);
    REP(i,n)
    vec[i]=k;
    vector<int>co(n);
    REP(i,n)
    co[i]=0;
    REP(i,q)
    {
        int a;
        cin>>a;
        co[a-1]++;
    }
    vector<string>ans;
    REP(i,n)
    {
        vec[i]-=q;
        vec[i]+=co[i];
        if(vec[i]>0)
            ans.push_back("Yes");
        else
            ans.push_back("No");
    }
    REP(i,n)
    cout<<ans[i]<<endl;

}


Measured memory_bytes: 6900
use proconio::input;

fn main() {
    input! {
        mut h: isize,
        n: usize,
        a: [isize; n],
    }

    for i in 0..n {
        h -= a[i];

        if h <= 0 {
            println!("Yes");
            return
        }
    }

    println!("No")
}


Measured memory_bytes: 3172
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	int n, c, k;
	cin >> n >> c >> k;

	vector<int> t(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &t.at(i));
	}

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

	int old = -1;
	int cnt = 0;
	int in = 1;
	for (int i = 0; i < n; i++)
	{
		if (old == -1)
		{
			old = t.at(i);
		}

		if (old + k >= t.at(i))
		{
			in++;
			if (in >= c)
			{
				cnt++;
				in = 0;
				old = -1;
			}
		}
		else
		{
			cnt++;
			in = 1;
			old = t.at(i);
		}	
	}

	if (in > 0)
	{
		cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,c[N];
ll ans;
struct data
{
	int x,y;
	bool operator <(const data&a) const
	{
		return x-y<a.x-a.y;
	}
}a[N];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read();
	for (int i=1;i<=n;i++) a[i].x=read();
	for (int i=1;i<=n;i++) a[i].y=read();
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) c[i]=a[i].x;
	for (int i=1;i<=n;i++) ans+=a[i].x-a[i].y;
	if (ans<0) {cout<<-1;return 0;}
	int x=n,ans=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i].x>=a[i].y) break;
		while (a[i].y-a[i].x>a[x].x-a[x].y)
		{
			a[i].x+=a[x].x-a[x].y;
			a[x].x=a[x].y;
			x--;
		}
		a[x].x-=a[i].y-a[i].x,a[i].x=a[i].y;
	}
	for (int i=1;i<=n;i++) if (c[i]!=a[i].x) ans++;
	cout<<ans;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    cout << 4 + (N + min({A, B, C, D, E}) - 1)/ min({A, B, C, D, E}) << endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define FAST_IO std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)
#define Puase system("pause")
using namespace std;
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> pli;
typedef pair<int, int> pint;

int const maxn = 5e5 + 10;
ll const INF = 0x3F3F3F3F3F3F3F3F;
ll dis[maxn << 2];
std::map<pint, int> Node;
struct node
{
    int v, w, next;
}e[maxn << 5];
int cnt, head[maxn];
int vis[maxn];

void add(int u, int v, int w) {
    e[cnt].v = v;
    e[cnt].w = w;
    e[cnt].next = head[u];
    head[u] = cnt++;
}
int node_num = 0;
int getNodeNum(int u, int v) {
    auto x = make_pair(u, v);
    if (Node.find(x) == Node.end()) {
        Node[x] = ++node_num;
    }

    return Node[x];
}

void dijkstra() {
    memset(dis, 0x3f, sizeof(dis));
    priority_queue<pli> q;
    dis[1] = 0;
    q.push(make_pair(0, 1));
    int c = 0;
    while (!q.empty()) {
        int u = q.top().second;
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        for (int i = head[u]; ~i; i = e[i].next) {
            int v = e[i].v;
            int w = e[i].w;
            if (dis[v] > dis[u] + w) {
                dis[v] = dis[u] + w;
                q.push(make_pair(-dis[v], v));
            }
        }
    }
}

int main(void) {    
    FAST_IO;
    memset(head, -1, sizeof(head));
    int n, m;
    cin >> n >> m;
    node_num = n;
    for (int i = 0 ; i < m; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        int u = getNodeNum(p, c);
        int v = getNodeNum(q, c);
        add(p, u, 1);
        add(u, p, 1);
        add(q, v, 1);
        add(v, q, 1);
        add(u, v, 0);
        add(v, u, 0);
    }
    dijkstra();

    cout << (dis[n] == INF ? -1 : dis[n] / 2) << endl;
    // Puase;
    return 0;
}

Measured memory_bytes: 64372
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define fo(a,b) for (int i = a; i < b; i++) 
#define foi(a,b) for (int i = a; i <= b; i++) 
using namespace std;


typedef long long ll;
typedef unsigned long long ull;

bool is_perfect_square(int n) {
    if (n < 0)
        return false;
    int root(round(sqrt(n)));
    return n == root * root;
}

int main ()  {
	int t1, t2, x1, x2, y1, y2, N;
	cin >> N;
	x1 = y1 = t1 = 0;
	bool ans = true;
	while (cin >> t2 >> x2 >> y2) {
		if (abs(t2-t1) >= abs(x2-x1)+abs(y2-y1) && (t2-t1)%2 == (abs(x2-x1+y2-y1)) % 2);
		else ans = false;

		x1 = x2;
		t1 = t2;
		y1 = y2;
	}

	if (ans) cout << "Yes";
	else cout << "No";
	return 0;
}

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

vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	string s;
	cin >> s;
	if(s.back() == 's'){
		cout << s << "es" << endl;
	}else{
		cout << s << 's' << endl;
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,a[405][4],tot[405];
ll h[405][4],hh[405];
map<ll,ll> f[5];
int id[4][4]={{1,0,1,0},{3,2,3,2},{2,1,0,3},{0,3,2,1}};
int main(){
	const ll inf=ll(1e15);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int p=0;p<4;p++) scanf("%d",&a[i][p]);
	for(int i=1;i<=n;i++){
		ll mn=inf;int sum=0;
		for(int p=0;p<4;p++){
			for(int j=0;j<4;j++){
				int x=(p+j)&3;
				h[i][p]=h[i][p]*1000+a[i][x];
			}
			if(h[i][p]<mn) mn=h[i][p],sum=0;
			if(h[i][p]==mn) sum++;
		}
		if(f[0].find(mn)==f[0].end()){
			for(int p=1;p<=4;p++) f[p][mn]=0;
			f[0][mn]=1;
		}
		hh[i]=mn;tot[i]=sum;
		for(int p=4;p;p--){
			f[p][mn]+=f[p-1][mn]*sum;
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=4;j++) f[j][hh[i]]-=f[j-1][hh[i]]*tot[i];
		for(int p=i+1;p<=n;p++){
			for(int j=1;j<=4;j++) f[j][hh[p]]-=f[j-1][hh[p]]*tot[p];
			for(int ww=0;ww<4;ww++){
				int b[4],c[4];
				for(int k=0;k<4;k++) b[k]=a[p][(k+ww)&3];
				ll mn[4]={inf,inf,inf,inf};
				for(int j=0;j<4;j++){
					for(int w=0;w<2;w++) c[w]=a[i][id[j][w]];
					for(int w=2;w<4;w++) c[w]=b[id[j][w]];
					for(int w=0;w<4;w++){
						ll H=0;
						for(int o=0;o<4;o++) H=H*1000+c[(o+w)&3];
						mn[j]=min(mn[j],H);
					}
					
				}
				sort(mn,mn+4);
				ll sum=1;
				for(int j=0;j<4;){
					int o;
					for(o=j;o<4&&mn[o]==mn[j];o++) sum*=(o-j+1);
					if(f[o-j].find(mn[j])==f[o-j].end()){
						sum=0;break;
					}
					sum*=f[o-j][mn[j]];
					j=o;
				}
				ans+=sum;
			}
			for(int j=4;j;j--) f[j][hh[p]]+=f[j-1][hh[p]]*tot[p];
		}
	}
	printf("%lld",ans);
	return 0;
}

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

int output(int *ans, int N, int flag){
  if(flag == 1){
    puts("-1");
    return 0;
  }

  if(ans[N-1] == -1){  
    ans[N-1] = 1;
    if(N == 1)
      ans[N-1] = 0;
  }
  
  int i;
  for(i=1; i<=N; i++){
    if(ans[N-i] == -1)
      ans[N-i] = 0;
    printf("%d", ans[N-i]);
  }
  printf("\n");

  return 0;
}

int main(void){
  int N, M;
  int s, c;
  int ans[5] = {-1, -1, -1, -1, -1};
  int i;
  int flag = 0;

  scanf("%d %d", &N, &M);

  for(i=0; i<M; i++){
    scanf("%d %d", &s, &c);
    if(((ans[N-s] != -1) && (ans[N-s] != c)) || (N > 1 && (s == 1 && c == 0)))
      flag = 1;
    ans[N-s] = c;
  }

  output(ans, N, flag);
	 
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const int MAX_H = 50000;
int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(MAX_H, INF));

    dp[0][0] = 0;
    rep(i, N) {
        rep(j, MAX_H) {
            if (j < A[i]) {
                chmin(dp[i + 1][j], dp[i][j]);
            }
            else {
                chmin(dp[i + 1][j], min(dp[i][j], dp[i + 1][j - A[i]] + B[i]));
            }
        }
        for (int j = MAX_H - 2; j >= 0; j--) {
            chmin(dp[i + 1][j], dp[i + 1][j + 1]);
        }
    }

    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 396032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x = new int[n];
		int sum = 0;

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			sum += Math.min(Math.abs(x[i] - 0), Math.abs(x[i] - k)) * 2;
		}

		System.out.println(sum);
	}
}

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

int main() {

    ll n, m; cin >> n >> m;
    vector<string> a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    ll ans = 0;
    REP(i, n) REP(j, m) ans += a[i][j] != b[i][j];
    cout << ans << endl;

}


Measured memory_bytes: 11132
n=int(input())
t,a=map(int,input().split())
h=[int(i) for i in input().split()]

ans=100000000000000
p=0
for i in range(n):
    j=t-h[i]*0.006
    if ans>abs(j-a):
        ans=min(ans,abs(j-a))
        p=i+1

print(p)
    

Measured memory_bytes: 3060
import sys
import heapq

def main():
    n = int(input())
    next = []
    for _ in range(n):
        l = list(map(int, input().split()))
        next.append([(c, i) for i, c in enumerate(l) if c != -1])
    visited = [0] * n
    connection = 0
    q = [(0, 0)]    # (cost, v)
    heapq.heapify(q)
    ans = 0
    while len(q):
        cost, v = heapq.heappop(q)
        if visited[v]:
            continue

        # そのノードと繋げる
        visited[v] = 1
        connection += 1
        ans += cost
        
        # 新たに繋げたノードから行けるところをエンキュー
        for i in next[v]:
            heapq.heappush(q, i)
        
        # 全部のノードが繋がったら終了
        if connection == n:
            break
    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 6476
#include <stdio.h>
#include <string.h>

int main(void) {
	int i, j, len;
	int f = 1;
	char c;
	char s[200001], t[200001];
	scanf("%s%s", s, t);
	len = strlen(s);;
	for (i = 0; i < len; i++) {
		if (s[i] != t[i]) {
			c = t[i];
			for (j = 0; j < len; j++) {
				if (t[j] == s[i] || t[j] == c) {
					if (j < i) {
						f = 0;
					}
					if (t[j] == c) t[j] = s[i];
					else if (t[j] == s[i]) t[j] = c;
				}
				if (f == 0) break;
			}
		}
		if (f == 0) break;
	}
	printf(f ? "Yes\n" : "No\n");

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
#define REP(m,n) for(int i=m;i<n;++i)
#define REPj(m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define ll long long
#define mp make_pair

int main() {
	vector<int>v, a;
	int n;
	ll ans = 1;
	string s, t;
	cin >> n >> s >> t;
	REP(0, n - 1) {
		if (s[i] == s[i + 1]) {
			v.push_back(3);
			i++;
		}
		else {
			v.push_back(1);
		}
	}
	if (n == 1) {
		v.push_back(1);
	}
	else {
		if (s[n - 1] != s[n - 2]) {
			v.push_back(1);
		}
	}
	if (v[0] == 1) {
		a.push_back(3);
	}
	else {
		a.push_back(6);
	}
	REP(0, v.size() - 1) {
		if (v[i] == 1) {
			a.push_back(2);
		}
		else {
			a.push_back(v[i + 1]);
		}
	}
	REP(0, a.size()) {
		ans = ans*a[i] % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
using pp = pair<p,p>;
using ll = long long;
const auto INF =(ll)1e5;
int a,b,c,d,e,f;
int main(){
  cin >> a >> b >> c >> d >> e >> f;

  auto x = vector<int>();
  auto y = vector<int>();
 
  
  for (int i = 0; i < 3000; i++)
  {
    for (int j = 0; j < 3000; j++)
    {
      if(100*(a*i)+b*j<=f){
      	x.push_back(100*(a*i+b*j));
      }
      if(c*i+d*j<=f){
      	y.push_back(c*i+d*j);
      }
    }
  }
  
  double _max=-1;
  auto _p = p(0,0);
  for(auto i:x){
    for(auto j:y){
      if(i+j>f) continue;
      if(j>i/100*e) continue;
      auto mol = i+j==0 ? 0:(double)100*j/(i+j);
      if(_max <= mol){
      	_p.first = i;
        _p.second = j;
        _max = mol;
      }
    }
  }
  
  cout << _p.first+_p.second<<" "<<_p.second;
  return 0;
}

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

using namespace std;

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void milkshake() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  int ans = a[0];
  for(int i = 1; i < n; i++) {
    if(i % 2) ans -= a[i];
    else ans += a[i];
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  //cin >> tt;
  while(tt--) milkshake();

  return 0;
}


Measured memory_bytes: 3584
n, m, c = map(int, input().split())
b = [int(x) for x in input().split()]
ans = 0
for i in range(n):
    a = [int(x) for x in input().split()]
    key = c
    for j in range(m):
        key += a[j]*b[j]
    if key > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

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



int main()
{
    
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
 
    vector<int> dp(n, INT_MAX);
  
    
    dp[0] = 0;
  
    dp[1] = abs(h[1] - h[0]);
    
    
    for(int i = 2; i < n; i++){
      for(int j = i - 1, jump = 0; j  >= 0 && jump < k; j--, jump++){
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
      }
    }
   
    cout << dp[n - 1];
    return 0;

}


Measured memory_bytes: 1024
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		boolean turnA = true;

		for(int i=0;i<k;i++){
			if(turnA){
				if(a%2==1){
					a-=1;
				}
				b = b+ a/2;
				a = a/2;
				turnA =false;
				// System.out.println(a + " "+b);
			}else{
				if(b%2==1){
					b-=1;
				}
				a = a+ b/2;
				b = b/2;
				turnA =true;
				// System.out.println(a + " "+b);
			}
		}
		System.out.println(a + " "+b);

	}
}

Measured memory_bytes: 23252
#include <iostream>

using namespace std;

int main()
{
    int m1,d1; cin>>m1>>d1;
    int m2,d2; cin>>m2>>d2;

    if((d1==30 || d1==31 || d1==28) && (m1<m2))
        {cout<<1<<endl; return 0;}
    else cout<<0<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

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

	if(x>=30)cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 3640
import sys
from collections import defaultdict
sys.setrecursionlimit(1000000)
N, Q = map(int,input().split())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

d = defaultdict(int)
for _ in range(Q):
    p,x = map(int,input().split())
    d[p-1] += x
visited = [False]*N
cnt = [0]*N
def dfs(n, acc):
    cnt[n] = acc
    for m in edges[n]:
        if not visited[m]:
            visited[m] = True
            dfs(m, acc+d[m])
visited[0] = True
dfs(0, d[0])
print(*cnt)

Measured memory_bytes: 254524
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f,g,h,i,j;
    map<int,int>m;
    map<int,int>::iterator it;
    int n;
    cin >> n;
    int t[n], x[n], y[n];
    for(i=0; i<n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }
    int T= 0;
    int X = 0;
    int Y = 0;
    for(i=0; i<n; i++)
    {
        int dt = t[i] - T;
        int dx = abs(X - x[i]);
        int dy = abs(Y - y[i]);
        if (dt >= dx + dy)
        {
            if ((dt - (dx + dy)) % 2 != 0)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}


Measured memory_bytes: 1408