akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(){
    int w,h,bottom=0,left=0,n;
    cin>>w>>h>>n;
    int x[n],y[n],a[n];
    rep(i,0,n)cin>>x[i]>>y[i]>>a[i];
    rep(i,0,n){
        if(a[i]==1){
            if(left<x[i])left=x[i];
        }else if(a[i]==2){
            if(w>x[i])w=x[i];
        }else if(a[i]==3){
            if(bottom<y[i])bottom=y[i];
        }else{
            if(h>y[i])h=y[i];
        }
    }
    cout<<max(w-left,0)*max(h-bottom,0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 2e5 + 10;
char c[N];
stack<int> r;
queue<int> w;
int main(){
	int n;
	scanf("%d %s",&n, c + 1);
	for(int i = 1; i <= n; i++){
		if(c[i] == 'R') r.push(i);
		else w.push(i);
	}
	int cnt = 0;
	while(!r.empty() && !w.empty()){
		if(r.top() < w.front()) break;
		cnt++;
		r.pop(), w.pop();
	}
	printf("%d", cnt);


}

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

using namespace std;

int main(){
  int N;
  long long x;
  cin >> N >> x;
  vector<long long> a;
  for (int i = 0; i < N; i++){
    long long tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  sort(a.begin(), a.end());
  int ans=0;
  for (int i = 0; i < N; i++){
    if (x - a[i] < 0){
      break;
    }
    x -= a[i];
    ans++;
  }
  if (x==0){
    printf("%d\n",ans);
  }else if(ans==N && x > 0){
    printf("%d\n",ans-1);
  }else{
    printf("%d\n",ans);
  }
  
}


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

#define N 100010
int main()
{
    int n, m, h[N], ma[N];

    cin >> n >> m;

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

        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }
    int ans = 0;

    for (int i = 1; i <= n;i++)
    {
        ans += h[i] > ma[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4380
#include<iostream>


#define maxn 100005
#define ll long long
using namespace std;

ll DP[maxn];
int N, K;
int height[maxn];

ll min(ll a, ll b)
{
    if(a <= b) return a;
    return b;
}

ll cal(int pos)
{
    if (pos == N - 1) return 0LL;


    ll &res = DP[pos];

    if (res != -1) return res;
    res = abs(height[pos + 1] - height[pos]) + cal(pos + 1);
    for (int i = 2; i <= K; i++)
    {
        if (pos + i < N)
        {
            res = min(res, abs(height[pos + i] - height[pos]) + cal(pos + i));
        }
    }

    return res;
}


int main()
{

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

    for (int i = 0; i < maxn; i++)
    {
        DP[i] = -1;
    }

    cout << cal(0) << endl;

    return 0;
}


Measured memory_bytes: 6144
#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 ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

struct Set {
	multiset <int> st;
	ll s = 0;
	void add(int x) {
		s += x;
		st.insert(x);
	}
	int pop_back() {
		int val = *(--st.end());
		s -= val;
		st.erase(--st.end());
		return val;
	}
	int pop_front() {
		int val = *st.begin();
		s -= val;
		st.erase(st.begin());
		return val;
	}
	int front() {
		return *st.begin();
	}
	int back() {
		return *(--st.end());
	}
	int size() {
		return st.size();
	}
	bool empty() {
		return st.empty();
	}
	void dbg() {
		cout << "sum " << s << '\n';
		for (int i : st) {
			cout << i << ' ';
		}
		cout << '\n';
	}
};

Set A, B;

void add(int x) {
	if (!B.empty() && B.front() <= x) {
		B.add(x);
	}	else {
		A.add(x);
	}
	while (A.size() - B.size() > 1) {
		B.add(A.pop_back());
	}
	while (A.size() < B.size()) {
		A.add(B.pop_front());
	}
	//cout << "A ";
	//A.dbg();
	//cout << "B ";
	//B.dbg();
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	ll C = 0;
	
	int q;
	cin >> q;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int a, b;
			cin >> a >> b;
			add(a);
			C += b;
		}	else {
			ll val = A.back();
			cout << val << ' ' << val * A.size() - val * B.size() - A.s + B.s + C << '\n';
		}
	}
}


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


int cmp(const void *p,const void *q)
{
    return *(int *)q - *(int *)p;
}

int main()
{
    int n,k,anum,sum=0;
    int i,j,l,lsum=0,flag=0;
    int a[510]={0};
    int moda[510]={0};
    int test,modsum=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&anum);
        sum+=anum;
        a[i]=anum;
    }

    int div=0;
    while(flag==0) {
        do
        {
            div++;
        }while (sum % div != 0);
        test = sum / div;
        //printf("test:%d\n",test);

        modsum=0;
        for (i = 0; i < n; i++) {
            moda[i] = a[i] % test;
            modsum += moda[i];
        }
        qsort(moda, n,sizeof(int), cmp);
        if (modsum % test == 0)flag = 1;
        else {
            flag = 0;
            continue;
        }
        lsum = 0;
        for (l = 0; l < modsum / test; l++)lsum += moda[l];
        if (modsum - lsum <= k)flag = 1;
        else flag = 0;
        //printf("%d %d\n",modsum,lsum);
    }
    printf("%d",test);
    return 0;
}



Measured memory_bytes: 252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

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


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stdio.h>

int main(void){
  std::string s,t;
  int c=0,n;
  std::cin >> s >> t;
  n=s.size();
  for(int i=0;i < n;i++){
    if(s[i]!=t[i]){
      c++;
    }
  }
  std::cout << c;

  return 0;
}

Measured memory_bytes: 3912
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int h, w; cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  vector<vector<char> > v(h, vector<char>(w, '0'));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        v[i][j] = '#';
        if(i - 1 >= 0){
          v[i - 1][j] != '#' ? v[i - 1][j]++ : 0;
          if(j - 1 >= 0) v[i - 1][j - 1] != '#' ? v[i - 1][j - 1]++ : 0;
          if(j + 1 < w) v[i - 1][j + 1] != '#' ? v[i - 1][j + 1]++ : 0;
        }
        if(i + 1 < h){
          v[i + 1][j] != '#' ? v[i + 1][j]++ : 0;
          if(j - 1 >= 0) v[i + 1][j - 1] != '#' ? v[i + 1][j - 1]++ : 0;
          if(j + 1 < w) v[i + 1][j + 1] != '#' ? v[i + 1][j + 1]++ : 0;
        }
        if(j - 1 >= 0) v[i][j - 1] != '#' ? v[i][j - 1]++ : 0;
        if(j + 1 < w) v[i][j + 1] != '#' ? v[i][j + 1]++ : 0;
      }
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << v[i][j];
    }
    cout << endl;
  }
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();

		Scanner sc = new Scanner(System.in);
		main.solve(sc);
		sc.close();
	}

	void solve(Scanner sc) {
		int K = sc.nextInt();
		int S = sc.nextInt();

		int count = 0;

		for (int x = 0; x <= K; x++) {
			for (int y = 0; y <= K; y++) {
				if (S - x - y <= K && S >= x + y) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <string>
#include <locale>
#include <stack>
#include <map>
using namespace std;

void funcPulas(int &a,const int &b) {
	 a += b;
}
void funcSub(int & a,const int &b) {
	 a -= b;
}
void funcMul(int &a, const int &b) {
	a *= b;
}

typedef
map<string, void(*)(int&,const int&)> map_typ;


int main(void)
{

	map_typ functio;

	functio.insert(make_pair("*", funcMul));
	functio.insert(make_pair("-", funcSub));
	functio.insert(make_pair("+", funcPulas));

	stack<int> por;

	string str;

	while (cin >> str)
	{
		if (str == "0")break;
		if (isdigit(str[0]))
			por.push(atoi(str.c_str()));
		else {
			map_typ::iterator it = functio.find(str);
			int b = por.top();
			por.pop();
			int a = por.top();
			por.pop();
			it->second(a, b);
			por.push(a);

		}
	}

	cout << por.top() << endl;



	return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  int A[2][N];
  for(int i=0; i<N; i++)
    cin >> A[0][i];
  for(int i=0; i<N; i++)
    cin >> A[1][i];
  int sum[2][N];
  sum[0][0] = A[0][0];
  sum[1][N-1] = A[1][N-1];
  for(int i=1; i<N; i++)
    sum[0][i] = sum[0][i-1] + A[0][i];
  for(int i=N-2; i>=0; i--)
    sum[1][i] = sum[1][i+1] + A[1][i];
  int ret = 0;
  for(int i=0; i<N; i++){
    int tmp = sum[0][i] + sum[1][i];
    if(tmp > ret)
      ret = tmp;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    if((100*r + 10*g + b)%4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int h, w;
char c[1005][1005];

int main () {
	cin >> h >> w;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> c[i][j];
		}
	}
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(c[i][j] == '.') {
				int cnt = 0;
				if(c[i-1][j-1] == '#') {
					cnt++;
				}
				if(c[i-1][j] == '#') {
					cnt++;
				}
				if(c[i-1][j+1] == '#') {
					cnt++;
				}
				if(c[i][j-1] == '#') {
					cnt++;
				}
				if(c[i][j+1] == '#') {
					cnt++;
				}
				if(c[i+1][j-1] == '#') {
					cnt++;
				}
				if(c[i+1][j] == '#') {
					cnt++;
				}
				if(c[i+1][j+1] == '#') {
					cnt++;
				}
				cout << cnt;
			}
			if(c[i][j] == '#') {
				cout << '#';
			}
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Char (isSpace)
import qualified Data.Vector as V

m :: Integer
m = 10 ^ 18

pr :: Integer -> Integer -> Maybe Integer
pr a b = let x = a * b in if x > m then Nothing else Just x

main :: IO ()
main = do
  _ <- getLine
  xs <- V.unfoldr (B.readInteger . B.dropWhile isSpace) <$> B.getLine
  print $
    if elem 0 xs
      then 0
      else maybe (-1) id $ foldM pr 1 xs

Measured memory_bytes: 22308
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int r, D, x0;
  std::cin >> r >> D >> x0;

  // Main

  int x_pre = x0;
  for (int i = 1; i <= 10; ++i) {
    int x = r * x_pre - D;
    x_pre = x;
    std::cout << x << std::endl;
  }

  // Output

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1; j <= s.length(); j++) {
                String a = s.substring(i, j);
                boolean able = true;
                for (int k = 0; k < a.length(); k++) {
                    if(a.substring(k, k+1).equals("A")) continue;
                    if(a.substring(k, k+1).equals("T")) continue;
                    if(a.substring(k, k+1).equals("C")) continue;
                    if(a.substring(k, k+1).equals("G")) continue;
                    able = false;
                    break;
                }
                if(able) ans = Math.max(ans, a.length());
            }
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 25300
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String l = sc.next();
        String[] sp = l.split("");
        int[] n = new int[4];
        for(int i=0; i<4; i++) {
            n[i] = Integer.parseInt(sp[i]);
        }
        String[] op = new String[3];
        int ans = n[0];
        for(int i=0; i<8; i++) {
            ans = n[0];
            for(int j=0; j<3; j++) {
                if((1 & i >> j) == 1) {
                    ans += n[j+1];
                    op[j] = "+";
                }else {
                    ans -= n[j+1];
                    op[j] = "-";
                }
            }
            if(ans == 7) {
                break;
            }
        }
        System.out.println(n[0]+op[0]+n[1]+op[1]+n[2]+op[2]+n[3]+"=7");
    }
}

Measured memory_bytes: 21588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[]) {
  int k, x, i;

  scanf("%d %d", &k, &x);

  for (i = x-k+1; i < x+k-1; i++) {
    printf("%d ", i);
  }
  printf("%d\n", i);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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,m; cin>>n>>m;
    vector<ll> a(n), b(n), x(m), y(m);
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,m) cin>>x[i]>>y[i];
    rep(i,n){
        ll tmp=1e10, res=-1;
        rep(j,m){
            if(abs(x[j]-a[i])+abs(y[j]-b[i]) < tmp){
                tmp=abs(x[j]-a[i])+abs(y[j]-b[i]);
                res=j+1;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;

int t;

int main()
{
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout); 
    string s,t,u;
    int a,b;
    while(cin>>s>>t) {
        cin>>a>>b;
        cin>>u;
        if(u==s)
            cout<<a-1<<" "<<b<<endl;
        else
            cout<<a<<" "<<b-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
object Main extends App{
  import scala.io.StdIn.readLine;
    val compare : String => String = (s:String) => {
      val nums = s.split(" ").map(_.toInt)
      if(nums(0) < nums(1)) s"a < b" 
      else if(nums(0) == nums(1)) s"a == b" 
      else s"a > b"
    }
    val a = readLine()
    println(compare(a))
}



Measured memory_bytes: 43828
#include <stdio.h>

typedef struct {
  int a, b, c, d, e, f;
} DICE;

int main()
{
  DICE p, q, r;
  scanf("%d %d %d %d %d %d\n", &p.a, &p.b, &p.c, &p.d, &p.e, &p.f);
  scanf("%d %d %d %d %d %d\n", &q.a, &q.b, &q.c, &q.d, &q.e, &q.f);
  
  for (int i=0; i<4; i++) {
    r.a = q.b;    r.e = q.a;    r.f = q.e;
    r.b = q.f;    r.c = q.c;    r.d = q.d;
    q = r;
    for (int j=0; j<4; j++) {
      r.b = q.d;      r.c = q.b;      r.e = q.c;
      r.d = q.e;      r.a = q.a;      r.f = q.f;
      q = r;
      for (int k=0; k<4; k++) {
	r.a = q.b;	r.e = q.a;	r.f = q.e;
	r.b = q.f;	r.c = q.c;	r.d = q.d;
	q = r;
	if (p.a == q.a && p.b == q.b && p.c == q.c &&
	    p.d == q.d && p.e == q.e && p.f == q.f) {
	  puts("Yes");
	  return 0;
	}
      }
    }
  }
  puts("No");
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
    using namespace std;
        int main() {
        	long long N;
    		cin >> N;

			long long result = 0;
			for(int i = 1; i <= N; i++){
				if(i % 3 != 0 && i % 5 != 0){
					result += i;
				}			
        	}
			cout << result << endl;
        }

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

int main(){
    int n; cin>>n;
    int a[100010];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,greater<int>());
    vector<int> v;
    for(int i=0;i<n-1&&v.size()<2;i++){
        if(a[i]==a[i+1]){
            v.push_back(a[i]);
            i++;
        }
    }
    if(v.size()<2)cout<<0<<endl;
    else cout<<(ll)v[0]*v[1]<<endl;
}


Measured memory_bytes: 640
n=int(input())
t0=0
x0=0
y0=0
ok=True
for i in range(n):
  t1,x1,y1=map(int,input().split())
  c=t1-t0-x1+x0-y1+y0
  if c<0 or c%2==1:
    ok=False
    break
print('Yes' if ok else 'No')

Measured memory_bytes: 3060
#include <string>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;

void b_make_triangle(void) {
    int n;
    int l[110];
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> l[i];

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            for (int k = j+1; k <= n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if((l[i]+l[j]>l[k])&&(l[j]+l[k]>l[i])&&(l[k]+l[i]>l[j]))
                        cnt++;
                }
            }
        }
    }

    cout << cnt << endl;
}

int main()
{
    b_make_triangle();

    return 0;
}

Measured memory_bytes: 3632
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; (i)<(n); ++(i))
#define rep1(i, n) for(int i = 1; (i)<(n); ++(i))
#define rev_rep(i, n) for(int i = (n) - 1; (i) >= 0; --(i))
#define range(a, i, b) for(int i = (a); (i) < (b); ++(i))
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
#define readl(N) ll N; cin >> N
#define readlv(N, vec) vector<ll> vec(N); rep(i, N){cin >> vec[i];}
#define greater_than [](ll l, ll r){return l > r;}
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(ll i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::set<T>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T> inline bool chmin(T& a, T const b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T const b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll fact(ll n){
  ll res=1;
  while(n>=0){
    res*=n;
    n--;
  }
  return res;
}
    
ll pow(ll i, ll n){
  ll res=1;
  while(n>=0){
    res*=i;
    n--;
  }
  return res;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  readl(N);
  map<ll, ll> a;

  rep(i, N){
    ll x;
    cin >> x;
    a[x]++;
  }
  ll res = 0;
  for(auto&& x:a){
    if(x.second % 2){
      res++;
    }
  }
  cout << res << endl;
}
#endif


Measured memory_bytes: 6528
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		List<String> cur = new ArrayList<String>();
		for(int i = 0 ; i <= 9 ; ++i){
			cur.add(i + "");
		}
		if(K < cur.size()){
			System.out.println(cur.get(K));
			return ;
		}
		K -= (cur.size() - 1);
		for(int len = 2 ; len <= 10 ; ++len){
			List<String> next = new ArrayList<String>();
			for(int i = 1 ; i <= 9 ; ++i){
				for(String s : cur){
					int top = s.charAt(0) - '0';
					if(Math.abs(top - i) <= 1){
						next.add(i+s);
					}
				}
			}
			Collections.sort(next);
			if(K < next.size()){
				System.out.println(next.get(K - 1));
				return ;
			}
			K -= next.size();
			for(String s : cur){
				int top = s.charAt(0) - '0';
				if(top <= 1){
					next.add("0"+s);
				}
			}			
			cur = next;
		}
	}
}


Measured memory_bytes: 45664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> p;

const int INF = 1e9;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<bool>> wall(H, vector<bool>(W, false));
    rep(i,H) {
        string s;
        cin >> s;
        rep(j,W) {
            if (s[j] == '#') wall[i][j] = true;
        }
    }

    vector<int> dx(4), dy(4);
    dx[0] = 1;
    dx[1] = 0;
    dx[2] = -1;
    dx[3] = 0;
    dy[0] = 0;
    dy[1] = 1;
    dy[2] = 0;
    dy[3] = -1;

    int ans = 0;
    rep(i,H) {
        rep(j,W) {
            if (!wall[i][j]) {
                queue<p> que;
                que.push(make_pair(i,j));
                vector<vector<int>> far(H,vector<int>(W,INF));
                far[i][j] = 0;

                while(!que.empty()) {
                    p now = que.front();
                    int x, y;
                    x = now.first;
                    y = now.second;
                    rep(k,4) {
                        int x1, y1;
                        x1 = x + dx[k];
                        y1 = y + dy[k];
                        if (x1 < 0 || x1 >= H || y1 < 0 || y1 >= W) continue;
                        else {
                            if((!wall[x1][y1]) && far[x1][y1] == INF) {
                                far[x1][y1] = far[x][y] + 1;
                                ans = max(ans, far[x1][y1]);
                                que.push(make_pair(x1,y1));
                            }
                        }
                    }
                    que.pop();
                }
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,cnt;
ll dp[MAXN][3];
char s[MAXN];

int main(){
	scanf("%s",s+1); len = (int)strlen(s+1);
	for(int i=1; i<=len; i++){
		if(s[i] == '?'){
			dp[i][0] = (dp[i-1][0]*3+fpow(3,cnt,MOD))%MOD;
			dp[i][1] = (dp[i-1][1]*3+dp[i-1][0])%MOD;
			dp[i][2] = (dp[i-1][2]*3+dp[i-1][1])%MOD;
			cnt++;
		}else{
			for(int k=0; k<3; k++) dp[i][k] = dp[i-1][k];
			if(s[i] == 'A') dp[i][0] = (dp[i][0]+fpow(3,cnt,MOD))%MOD;
			else if(s[i] == 'B') dp[i][1] = (dp[i][1]+dp[i-1][0])%MOD;
			else dp[i][2] = (dp[i][2]+dp[i-1][1])%MOD;
		}
	}
	printf("%lld\n",dp[len][2]);
}


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

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

  int tmp[3];
  for (int i=0;i<3;i++) {
    tmp[i] = s % 60;
    s /= 60;
  }

  cout << tmp[2] << ":" << tmp[1] << ":" << tmp[0] << endl;
}



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

double a, b, res;

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

    cin >> a >> b;

    for (int i = 10 * b; i < 10 * (b + 1); ++i)
    {
        if (25 * a <= 2 * i && 2 * i < 25 * (a + 1))
        {
            cout << i << "\n";
            return 0;
        }
    }

    cout << -1 << "\n";
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll N;
  cin >> N;
  ll A = (10e+8)+7;
  ll B= 1; ll C=1;ll D=1;
  for(int i = 0; i < N; i++){
    B = (B*10)%A;
    C = (C*8)%A;
    D = (D*9)%A;
  }
  
  int x = (B+C)%A;
  int y = (2*D)%A;

  cout <<(x-y+A)%A << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stack>

using namespace std;

int ask(int x,int y){
    cout << "? " << x << " " << y << endl;
    cout.flush();
    char c;
    cin >> c;
    return c == 'Y';
}
int main(){

    int a,b,r;
    stack <int> S;
    bool C[4567];

    cin >> a >> b;
    if(a <= b){
        cout << "Impossible";
        return 0;
    }

    int n = a + b;
    
    for(int i = 0; i < n; ++i){
        if(S.empty()) S.push(i);
        else{
            int j = S.top();
            if(ask(j,i)) S.push(i);
            else S.pop();
        }
    }

    int k = S.top();
    C[k] = 1;
    for(int i = 0; i < n; ++i) if(i != k){
        C[i] = ask(k,i);
    }

    cout << "! ";
    for(int i = 0; i < n; ++i) cout << C[i];

    return 0;
}

Measured memory_bytes: 724
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[][] map = new int[k][n+1];
		int p = 0;
		
		for(int i=0;i<k;i++){
			p = sc.nextInt();
			for(int j=0;j<p;j++){
				map[i][sc.nextInt()]++;
			}
		}
		
		int m = sc.nextInt();
		int a, b;
		int[] ans = new int[n+1];
		
		for(int i=0;i<m;i++){
			a = sc.nextInt();
			b = sc.nextInt();
			for(int j=0;j<k;j++){
				if(map[j][a]>0 && map[j][b]>0){
					ans[a]++;
					ans[b]++;
					break;
				}
			}
		}
		
		int count = 0;
		for(int i=0;i<n+1;i++){
			if(ans[i]>0) count++;
		}
		
		System.out.println(count);
	}	
}

Measured memory_bytes: 24320
/***
	chauhan176's code

	DO WHATEVER IT TAKES!!!
	Nothing happens , nothing happens and then everything happens.
	But the thing is nothing happens in air:)-
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define maxn 300005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stringio cin.ignore(256, '\n')  //to take string input after taking integer inputs
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

typedef pair<int,int>pi;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int mx = 1000007;
#define PI 3.14159265
int main()
{
    fastio;
    int a,b,x;
    cin>>a>>b>>x;


    double vol=2*x;
    vol = vol/(double)(a*b);
    if(vol<=a){
    double p = (double)b , base = vol;
    double param = p/base;
    //trace3(p,base,param);
    cout<<fixed<<setprecision(10)<<(atan(param)*180)/(PI)<<endl;
    }
    else
    {
        double rhs = a*a*b - x;
        double side = 2*rhs;
        side = side/(double)(a*a);
        double p = (double)a , base = side;
        double param = p/base;
        //trace3(p,base,param);
        double ans = 90 - (atan(param)*180)/(PI);
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// tourist氏.
// https://atcoder.jp/contests/arc098/submissions/2563033
// 正答者の解答を勉強する.
#include <bits/stdc++.h>
using namespace std;

int main(){
    
    // 1. 入力情報取得.
    int N, K, Q;
    scanf("%d %d %d", &N, &K, &Q);
    vector<int> A(N);
    for(int i = 0; i < N; i++) scanf("%d", &A[i]);
    
    // 2. X - Y の 最小値 を 求める.
    int ans = (int)2e9;
    for(int bound : A){
        vector<int> c;
        multiset<int> s;
        for(int i = 0; i <= N; i++){
            if (i == N || A[i] < bound){
                sort(c.begin(), c.end());
                for(int j = 0; j <= (int)c.size() - K; j++) s.insert(c[j]);
                c.clear();
            }else{
                c.push_back(A[i]);
            }
        }
        if((int)s.size() < Q) continue;
        auto it = s.begin();
        for(int i = 0; i < Q - 1; i++) it++;
        ans = min(ans, *it - bound);
    }
    
    // 3. 出力 ～ 後処理.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <stdio.h>

using namespace std;

#define MAX 1000000
#define NIL -1

typedef struct Node{int p, l, r;}Node;
int n;
Node node[MAX];

void preorder(int now_node){
    cout << " " << now_node;
    if(node[now_node].l != NIL)preorder(node[now_node].l);
    if(node[now_node].r != NIL)preorder(node[now_node].r);
}
void inorder(int now_node){
    if(node[now_node].l != NIL)inorder(node[now_node].l);
    cout << " " << now_node;
    if(node[now_node].r != NIL)inorder(node[now_node].r);
}
void postorder(int now_node){
    if(node[now_node].l != NIL)postorder(node[now_node].l);
    if(node[now_node].r != NIL)postorder(node[now_node].r);
    cout << " " << now_node;
}

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    cin >> n;
    for(int i=0; i<n; i++)node[i].p = node[i].l = node[i].r = NIL;
    for(int i=0; i<n; i++){
        int tmp_n, tmp_l, tmp_r;cin >> tmp_n >> tmp_l >> tmp_r;
        node[tmp_n].l = tmp_l;
        node[tmp_n].r = tmp_r;
        if(tmp_l!=NIL)
            node[tmp_l].p = tmp_n;
        if(tmp_r!=NIL)
            node[tmp_r].p = tmp_n;
    }
    int root_node_num = 0;
    for(int i=0; i<n; i++){
        if(node[i].p == NIL){
            root_node_num = i;
            break;
        }
    }
    
    cout << "Preorder"<< endl;
    preorder(root_node_num);
    cout << endl;
    cout << "Inorder"<< endl;
    inorder(root_node_num);
    cout << endl;
    cout << "Postorder"<< endl;
    postorder(root_node_num);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3104
import java.util.*;

class Main {

   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int c = Integer.parseInt(sc.next());
      int cnt = 0;
      for (int i = a; i <= b; i++) {
         if (c % i == 0)
            cnt++;
      }
      System.out.printf("%d\n", cnt);
   }
}

Measured memory_bytes: 17324
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int aka[345678], ao[345678], mu[345678], cnt[345678];
signed main() {
	int x, y, a, b, c, d = 0, ans = 0; cin >> x >> y >> a >> b >> c;
	for (int h = 0; h < a; h++) { cin >> aka[h]; }
	sort(aka, aka + a); reverse(aka, aka + a);
	for (int h = 0; h < b; h++) { cin >> ao[h]; }
	sort(ao, ao + b); reverse(ao, ao + b);
	for (int h = 0; h < c; h++) { cin >> mu[h]; }
	sort(mu, mu + c); reverse(mu, mu + c);
	for (int h = 0; h < x; h++) { cnt[d] = aka[h]; d++; }
	for (int h = 0; h < y; h++) { cnt[d] = ao[h]; d++; }
	for (int h = 0; h < x + y; h++) { cnt[d] = mu[h]; d++; }
	sort(cnt, cnt + d); reverse(cnt, cnt + d);
	for (int h = 0; h < x + y; h++) { ans += cnt[h]; }
	cout << ans << endl;
	return 0;
}

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

int main()
{
int n;
  cin>>n;
  set<string>v;
  for(int i=0;i<n;i++)
  {
     string s;
    cin>>s;
    v.insert(s);
  }
  cout<<v.size()<<endl;
}

Measured memory_bytes: 19224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

template <class COST>
void warshall_floyd(vector<vector<COST>> &cost) { // cost[n][n]
	int n = cost.size();
	REP(k, n) REP(i, n) REP(j, n) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}

int main() {
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0); // cin??¨cout?????£????????????
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	while (true) {
		ll n, m; cin >> n >> m;
		if (n == 0) break;
		const ll MAX = 200000000ll;
		vvl path_l(n, vl(n, MAX));
		vvl path_s(n, vl(n, MAX));
		REP(i, m) {
			ll x, y, t; char sl;
			cin >> x >> y >> t >> sl; x--; y--;
			(sl == 'L' ? path_l : path_s)[x][y] = t;
			(sl == 'L' ? path_l : path_s)[y][x] = t;
		}
		REP(i, n) {
			path_l[i][i] = 0;
			path_s[i][i] = 0;
		}
		warshall_floyd(path_l);
		warshall_floyd(path_s);

		ll r; cin >> r;
		vl z(r); REP(i, r) { cin >> z[i]; z[i]--; }

		vvl dp(r, vl(n, MAX)); dp[0][z[0]] = 0;
		REP(i, r - 1) REP(j, n) REP(k, n) {
			ll dist = (j == k ? path_l[z[i]][z[i + 1]] : path_l[z[i]][j] + path_s[j][k] + path_l[k][z[i + 1]]);
			dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + dist);
		}

		ll ans = MAX;
		REP(i, n) ans = min(ans, dp[r - 1][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5140
// https://atcoder.jp/contests/agc008/tasks/agc008_b
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n + 1, 0);
    REP(i, n) cin >> v[i];
    ll sum = 0, now = 0, nowm = 0;
    REP(i, n) sum += max(0, v[i]);
    // 区間Kに含まれる0未満の合計が最小の区間を探す
    REP(i, k) {
        now += v[i];
        nowm += max(0, v[i]);
    }
    ll maxv = -INFL;
    REP(i, n - k + 1) {
        maxv = max(maxv, sum - nowm + max(0LL, now));
        now += v[i + k] - v[i];
        nowm += max(0, v[i + k]) - max(0, v[i]);
    }
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 640
'use strict';

function main(stdin) {
  const input = stdin.split(' ').map(v => { return parseInt(v, 10) });
  const R = input[0];
  const G = input[1];
  const B = input[2];
  const N = input[3];

  let ans = 0;

  for (let r = 0; r <= N; r += R) {
    for (let g = 0; g <= N - r; g += G) {
      if ((N - r - g) % B === 0) ++ans;
    }
  }

  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
"use strict";

function main(arg) {
  var a = arg.split("\n")[1].split(" ");
  var i = 0;

  while (a.every(function (e) {
    return e % 2 == 0;
  })) {
    i++;
    a = a.map(function (e) {
      return e / 2;
    });
  }
  console.log(i);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll n;
 sf(n);
 ll ar[n+1];
 for(ll i=1;i<=n;i++) sf(ar[i]);
 ll ans=0;
 for(ll i=2;i<=n;i++){
 	ans+=max(0ll,ar[i-1]-ar[i]);
 	ar[i]+=max(0ll,ar[i-1]-ar[i]);
 }
 pf(ans);
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

int main() {
	int n, m;
	cin >> n >> m;
	ll answer = n * (n - 1) / 2;
	answer += m * (m - 1) / 2;
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif*/
   string s;
   cin >> s;
   if(s[2]==s[3] && s[4]==s[5]){
      cout<<"Yes";
   }
   else{
      cout<<"No";
   }
   return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

bool isInc = false;
vector<int> a;

void check2(int i) {
	for (int k = i; k < a.size() - 1; k++) {
		if (a[k] != a[k + 1]) {
			if (a[k] < a[k + 1]) {
				isInc = true;
			}
			else {
				isInc = false;
			}
			break;
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n) {
		int num;
		cin >> num;
		a.pb(num);
	}
	int ans = 0;
	if (a.size() == 1) {
		cout << 1 << endl;
		return 0;
	}
	check2(0);
	for (int i = 1; i < a.size(); i++) {
		if (isInc) {
			if (a[i - 1] > a[i]) {
				ans++;
				if (a.size() - 1 < i + 1) break;
				check2(i);
			}
		}
		else {
			if (a[i - 1] < a[i]) {
				ans++;
				if (a.size() - 1 < i + 1) break;
				check2(i);
			}
		}
	}
	cout << ans + 1 << endl;
	return 0;
}



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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int[] a = new int[n + 1];
		a[0] = -1000000001;
		str = br.readLine().split(" ");
		for(int i = 0; i < n; i++) a[i + 1] = Integer.parseInt(str[i]);
		str = br.readLine().split(" ");
		int q = Integer.parseInt(str[0]);
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int k = Integer.parseInt(str[0]);
			int lb = 0;
			int ub = n + 1;
			while(ub - lb > 1){
				int mid = lb + (ub - lb) / 2;
				if(a[mid] >= k) ub = mid;
				else lb = mid;
			}
			System.out.print((ub - 1) + " ");
			lb = 0;
			ub = n + 1;
			while(ub - lb > 1){
				int mid = lb + (ub - lb) / 2;
				if(a[mid] > k) ub = mid;
				else lb = mid;
			}
			System.out.println(ub - 1);
		}
	}
}



Measured memory_bytes: 85244
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

#define x first
#define y second

typedef pair<int,int> pii;
typedef long long ll;

const ll MOD = 998244353;

ll sum(ll a, ll b)
{
    return (a + b) % MOD;
}
ll sub(ll a, ll b)
{
    return ((a - b) % MOD + MOD) % MOD;
}
ll mult(ll a, ll b)
{
    return (a * b) % MOD;
}

const int N = 2e5 + 5;

ll pw2[N], f[N];

int n;
pii p[N];
pii aY[N];
int ordX[N], ordY[N];

bool cmpX(int i, int j)
{
    return p[ordX[i]].x < p[ordX[j]].x;
}
bool cmpY(int i, int j)
{
    return p[ordY[i]].y < p[ordY[j]].y;
}


int t[N];

void init()
{
    for (int i = 0; i < n; ++i)
        t[i] = 0;
}
int get(int r)
{
	int res = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1)
		res += t[r];
	return res;
}
void upd(int i, int delta)
{
	for (; i < n; i = (i | (i + 1)))
		t[i] += delta;
}
int get(int l, int r)
{
	return get(r) - get(l - 1);
}


int main()
{
    //freopen("input.txt", "r", stdin);


    scanf("%d", &n);

    pw2[0] = 1;
    for (int i = 0; i < n + 3; ++i)
        pw2[i + 1] = mult(pw2[i], 2);
    for (int i = 0; i < n + 5; ++i)
        f[i] = sub(pw2[i], 1);

    for (int i = 0; i < n; ++i)
    {
        scanf("%d%d", &p[i].x, &p[i].y);
        ordY[i] = i;
    }

    sort(p, p + n);

    for (int i = 0; i < n; ++i)
        aY[i] = {p[i].y, i};
    sort(aY, aY + n);
    for (int i = 0; i < n; ++i)
        ordY[aY[i].second] = i;

    ll ans = mult(n, f[n]);
    for (int i = 0; i < n; ++i)
    {
        ans = sub(ans, f[i]);
        ans = sub(ans, f[n - i - 1]);
        ans = sub(ans, f[ordY[i]]);
        ans = sub(ans, f[n - ordY[i] - 1]);
    }
    init();
    for (int i = 0; i < n; ++i)
    {
        ans = sum(ans, f[get(0, ordY[i])]);
        ans = sum(ans, f[get(ordY[i], n - 1)]);
        upd(ordY[i], 1);
    }
    init();
    reverse(ordY, ordY + n);
    for (int i = 0; i < n; ++i)
    {
        ans = sum(ans, f[get(0, ordY[i])]);
        ans = sum(ans, f[get(ordY[i], n - 1)]);
        upd(ordY[i], 1);
    }


    printf("%lld", ans);
}


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

int main(){
    string s, t;
    bool flag = false;
    cin >> s >> t;
    for (int i = s.length() - t.length(); i >= 0;i--){
        for (int j = 0; j < t.length();j++){
            if(!(s[i+j]==t[j] || s[i+j]=='?')){
                break;
            }
            if(j==t.length()-1){
                flag = true;
                for (int k = 0;k< t.length();k++){
                    s[i + k] = t[k];
                }
                for (int k = 0; k < s.length();k++){
                    if(s[k] == '?'){
                        s[k] = 'a';
                    }
                }
            }
        }
        if(flag){
            break;
        }
    }
    if(flag){
        cout << s << endl;
    }
    else{
        cout << "UNRESTORABLE" << endl;
    }
        return 0;
}

Measured memory_bytes: 256