akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define MAX 10000
#define NIL -1 

struct Node{int parent, left, right; };

struct Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
  if(u == NIL)return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)h1 = setHeight(T[u].left)+1;
  if(T[u].right != NIL)h2 = setHeight(T[u].right)+1;
  if(h1 >= h2)return H[u] = h1;
  if(h2 > h1)return H[u] = h2;
}

int getSibling(int u){
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
 
  if(T[u].parent == NIL)printf("root\n");
  else if (T[u].left == NIL && T[u].right == NIL)printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i, v, l, r, root = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].parent = NIL;

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v, &l, &r);
    T[v].left=l;
    T[v].right = r;
    if(l != NIL)T[l].parent = v;
    if(r != NIL)T[r].parent = v; 
  }
  
  for(i=0;i<n;i++)if(T[i].parent == NIL)root = i;

  setDepth(root,0);
  setHeight(root);
  
  for(i=0;i<n;i++)print(i);

  return 0;
}



Measured memory_bytes: 2132
import bisect

x = int(input())
six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]


def six_nine(n):
    if n < 6:
        return n
    else:
        six = six_list[bisect.bisect_right(six_list, n) - 1]
        nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
        return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))


print(six_nine(x))


Measured memory_bytes: 42200
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

auto pair_hash = [hash_fn = hash<int>()](const PII& o) {
    return hash_fn(o.first) ^ hash_fn(o.second);
};

unordered_map<PII, LL, decltype(pair_hash)> s(0, pair_hash);
int a[200010], premax[200010];
int n;

LL dfs(int n, int k) {
    if (!k) {
        return 0;
    }
    if (s.count({n, k})) {
        return s[{n, k}];
    }
    if (k == 1) {
        return s[{n, k}] = premax[n];
    }
    LL opt = LONG_MIN;
    for (int i = n; (k - 1) * 2 - 1 <= i - 2; --i) {
        opt = max(opt, dfs(i - 2, k - 1) + a[i]);
    }
    return s[{n, k}] = opt;
}

inline void work() {
    cin >> n;
    premax[0] = INT_MIN;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        premax[i] = max(premax[i - 1], a[i]);
    }
    cout << dfs(n, n / 2) << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 32264
#include "bits/stdc++.h"

using namespace std;

int comp(string s,string t){// s>t:=1,s==t:=0,s<t:=-1;
    int slen=s.length(),tlen=t.length();
    if(slen>tlen) return 1;
    if(slen<tlen) return -1;
    for(int i=0;i<slen;i++){
        if(s[i]>t[i]) return 1;
        if(s[i]<t[i]) return -1;
    }
    return 0;
}

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

    int w,h;
    while(cin>>w>>h,w||h){
        vector<string> v(h);
        for(int i=0;i<h;i++) cin>>v[i];
        vector<vector<string> > dp(100,vector<string>(100,""));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if('1'<=v[i][j] && v[i][j]<='9') dp[i][j]+=v[i][j];
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(v[i][j]<'0' || '9'<v[i][j]) continue;
                if(i==0 && j==0) continue;
                else if(i==0){
                    if(dp[i][j-1]=="") continue;
                    if(v[i][j]<'0' || '9'<v[i][j]) continue;
                    dp[i][j]=dp[i][j-1]+v[i][j];
                }
                else if(j==0){
                    if(dp[i-1][j]=="") continue;
                    if(v[i][j]<'0' || '9'<v[i][j]) continue;
                    dp[i][j]=dp[i-1][j]+v[i][j];
                }
                else{
                    if(dp[i-1][j]=="" && dp[i][j-1]=="") continue;
                    else if(dp[i-1][j]=="") dp[i][j]=dp[i][j-1]+v[i][j];
                    else if(dp[i][j-1]=="") dp[i][j]=dp[i-1][j]+v[i][j];
                    else{
                        string s=dp[i-1][j],t=dp[i][j-1];
                        if(comp(s,t)==-1) dp[i][j]=t+v[i][j];
                        else dp[i][j]=s+v[i][j];
                    }
                }
            }
        }
        string res="0";
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(dp[i][j]=="") continue;
                if(comp(dp[i][j],res)==1) res=dp[i][j];
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3332
N = int(input())
L = list(map(int,input().split()))

L.sort(reverse=True)
counter = 0
import bisect

for index1,c in enumerate(L):
    for index2,b in enumerate(L[index1+1:],start=index1+1):
        left = 0 ; right = N
        oppai = c-b
        while left+1<right:
            mid = (left+right)//2
            if L[mid]>oppai:
                left = mid
            else :
                right=mid
        
        index3 = left
        
        if index3>index2:

            counter += index3-index2
print(counter)

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


def solve(S: str):
    print( "ABC" if S == "ARC" else "ARC")

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
<?php   
    fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$d);
	//explode(" ",trim(fgets(STDIN));
	
	for($i=0; $a>0 && $c>0 ;$i++){
      if($i%2==0){
        $c -= $b;
      }else{
        $a -= $d;
      }
    }

	if($c<=0){
      echo "Yes\n";
    }else{
      echo "No\n";
    }



Measured memory_bytes: 16244
from sys import stdin
def ii(): return int(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def li(): return list(mi())
n=ii()-2
a=li()
for i in range(n, -1, -1):
    if a[i]>a[i+1]:
        a[i]-=1
        if a[i]>a[i+1]:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 14168
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265
#define seive_len 10000001

bool seive[seive_len];
int primeSeive[seive_len];

typedef long long int lli;

lli gcd(lli a, lli b) {
  if(b == 0)
    return a;
  return gcd(b, a%b);
}

lli lcm(lli a, lli b) {
  lli gcd_ = gcd(a, b);
  lli lcm_ = (a*b)/gcd_;
  return lcm_;
}

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

lli fastPowerM(lli a, lli b, lli mod) {
  a %= mod;
  lli res = 1;
  while(b) {
    if(b%2 == 1)
      res = (res*a)%mod;
    a = (a*a)%mod;
    b >>= 1;
  }
  return res;
}

void multiply(lli a[][2], lli b[][2], int mod) {
  int res[2][2];
  memset(res, 0, sizeof(res));
  for(int i=0;i<2;i++) {
    for(int j=0;j<2;j++) {
      for(int k=0;k<2;k++) {
        res[i][j] += a[i][k]*b[k][j]%mod;
      }
    }
  }
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      a[i][j] = res[i][j];
}

void matrixExpo(lli a[][2], lli n, int mod) {
  if(n == 0 || n == 1)
    return;
  lli b[][2] = {{1,1}, {1,0}};
  matrixExpo(a, n/2, mod);
  multiply(a, a, mod);
  if(n%2)
    multiply(a, b, mod);
}

void makeSeive() {
  for(int i=2;i*i<=seive_len;i++) {
    if(seive[i]) {
      for(int j=i*i;j<=seive_len;j+=i)
        seive[j] = false;
    }
  }
}

void makePrimeSeive() {
  for(int i=1;i<seive_len;i++)
    primeSeive[i] = i;
  for(int i=4;i<seive_len;i+=2)
    primeSeive[i] = 2;
  for(int i=3;i*i<seive_len;i++) {
    if(primeSeive[i] == i) {
      for(int j=i*i;j<seive_len;j+=i) {
        if(primeSeive[j] = j)
          primeSeive[j] = i;
      }
    }
  }
}

bool isPrime(lli n) {
  for(int i=2;i<=sqrt(n);i++) {
    if(n%i == 0)
      return false;
  }
  return true;
}

void getInput(vector<lli>& a, int n) {
  lli x;
  for(int i=0;i<n;i++) {
    cin >> x;
    a.push_back(x);
  }
}

lli sumOfFactors(lli n) {
  lli prev = -1, count = 0, res = 1;
  map<int, int> m;
  while(n != 1) {
    // if(primeSeive[n] != prev) {
    //   // res *= (count+1);
    //
    //   // prev = primeSeive[n];
    //   // count = 1;
    // }
    // else
    //   count++;
    m[primeSeive[n]]++;
    n /= primeSeive[n];
  }
  for(auto i: m)
    res *= (i.second+1);
  // res *= (count+1);
  return res;
}

void testCase() {
  lli i, n;
  cin >> n;
  lli res = 1;
  for(i=2;i<=n;i++)
    res += i*sumOfFactors(i);
  cout << res;
}

int main() {
	int t=1;
	// cin >> t;
  makePrimeSeive();
	while(t--) {
		testCase();
    cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 42780
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

ll kiri(ll a,ll b){return a%b==0?a/b:a/b+1;}

ll a,b,c,d;
map<ll,ll> mp;

ll dfs(ll n){
  if(n==0) return 0;
  if(n==1) return d;
  if(mp.count(n)) return mp[n];
  ll res=1e18;
  if(n<res/d) res=n*d;
  ll ret=min({
    res,
    d*abs(n-n/5*5)+c+dfs(n/5),
    d*abs(n-kiri(n,5)*5)+c+dfs(kiri(n,5)),
    d*abs(n-n/3*3)+b+dfs(n/3),
    d*abs(n-kiri(n,3)*3)+b+dfs(kiri(n,3)),
    d*abs(n-n/2*2)+a+dfs(n/2),
    d*abs(n-kiri(n,2)*2)+a+dfs(kiri(n,2))
  });
  mp[n]=ret;
  return ret;
}

int main(){
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  ll T; cin >> T;
  vector<ll> ans(0);
  rep(z,T){
    mp.clear();
    ll n;
    cin >> n >> a >> b >> c >> d;;
    ans.push_back(dfs(n));
  }
  rep(i,T){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long int sum=0;
  cin >> n;
  for(int i=1; i<=n; i++){
    if(i%3!=0 && i%5!=0)
      sum+=i;
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int K;

int main() {
  INCANT;
  cin >> K;
  ll ret= 0;
  rep(i, K) {
    rep (j, K) {
      rep (k, K) {
        int tmp = gcd(i+1, j+1);
        ret+=gcd(tmp, k+1);
      }
    }
  }
  cout << ret << "\n";
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
map<ll,ll>mp;
cin>>n;
for(ll i=0;i<n;i++){
    ll t;
    cin>>t;
    mp[t]++;
    mp[t-1]++;
    mp[t+1]++;
}
ll ans=0;
for(auto i:mp)chmax(ans,i.second);
cout<<ans<<endl;
}

Measured memory_bytes: 9516
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a, T b) { return a<b?(a=b,true):false; }
#define forn(i,x,y) for(int i=(x);i<(int)(y);i++)
#define rep(i,y) for(int i=0;i<(int)(y);i++)
#define repb(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define debug(X) cout<<" "<<#X<<" = "<<X<<endl;

template<class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << " ";
    os << *it;
  }
  return os;
}

void err() {
  cout << "NO" << endl;
  exit(0);
}


ll n;
int a[100100];
int d[100100];

int main() {
  cin>>n;
  ll sum=0;
  rep(i,n) {
    cin>>a[i];
    sum += a[i];
  }
  if (sum % (n * (n+1) / 2) != 0) err();
  ll k = sum / (n * 1LL * (n+1) / 2);

  d[0] = a[0] - a[n-1];
  for (int i=1; i<n; i++)
  {
    d[i] = a[i] - a[i-1];
  }

  int t = k;
  rep(i, n) {
    d[i] -= k;
    if (d[i] > 0) err();

    if ((-d[i]) % n != 0) err();
    t -= (-d[i]) / n;
  }
  if (t!=0) err();
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int	main(void)
{
  	int	x1;
  	int	x2;
  	int	x3;
  	int x4;
  	int x5;
  
  	scanf("%d %d %d %d %d", &x1, &x2, &x3, &x4, &x5);
  
  	if (x1 == 0)
      	printf("1");
  	else if (x2 == 0)
      	printf("2");
  	else if (x3 == 0)
      	printf("3");
  	else if (x4 == 0)
      	printf("4");
  	else if (x5 == 0)
      	printf("5");
  	
  	return (0);
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;

	cin >> N;
	int d[N];

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

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



Measured memory_bytes: 256
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
 
ab_sorted = sorted(ab, key=lambda x:x[0])
 
num = 0
amount_of_money = 0

for i in range(n):
    buy = min(ab_sorted[i][1], m-num)
    num += buy
    amount_of_money += ab_sorted[i][0] * buy
        
    if num >= m:
        print(amount_of_money)
        exit(0)

Measured memory_bytes: 29304
#include<stdio.h>
 
int main(void){
 
  int i;
 
  /* 文字 */
  char moji;
 
  /* 文字を入力 */
  scanf("%c", &moji);
 
  /* アルファベットの小文字か大文字かを判定 */
  if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  else if((moji>= 'A') && (moji<='Z')){
    printf("A\n");
    return 0;
  }
  else {
    printf("その他の文字！\n");
  }
 
  return 0;
}


Measured memory_bytes: 1596
#include <iostream>
#include <cstring>

using namespace std;

int max(int a,int b)
{
	return (a > b ? a : b);
}
int main()
{
	string s,t;
//	cout << "Enter two strings\n";
	cin >> s >> t;
	int l = s.size();
	int m = t.size();

	int dp[l + 1][m + 1];

	memset(dp,0,sizeof(dp));

	int i,j,k = 0;
	for (i = 1; i <= l; ++i)
	{
		for (j = 1; j <= m; ++j)
		{
			if(s[i - 1] == t[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
			}
		}
	}
//	cout << dp[l][m] << '\n';

	char cc[dp[l][m] + 1];
	cc[dp[l][m]] = '\0';
	i = l;
	j = m;
	int idx = dp[l][m];
	while(i > 0 && j > 0)
	{
		if(s[i - 1] == t[j - 1])
		{
			cc[idx - 1] = s[i - 1];
			idx--;i--;j--;
		}
		else
		{
			if(dp[i][j - 1] > dp[i - 1][j])
			{
				j--;
			}
			else
			{
				i--;
			}
		}
	}
	cout << cc << '\n';
	return 0;
}

Measured memory_bytes: 35456
use petgraph::unionfind::UnionFind;
use proconio::input;

fn main() {
    input! {
        n: usize,
        q: usize,
        tq: [(usize, usize, usize); q],
    }
    let mut f = UnionFind::new(n);
    for (t, u, v) in tq {
        if t == 0 {
            f.union(u, v);
        } else if t == 1 {
            println!("{}", if f.equiv(u, v) { 1 } else { 0 });
        }
    }
}


Measured memory_bytes: 10112
//#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

const i64 INF = 1LL << 50;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int rev[4] = {1, 0, 3, 2};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 H, W, K;
  cin >> H >> W >> K;
  pair<i64, i64> start, goal;
  cin >> start.first >> start.second;
  cin >> goal.first >> goal.second;
  start.first--;
  start.second--;
  goal.first--;
  goal.second--;

  vector<string> grid(H);
  cin.ignore();
  REP(i, H) {
    getline(cin, grid[i]);
    assert(grid[i].size() == (size_t)W);
  }

  vector<vector<i64>> distm(H, vector<i64>(W, INF));

  auto solve = [&]() -> i64 {
    deque<tuple<i64, int, int, int>> pq;
    pq.emplace_back(0LL, start.first, start.second, -1);
    distm[start.first][start.second] = 0;
    while (pq.size()) {
      auto [d, r, c, dirs] = pq.front();
      d *= -1;
      pq.pop_front();
      if (r == goal.first && c == goal.second) return d;
      DEBUG(r, c, d);
      REP(j, 4) {
        if ((dirs & (1 << j)) == 0) continue;
        for (int k = 1; k <= K; ++k) {
          int nr = r + dx[j] * k;
          int nc = c + dy[j] * k;
          if (nr < 0 || nr >= H) break;
          if (nc < 0 || nc >= W) break;
          if (grid[nr][nc] == '@') break;
          if (distm[nr][nc] <= d + 1) continue;
          distm[nr][nc] = d + 1;
          int ndirs = -1 & ~(1 << rev[j]);
          if (k < K) {
            ndirs &= ~(1 << j);
          }
          pq.emplace_back(-(d + 1), nr, nc, ndirs);
        }
      }
    }
    return -1LL;
  };
  i64 ans = solve();
  cout << ans << endl;
}


Measured memory_bytes: 19748
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,a[200000],i,j,flg=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			flg=1;
		}
	}
	if(flg==1){
		printf("NO\n");
	}
	else{
		printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 2384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int position =0;
		while (position<s.length()) {
			if (position+5>s.length()) {
				System.out.println("NO");
				return ;
			}
			if ("dream".equals(s.substring(position,position+5))==false&&"erase".equals(s.substring(position,position+5))==false) {
				System.out.println("NO");
				return ;
			}
			position+=5;
			if (s.charAt(position-1)=='m') {
				if (position+2<=s.length()) {
					if ("er".equals(s.substring(position,position+2))==false ) {
						continue;
					}
					if (position+2<s.length()&&(s.charAt(position+2)=='e'||s.charAt(position+2)=='d')) {
						position +=2;
					} else if (position+2==s.length()){
						position +=2;
					}
				}
			} else {
				if (position<s.length()) {
					if (s.charAt(position)=='r') {
						position +=1;
					}
				}
			}

		}
		System.out.println("YES");
	}
}

Measured memory_bytes: 40552
#!/use/bin/env python3

from collections import defaultdict

n = int(input())
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(s[0], s[-1] + 1):
    l = sum([pow(x - p, 2) for x in s])

    if l < ans:
        ans = l

print(ans)

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

#define ll long long

using namespace std;

ll ans = 0;

void gcd (ll a, ll b)
{
    if(b == 0)
    {
        ans -= a;
        return;
    }
    if(a >= b)
        ans += b * (a / b) * 2;
    gcd(b, a % b);
}

ll n, x;

int main()
{
    cin >> n >> x;
    gcd(n - x, x);
    cout << ans + n << "\n";
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	sc.SetSplitter(" ")
	n, k := sc.ScanInt(), sc.ScanInt()

	count := 0

	for b := 1; b <= n; b++ {
		q := n / b
		s := n % b

		count += Max(b-k, 0) * q
		if s >= k {
			count += s - Max(k-1, 0)
		}
	}

	fmt.Println(count)
}

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{bufio.NewScanner(r)}
}

func (s *Scanner) SetSplitter(sep string) {
	switch sep {
	case "":
		s.sc.Split(bufio.ScanRunes)
	case " ":
		s.sc.Split(bufio.ScanWords)
	default:
		s.sc.Split(bufio.ScanLines)
	}
}

func (s *Scanner) ScanInt() int {
	s.sc.Scan()
	i, e := strconv.Atoi(s.sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}


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


#define ll long long
#define pll pair <ll,ll>
#define fi first
#define se second
#define endl "\n"
#define sqr(b) (b)*(b)


using namespace std;



int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    ll n, w, v = 0;
    ll a[111][2];

    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i][0] >> a[i][1];
        v += a[i][1];
    }

    ll dp[111111];
    for (int i = 1; i <= v; i++) dp[i] = 2e9;

    for (int i = 1; i <= n; i++) {
        for (int j = v; j > 0; j--) if (j - a[i][1] >= 0) {
            dp[j] = min(dp[j], dp[j - a[i][1]] + a[i][0]);
        }
    }


    for (int i = v; i >= 0; i--) if (dp[i] <= w) {
        cout << i << endl;
        break;
    }

    return 0;
}


Measured memory_bytes: 4420
#include<iostream>
using namespace std;
int main(int a,int b) {
    cin >> a >> b;
    if(a < b) {
        cout << "a < b" << endl;
    }
    else if(a > b) {
        cout << "a > b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>

using namespace std;

int main() {
  size_t N;
  cin >> N;

  vector<size_t> A;
  size_t max = 0, max_1 = 0;
  size_t max_idx = 0, max_1_idx = 0;
  for (size_t i = 0; i < N; i++) {
    size_t a;
    cin >> a;
    A.emplace_back(a);
    if (a >= max_1 && a >= max) {
      max_1 = max;
      max_1_idx = max_idx;
      max = a;
      max_idx = i;
    } else if (a >= max_1) {
      max_1 = a;
      max_1_idx = i;
    }
  }

  for (size_t i = 0; i < N; i++) {
    if (i == max_idx) {
      cout << max_1 << endl;
    } else {
      cout << max << endl;
    }
  }

  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);

//int dxy[5] = {0, 1, 0, -1, 0};
// assign

vector< vector< char > > board;
int n, m;

bool comp(vector<char> &v1, vector<char> &v2);
void search(int i, int j);

signed main()
{
    cin >> n >> m;
    while (m) {
        board.assign(m, vector<char>(n));
        getchar();
        rep(i, m) {
            rep(j, n) {
                cin >> board[i][j];
            }
        }
        vector< vector< vector<char> > > dp(m, 
                vector<vector<char> >(n));
        if ('1' <= board[0][0] && board[0][0] <= '9') {
            dp[0][0].pb(board[0][0]);
        }
        rep(i, m) {
            rep(j, n) {
                if (dp[i][j].size()) {
                    vector<char> tmp = dp[i][j];
                    if (i+1 < m && '0' <= board[i+1][j]
                            && board[i+1][j] <= '9') {
                        tmp.pb(board[i+1][j]);
                        if (comp(tmp, dp[i+1][j])) {
                            dp[i+1][j] = tmp;
                        }
                        tmp.pop_back();
                    }
                    if (j+1 < n && '0' <= board[i][j+1]
                            && board[i][j+1] <= '9') {
                        tmp.pb(board[i][j+1]);
                        if (comp(tmp, dp[i][j+1])) {
                            dp[i][j+1] = tmp;
                        }
                        tmp.pop_back();
                    }
                } else {
                    if (i+1 < m && '1' <= board[i+1][j]
                            && board[i+1][j] <= '9'
                            && !dp[i+1][j].size()) {
                        dp[i+1][j].pb(board[i+1][j]);
                    }
                    if (j+1 < n && '1' <= board[i][j+1]
                            && board[i][j+1] <= '9'
                            && !dp[i][j+1].size()) {
                        dp[i][j+1].pb(board[i][j+1]);
                    }
                }
            }
        }
        vector<char> ans;
        rep(i, m) {
            rep(j, n) {
                if (comp(dp[i][j], ans)) {
                    ans = dp[i][j];
                }
            }
        }
        for (char i : ans) {
            cout << i;
        }
        cout << endl;

        cin >> n >> m;
    }
    return 0;
}

bool comp(vector<char> &v1, vector<char> &v2)
{
    if (v2.size() < v1.size() ) {
        return true;
    } else if (v2.size() == v1.size() ) {
        rep(i, v2.size()) {
            if (v1[i] > v2[i]) {
                return true;
            } else if (v1[i] < v2[i]) {
                return false;
            }
        }
    }
    return false;
}

Measured memory_bytes: 3212
#include <iostream>
using namespace std;
#define MAX (1<<15)

bool prime[MAX];

int main(){
	int n;
	for(int i=2; i<MAX; i++) prime[i] = true;
	for(int i=2; i<MAX; i++){
		if( prime[i] ){
			for(int j=i+i; j<MAX; j+=i){
				prime[j] = false;
			}
		}
	}
	while( cin >> n, n ){
		int cnt = 0;
		for(int i=2; i<=n/2; i++){
			if( prime[i] && prime[n-i] ) cnt++;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
  { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int n, u, v;
  vector<int> V[maxn];
  bool is[maxn];
  int Maxdep[maxn], dep[maxn];
  void solve() {
    cin >> n >> u >> v;
    for (int i = 1; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      V[a].push_back(b);
      V[b].push_back(a);
    }
    dfs(v, v);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (i == v || !is[i])
        continue;
      if (dep[u] - dep[i] < dep[i] - 1) {
        ans = max(ans, Maxdep[i] - 2);
      }
    }
    cout << ans;
  }
  bool dfs(int a, int f) {
    if (a == u) {
      is[a] = 1;
    }
    dep[a] = dep[f] + 1;
    Maxdep[a] = dep[a];
    for (int v : V[a]) {
      if (v == f)
        continue;
      is[a] |= dfs(v, a);
      Maxdep[a] = max(Maxdep[a], Maxdep[v]);
    }
    return is[a];
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 12288
// Starting with the name of Allah

#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>\
#include<string>
using namespace std;
int main()
{
	char s[100];
	char t[100];
	cin>>s>>t;
	int l;
	l=strlen(s);
	if(strncmp(s,t,l)==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
using namespace std ;
int main()  {
  int a,b,c;

 cin>>a>>b>>c;
 
 if(a>b){
   swap(a,b);
    }
    if(b>c){
      swap(b,c);
    }
    if(a>b){
      swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}

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

//https://atcoder.jp/contests/agc010/tasks/agc010_b

const int nm = 1e5;
int n, a[nm];
long long s = 0, c, b[nm];

int main() {
	cin >> n;
	c = (long long) n * (n + 1) / 2;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}

	if (s % c) {
		cout << "NO" << endl;
		return 0;
	}

	for (int i = 0; i < n; i++)
		b[i] = a[(i + 1) % n] - a[i] - s / c;
	for (int i = 0; i < n; i++)
		if (b[i] > 0 || b[i] % n) {
			cout << "NO" << endl;
			return 0;
		}
	cout << "YES" << endl;
}


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

int main(){
    int a,b,t;
    cin >> a >> b >> t;
    int ans = 0;
    
    for(int i = 0; i < t+0.5; i++){
        if(i!=0 && i % a == 0){
            ans += b;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

const int mod = 1000000007;

int f[10001][2][101];

char c[10001];
int n, k;

int F(int i, bool isLess, int m)
{
    if (i==n)
        return m == 0;
    int &r = f[i][isLess][m],j;
    if (r == -1)
    {
        r = 0;
        if (isLess)
        {
            for ( j=0; j<=9; ++j)
                r = (r + F(i+1, true, (m+j)%k)) % mod;
        }
        else
        {
            for ( j=0; j<c[i]-'0'; ++j)
                r = (r + F(i+1, true, (m+j)%k)) % mod;
            r = (r + F(i+1, false, (m+j) %k)) % mod;
        }
    }
    return r;
}

int main()
{
    for (int i=0; i<=10000; ++i)
        for (int j=0; j<2; ++j)
            for (int k=0; k<=100; ++k)
                f[i][j][k] = -1;
    scanf ( "%s %d", c, &k);
    n = strlen(c);
    cout << (F(0,0,0) + mod - 1) % mod;;
    return 0;
}


Measured memory_bytes: 8960
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n;
	while(cin>>n){
	int ans=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				for(int l=0;l<10;l++){
					if(i+j+k+l==n)ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll a,b,c;

int main(){
	cin>>a>>c;
  b=2*c-a;
  cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
while True:
	m, f, r = map(int, input().split())
	if m == f == r == -1: break
	if m == -1 or f == -1: print("F")
	elif m + f >= 80: print("A")
	elif m + f >= 65: print("B")
	elif m + f >= 50: print("C")
	elif m + f >= 30:
		if r >= 50: print("C")
		else: print("D")
	else: print("F")

Measured memory_bytes: 7592
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>

using namespace std;

char nums[]={'3','5','7'};
string N;
long long n;

int dfs(string num,bool three,bool five,bool seven) {
    if(num.size()>N.size())return 0;
    if(atoi(num.c_str())>n){
        return 0;
    }
    int res=0;
    if(three&&five&&seven){
        res++;
    }
    res+=dfs(num+'3',true,five,seven);
    res+=dfs(num+'5',three,true,seven);
    res+=dfs(num+'7',three,five,true);
    return res;
}
int main() {
    int i;
    cin>>N;
    n=atoi(N.c_str());
    cout<<dfs("",false,false,false);
    return 0;
}

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

int main(){
    int N, D;
    cin >> N >> D;
    int p[N][D];
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            cin >> p[i][j];
        }
    }
    int ans = 0;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            double distance_square = 0;
            for(int k=0; k<D; k++){
                distance_square += pow(p[j][k] - p[i][k], 2);
            }
            double distance = sqrt(distance_square);
            if(ceil(distance) == floor(distance)) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

import math
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]

def f():
    for p in PrimeUtils.primes_sieve(math.ceil(math.sqrt(M))):
        if M % p == 0:
            for x in range(N, (M//2) + 1):
                if M % x == 0:
                    return M // x
            else:
                return 1
    return 1
print(f())

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string o, e, ans = "";
    cin >> o >> e;
    int sum = o.size() + e.size();
    for(int i = 0; i < sum; ++i){
        if(i % 2 == 1) ans += e.at(i / 2);
        else if(i % 2 == 0) ans += o.at(i / 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
H, W = map(int, input().split())
HW = [0] * H
for i in range(H):
  HW[i] = str(input())
#print(HW)
visited = [[0] * W for i in range(H)]
def bfs(x, y):
  #now = HW[x][y]
  if visited[x][y] == 1:
    return 0
  visited[x][y] = 1
  
  if HW[x][y] == ".":
    return 0
    
  queue = [[0, 1], [0, -1], [1, 0], [-1, 0]]
  tt = 0
  for i, j in queue:
    if (0 <= x + i < H) and (0 <= y + j < W):
      if HW[x + i][y + j] == "#":
        tt = 1
        #print(x, y, x + i, y + j, strock)
  if tt == 0:
    return 1
  return 0
  
for i in range(H):
  for j in range(W):
    #print(i, j)
    st = bfs(i, j)
    #print(st)
    if st == 1:
      print("No")
      quit()
      
print("Yes")
  
  
      
  
  
  

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

class segtree {
public:
    struct node {
        int mi, sum, mii;
        node() {}
        node(int mi, int sum, int mii) : mi(mi), sum(sum), mii(mii) {}
    };
private:
    int n, s, t;
    vector<node> tr;

    node f(node a, node b) {
        return node(min(a.mi, a.sum + b.mi), a.sum + b.sum, a.mi < a.sum + b.mi ? a.mii : b.mii);
    }
    const node ex = node(M, 0, -1);
    node q(int k, int l, int r) {
        return r <= s || t <= l ? ex : s <= l && r <= t ? tr[k]
                : f(q(k << 1 | 1, l, (l + r) >> 1), q((k + 1) << 1, (l + r) >> 1, r));
    }

public:
    segtree(int m) {
        n = 1;
        while (n < m) n <<= 1;
        tr.clear();
        tr.resize((n << 1) - 1, ex);
    }
    void update(int j, const int& x) {
        int i = j + n - 1;
        tr[i] = node(x, x, j);
        while (i > 0) { i = (i - 1) >> 1; tr[i] = f(tr[i << 1 | 1], tr[(i + 1) << 1]); }
    }
    // [s, t)
    node run(int _s, int _t) { s = _s; t = _t; return q(0, 0, n); }
};



int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    set<int> cp;
    segtree sg(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '(')
            sg.update(i, 1);
        else {
            sg.update(i, -1);
            cp.insert(i);
        }
    }
    for (int _ = 0; _ < q; ++_) {
        int t;
        cin >> t;
        --t;
        if (s[t] == '(') {
            cp.insert(t);
            sg.update(t, -1);

            s[t] = ')';

            int u = *cp.begin();
            cp.erase(cp.begin());
            sg.update(u, 1);

            s[u] = '(';
            cout << u + 1 << "\n";
        }
        else {
            cp.erase(t);
            sg.update(t, 1);

            s[t] = '(';

            segtree::node nod = sg.run(0, n);
            if (nod.mi == 0)
                nod = sg.run(nod.mii + 1, n);

            int u = nod.mii + 1;
            cp.insert(u);
            sg.update(u, -1);

            s[u] = ')';
            cout << u + 1 << "\n";
        }
    }
    return 0;
}



Measured memory_bytes: 22432
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
int main(void)
{
    string a,b;
    cin>>a>>b;
    for(int i = 0;i < a.length();i ++)
        if(b[i]!=a[i])
    {
        cout<<"No"<<endl;return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
struct edge{
	int to,next;
}e[400010];
int head[200010];
int n,m,nedge;
 inline void add(int a,int b)
{
	e[++nedge].to=b;
	e[nedge].next=head[a];
	head[a]=nedge;
}

 int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	for (int i=2;i<=n-1;++i)
	{
		bool f1=0,f2=0;
		for (int k=head[i];k;k=e[k].next)
		{
			if (e[k].to==1) f1=1;
			if (e[k].to==n) f2=1;
		}
		if (f1&&f2)
		{
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
} 

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

int main()
{
	fastIO;
	int n, x, t; cin >> n >> x >> t;
	int ans = 0;
	ans = n/x;
	ans *= t;
	if(n % x) ans += t;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
bool a[1000101];
int main()
{
	int n,m,k; cin>>n>>m>>k;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++){
			a[i*m+j*n-i*j*2]=1;
		}
	if(a[k]) printf("Yes"); else printf("No");
}

Measured memory_bytes: 1280
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        //配列の宣言
        int[] h = new int[n];

        for(int i = 0; i < n; i++){
            h[i] = sc.nextInt();
        }

        int l = 0, j, min, answer = 0;
        while(l < n){
            while(l < n && h[l] == 0){
                l++;
            }
            if(l == n) break;
            j = l;
            min = h[l];
            while(j < n && h[j] != 0){
                min = Math.min(h[j], min);
                j++;
            }
            for(int k = 0; k < j; k++){
                h[k] -= min;
            }
            answer += min;
        }

        // 出力
        System.out.println(answer);

    }

}

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

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

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

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

    vector<ll>h(n);
    rep(i,n){
        cin>>h[i];
    }

    if(n<=k){
        cout<<0<<endl;
        return 0;
    }

    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());

    ll ans=0;

    for (ll i=k;i<n;i++) {
        ans+=h[i];
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;

using ll = long long;

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int ans = 0;
  while(x>0 && y>0){
    if((a + b) < 2*c){
      ans += a;
      ans += b;
      x -= 1;
      y -= 1;
    }
    else{
      ans += 2*c;
      x -= 1;
      y -= 1;
    }
  }

  while(x>0){
    if(a < 2*c){
      ans += a;
      x--;
    }
    else{
      ans += 2*c;
      x--;
    }
  }

  while(y>0){
    if(b < 2*c){
      ans += b;
      y--;
    }
    else{
      ans += 2*c;
      y--;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

inline ll read()
{
    ll ret=0,flag=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
    while(c>='0'&&c<='9')ret=ret*10+(c^'0'),c=getchar();
    return flag*ret;
}

const int N=1e3+5,H=1e4+5;
int h,n;
int a[N],b[N];
int dp[H];

int main()
{
    h=read(),n=read();
    for(int i=1;i<=n;i++)a[i]=read(),b[i]=read();
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<a[i];j++)dp[j]=min(dp[j],b[i]);
        for(int j=a[i];j<=h;j++)dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
    }
    printf("%d",dp[h]);
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<int, string> P;

string test_str = "A35k4iY0PLUiCqSjimYK9vbYqxAFGVOzCT2jsjLcPhEL3e4x5BFjlMk5NcCjLKrgXrmRwbbK3X54yPH9goWZMQvv5dSXyaAiA6ZoJrrcjZs1VCcGcC69fNXZsBRna4jD";
int query_cou = 0;

int dp[222][222];
int LS(string a,string b)
{
	REP(i, 222)REP(j, 222)dp[i][j] = 0;
	REP(i,a.size()+1)dp[i][0]=i;
	REP(i,b.size()+1)dp[0][i]=i;
	for(int i=1;i<=a.size();i++)
	{
		for(int j=1;j<=b.size();j++)
		{
			int q=1;if(a[i-1]==b[j-1])q = 0;
			dp[i][j]=min(min(dp[i-1][j-1]+q,dp[i][j-1]+1),dp[i-1][j]+1);
		}
	}
	return dp[a.size()][b.size()];
}

ll query(string str){
	query_cou++;
	cout << "? " << str << endl;
	//return LS(str, test_str);

	ll ret;cin >> ret;
	return ret;
}

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

	ll L = 128;
	string index = "";
	for(char c = 'a';c <= 'z';c++)index += c;
	for(char c = 'A';c <= 'Z';c++)index += c;
	for(char c = '0';c <= '9';c++)index += c;

	priority_queue<P, vector<P>, greater<> > pq;
	ll string_length = 0;
	REP(i, index.size()){
		ll num = L - query(string(L, index[i]));
		pq.push(MP(num, string(num, index[i])));
		string_length += num;
	}

	while(pq.size() > 1){
		auto a = pq.top();pq.pop();
		auto b = pq.top();pq.pop();

		string now = a.SE;
		ll pla = 0;
		ll cou = 0;

		while(cou < b.FI){
			string tmp = now;
			tmp.insert(pla, 1, b.SE[cou]);
			ll ret = query(tmp);
			if(ret == string_length - tmp.size()){
				now = tmp;
				cou++;
			}
			pla++;
		}
		pq.push(MP(now.size(), now));
	}

	cout << "! " << pq.top().SE << endl;
	//cout << "query " << query_cou << endl;

	return 0;
}


Measured memory_bytes: 3808
#include <vector>
#include <iostream>

using namespace std;

int N, M;
bool e[8][8];
int ans = 0;
int p[8];

void dfs(int pos, int mask) {
		if (pos == N) {
				for (int i = 0; i < N-1; i++) {
						if (p[0] != 0) return;
						else if (!e[p[i]][p[i+1]]) return;
				}
				ans++;
				return;
		}

		for (int i = 0; i < N; i++) {
				if (mask & (1<<i)) {
						p[pos] = i;
						dfs(pos+1, (mask^(1<<i)));
				}
		}
}

int main() {
		cin >> N >> M;
		vector<int> v[N];
		for (int i = 0; i < M; i++) {
				int a, b;
				cin >> a >> b;
				a--; b--;
				e[a][b] = true;
				e[b][a] = true;
		}

		dfs(0, (1<<N) - 1);
		cout << ans << endl;
		return 0;
}


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

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

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        while (a[i] % 2 == 0)
        {
            ans++;
            a[i] /= 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line;
            int i = 1;
            while((line = br.readLine()) != null){
                if(line.equals("0")){
                    break;
                }
                System.out.println("Case " + i + ": " + line);
                i++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 31964
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1000119
int num[maxn],tree[maxn],booll[maxn],nnn[maxn],N,ww;;
//num数组保存原数列，tree树状数组，nnn保存结果
struct tt
{
    int l,r;//左右边界
    int pos;//原位置（因为我们要离线排序后处理）
};
tt ask[maxn];
bool cmp(tt x,tt y)
{ 
    return x.r<y.r;
    //快排大法好，没有什么是快排解决不来哦
    //实在不行就加上一个cmp
}
int lowbit(int n) 
{
    return n&(-n);
    //树状数组核心操作×1
}
void add(int n,int now)
{
    while(n<=N)
    {
        tree[n]+=now;
        n+=lowbit(n);
    }
    //树状数组核心操作×2-->更新操作
}
int sum(int n)
{
    int ans=0;
    while(n!=0)
    {
        ans+=tree[n];
        n-=lowbit(n);
    }
    return ans;
    //树状数组核心操作×3———>查询操作
}
int main()
{
        scanf("%d",&N);
        scanf("%d",&ww);
        for(int i=1;i<=N;i++)
            scanf("%d",&num[i]);
        for(int i=1;i<=ww;i++)
        {
            scanf("%d%d",&ask[i].l,&ask[i].r);
            ask[i].pos=i; //存储初始位置
        }
        sort(ask+1,ask+1+ww,cmp);//按r排序
        int next=1;
        for(int i=1;i<=ww;i++)
        {
            for(int j=next;j<=ask[i].r;j++)
            {
                if(booll[num[j]]) 
                    add(booll[num[j]],-1);
                 //之前打过标记，在之前的位置加上-1，保证无重复
                add(j,1);
                booll[num[j]]=j;
            }
            next=ask[i].r+1;
            //更新下一次查询的位置
            nnn[ask[i].pos]=sum(ask[i].r)-sum(ask[i].l-1);
            //按询问编号存储每组询问的结果
        }
    for(int i=1;i<=ww;i++)
      cout<<nnn[i]<<endl;
    return  0;
}

Measured memory_bytes: 17360