akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll N, K, ans = 0;
  cin >> N >> K;

  vector<ll> v(N);
  for (int i = 0; i < N; i++) cin >> v.at(i);
  
  sort(v.begin(), v.end(), greater<int>());

  for (int i = K; i < N; i++) ans += v.at(i);

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    int64_t m = A[0];
    int64_t ans = 0;
    for(int i=0; i<N; i++) {
        ans += max(m - A[i], 0L);
        m = max(m, A[i]);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define ll long long 
#define ull unsigned ll
#define db double
#define pii pair<int, int>

const int N = 3e5+5;
int n;
char s[N];
int dir[N];
int to_west[N], to_east[N];

int main() {
	scanf("%d %s", &n, s+1);
	int ans = 0x3f3f3f3f;
	for (int i = 1; i <= n; i++) {
		to_west[i] = to_west[i-1];
		to_east[i] = to_east[i-1];
		if (s[i] == 'E') to_east[i]++;
		else to_west[i]++;
	}
	for (int i = 1; i <= n; i++) {
		int turn = to_west[i-1] + to_east[n] - to_east[i];
		ans = min(ans, turn);
	}
	printf("%d\n", ans);
    return 0;
}

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

int main(){
  int N,s1,s2,g1,g2;
  string map;
  cin >> N >> s1 >> s2 >> g1 >> g2 >> map;
  s1--; s2--; g1--; g2--; // 1-indexed -> 0-indexed
  int left = s1;          // 仮定よりs1 < s2
  int right= max(g1, g2); // 仮定よりg1 != g2

  bool reachable= true;
  int leapable= INT_MAX;
  for(int i=right; i>left; i--){
    if(map.at(i)=='#' && map.at(i-1)=='#'){
      reachable= false;
      break;
    }
    if(i-1 >= s2 && map.at(i)=='.' && map.at(i-1)=='.' && map.at(i-2)=='.'){
      leapable= i-1;
    }
  }

  string ans= (reachable && (g1 < g2 || leapable <= g2)) ? "Yes" 
                                                         : "No";
  cout << ans << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
s = input()
n = len(s)
cnt = 1
ss = s[0]
l = 1
while l<n:
    r = l+1
    while r<n and ss==s[l:r]:
        r += 1
    if r==n and ss==s[l:r]:
        cnt -= 1

    ss = s[l:r]
    cnt += 1
    l = r

print(cnt)

Measured memory_bytes: 41564
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  int N; cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
     vec[i] -= i+1;
  }
  sort(ALL(vec));
  int M ((N%2 == 1)?vec[N/2]:(vec[N/2] + vec[N/2-1])/2);
  int res = 0;
  for (int t = 0; t < N; t++)
  {
    res += abs(vec[t] - M);
  }
  cout<<res<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 4784
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a != 1 && b != 1) {
    puts("1");
  } else if (a != 2 && b != 2) {
    puts("2");
  } else {
    puts("3");
  }
  return 0;
}

Measured memory_bytes: 256
N, X = gets.split.map(&:to_i)
m = []
gram = X
num = 0

N.times do
  tmp = gets.to_i
  m << tmp
  gram = gram - tmp
  num += 1
end
m.sort!

while (gram - m[0])>= 0 do
  gram = gram - m[0]
  num += 1
end
puts num

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define vi vector<int>
using namespace std;
int vis[1000][1000];
long long gn;
long long po(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b&1) return a*po(a*a,(b-1)/2);
    if(b&1^1)return po(a*a,b/2);
    return 1;
}
int vectoint(std::vector<int>v){
    reverse(v.begin(), v.end());
    long long p=0;
    for(int i=0;i<v.size();i++){
        p+=v[i]*po(2,i);
    }
return p;
}
int dp[100][100];
int print(int x,int y){
    if(x<=1){
            if(y>2 || y<=0)return 0;
            else return 1;
    }
  if(dp[x][y]!=0)return dp[x][y];
    else{

    return dp[x][y]=print(x-1,y)+print(x-1,y-1);
} }
void dele(stack<int>&s,int k){
    if(k==1){
        s.pop();
        return ;
    }
    int x=s.top();
    s.pop();
    dele(s,k-1);
    s.push(x);
    return;
}
void sort0(){

}
void finddup(){
    int arr[]={1,2,3,4,5,4};
    int tor=arr[0];
    int hare=arr[0];
    do{
        tor=arr[tor];
        hare=arr[arr[hare]];
    }
    while(hare!=tor);
    hare=arr[0];
    while(hare!=tor){
        hare=arr[hare];
        tor=arr[tor];
    }
    cout<<hare<<endl;
    return;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
    int t;
    // stack<int>s;
    // s.push(1);
    // s.push(111);
    // s.push(112);
    // s.push(112312);
    // s.push(12312);
    //  s.push(122);


    // cout<<s.size()<<endl;
    // stack<int>p=s;
    // while(!p.empty()){cout<<p.top()<<" ";p.pop();}
    // cout<<endl;
    // dele(s,(s.size()%2==0)?s.size()/2:(s.size()/2)+1);
    // cout<<s.size()<<endl;
    // while(!s.empty()){cout<<s.top()<<" ";s.pop();}
    //finddup();
    //sort0();
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes\n";
    else cout<<"No\n";
return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int N, M;

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

	long long int T = (N - M) * 100 + M * 1900;

	long long int num = 1;
	for (int i = 1; i <= M; i++) {
		num *= 2;
	}

	cout << num*T << endl;

	//system("pause");
	return 0;
}

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

namespace AtTest.EducationalDP
{
    class H
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] hw = ReadInts();
            int h = hw[0];
            int w = hw[1];
            bool[,] grid = new bool[h, w];
            for(int i = 0; i < h; i++)
            {
                string s = Read();
                for(int j = 0; j < w; j++)
                {
                    grid[i, j] = s[j] == '.';
                }
            }
            int[,] dp = new int[h, w];
            for (int i = 0; i < h; i++)
            {
                if (!grid[i, 0]) break;
                dp[i, 0] = 1;
            }
            for (int i = 0; i < w; i++)
            {
                if (!grid[0, i]) break;
                dp[0, i] = 1;
            }
            int mask = 1000000000 + 7;
            for(int i = 1; i < h; i++)
            {
                for(int j = 1; j < w; j++)
                {
                    if (!grid[i, j]) continue;
                    dp[i, j] = dp[i, j - 1] + dp[i - 1, j];
                    dp[i, j] %= mask;
                }
            }
            /*for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    Console.Write(dp[i, j] + " ");
                }
                Console.WriteLine();
            }*/
            Console.WriteLine(dp[h - 1, w - 1]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 19932
(let* ((arr (make-array (expt 10 5) :initial-element 0 :element-type 'fixnum)))
  (loop :repeat (read) :do (incf (aref arr (read))))
  (princ (loop :for k :from 1 :upto (- (expt 10 5) 2) :maximize (+ (aref arr (1- k))
                                                                   (aref arr k)
                                                                   (aref arr (1+ k))))))

Measured memory_bytes: 57952
puts case gets.chomp
when 'SUN'
  7
when 'MON'
  6
when "TUE"
  5
when "WED"
  4
when "THU"
  3
when "FRI"
  2
when "SAT"
  1
end
# SUN,MON,TUE,WED,THU,FRI,SAT


Measured memory_bytes: 1788
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int i = b - a - 2;
  printf("%d\n", (i+1)*(i+2)/2-a);
}

Measured memory_bytes: 128
def resolve():
    x1, y1, x2, y2 = list(map(int, input().split()))
    diff1 = y2-y1
    diff2 = x2-x1
    x3, y3 = x2 - diff1,  y2 + diff2
    x4, y4 = x1 - diff1,  y1 + diff2
    print(x3, y3, x4, y4)
        

if '__main__' == __name__:
    resolve()

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

int n;
int a[100001];
long long m = 0;

int main()
{
	cin >> n;

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

	int t = a[0];

	for (int i = 0; i < n; i++) {
		int b;

		cin >> b;

		if (t >= b) {
			m += b;
			t = a[i + 1];
		}
		else {
			t += a[i + 1];

			if (t < b) {
				m += t;
				t = 0;
			}
			else {
				m += b;
				t -= b;
			}
		}
	}

	cout << m << endl;

	return 0;
}

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

typedef class UnionFound {
	public:
		int n;
		int *f;
		int *w;

		void init(int n) {
			this->n = n;
			f = new int[(n + 1)];
			w = new int[(n + 1)];
			for (int i = 0; i <= n; i++) {
				f[i] = i;
			}
			fill(w, w + n + 1, 0);
		}
		
		int find(int x) {
			if (f[x] == x)
				return x;
			int y = f[x];
			f[x] = find(f[x]);
			w[x] ^= w[y];
			return f[x];
		}

		bool unit(int x, int y, int t) {
			int fx = find(x), fy = find(y);
			if (fx == fy) {
				return !(w[x] ^ w[y] ^ t);
			}
			w[fx] = w[x] ^ t;
			f[fx] = y;
			return true;
		}
} UnionFound;

int n;
int a[55];

int gap(int x, int y) {
	if (x > y)
		swap(x, y);
	return min(y - x, 24 - y + x);
}

bool check(int mid) {
	UnionFound uf;
	uf.init(n);
	for (int i = 0; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (gap(a[i], a[j]) < mid) {
				if (gap(a[i], 24 - a[j]) < mid) {
					return false;
				}
				if (!uf.unit(i, j, 1)) {
					return false;
				}
			} else if (gap(a[i], 24 - a[j]) < mid) {
				if (!uf.unit(i, j, 0)) {
					return false;
				}
			}
		}
	}
	return true;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		if (a[i] >= 12) {
			a[i] = 24 - a[i];
		}
	}
	int ans = 0;
	while (check(ans + 1)) {
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


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

int N;long long base=1000000007LL;

int main() {
  cin >> N;
  long long A[3][N];long long count=3LL;
  for (int i=0;i<N;i++) {
    for (int j=0;j<3;j++) {
      A[j][i]=0LL;
    }
  }
  for (int i=0;i<N;i++) {
    long long x;cin >> x;
    if (i==0) {
      A[0][0]=1LL;
      if (x!=0) count=0LL;
    }
    else {
      long long y=0LL;bool tuika=false;
      for (int j=0;j<3;j++) {
        if (A[j][i-1]==x) {
          y++;
          if (!tuika) {
            A[j][i]=A[j][i-1]+1LL;
            tuika=true;
          }
          else A[j][i]=A[j][i-1];
        }
        else A[j][i]=A[j][i-1];
      }
      count*=y;
      count=count%base;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main(void)
{
    int count = 0;
    string s;
    cin >> s;
    for(int i = 0;i<3;i++){if(s[i] == 'o'){count++;}}
    cout << 700 + count * 100 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <climits>

using namespace std;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define all(x) (x).begin(),(x).end()

// using int64 = long long;
typedef long long int64;




int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<set<int>> alpha(26);
    for (int i=0; i<n; i++) alpha[s[i] - 'a'].insert(i);

    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        int type; cin >> type;
        switch(type) {
            case 1:
                int i;
                char c;
                cin >> i >> c;
                alpha[s[i-1] -'a'].erase(i-1);
                alpha[c - 'a'].insert(i-1);
                s[i-1] = c;
                break;
            case 2:
                int l,r;
                cin >> l >> r;
                int ans = 0;
                for (int i=0; i<26; i++) {
                    auto it = alpha[i].lower_bound(l-1);
                    if (it != alpha[i].end() && *it < r) ans++;
                }
                cout << ans << endl;
                break;
        }
    }
}


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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
    if (A.size() == n + 1){
        int now = 0;
        for (int i = 0; i < q; i++){
            if (A[b[i]] - A[a[i]] == c[i]){
                now += d[i];
            }
        }
        ans = max(ans, now);
        return;
        //終了ということ
    }
    //末尾に数値を追加
    A.push_back(A.back());
    while (A.back() <= m){
        dfs(A);
        A.back()++;
    }
}
int main(void){
    cin >> n >> m >> q;
    a = b = c = d = vector<int> (q);
    for (int i = 0; i < q; i++){

        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int> (1, 1));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;


signed main() {

	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int m,d;
	cin>>m>>d;

		int ans=0;
		for(int j=22;j<=d;j++)
		{
			for(int i=1;i<=m;i++)
			{
				if((j%10)<2)
					continue;
				if((((j-(j%10))/10))<2)
					continue;

				if(((j%10)*((j-(j%10))/10))==i)
				{
					ans++;
					//cout<<j<<" "<<i<<endl;
				}
			}	
		}
		
		cout<<ans;
	

	
	return 0;
 
 }

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	cin >> n;
	double x = n / 2 + n % 2;
	cout << x / n;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

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

int main() {
  string N;
  cin >> N;
  int x = 0;
  for(int i = 0;i < N.length();++i){
    x += (int)(N[i] - '0');
  }
  
  if(x % 9 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint a(n);
  set<tuple<int,int>> reva;
  REP(i,n) {
    int x;
    cin>>x;
    a[i] = x;
    reva.emplace(x, i);
  }
  vector<vecint> g(n);
  REP(i,n-1) {
    int x,y;
    cin>>x>>y;
    --x;--y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<bool> ans(n, false);
  for (auto&&[x, i] : reva) {
    bool win = false;
    for (auto&& dest : g[i]) {
      if (a[dest] >= x) continue;
      if (!ans[dest]) {
        win = true;
      }
    }
    ans[i] = win;
  }
  bool first = true;
  REP(i,n) {
    if (ans[i]) {
      if (!first) cout << " ";
      else first = false;
      cout << (i+1);
    }
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

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

int main()
{
  int N, A[51] = {}, B[51] = {};
  bool graph[50][50] = {{}};

  cin >> N;
  for(int i = 0; i <= N; i++) cin >> A[i];
  for(int i = 0; i <= N; i++) cin >> B[i];

  if(accumulate(begin(A), end(A), 0) != N) fail();
  if(accumulate(begin(B), end(B), 0) != N) fail();
  vector< pair< int, int > > ventex;
  for(int i = 0; i <= N; i++) {
    while(B[i] > 0) {
      ventex.emplace_back(i, ventex.size());
      --B[i];
    }
  }

  int idx = 0;
  for(int i = N; i > 0; i--) {
    while(A[i] > 0) {
      sort(ventex.rbegin(), ventex.rend());
      int sz = i;
      for(auto &s : ventex) {
        if(s.first == 0) fail();
        --s.first;
        graph[idx][s.second] = true;
        if(--sz == 0) break;
      }
      --A[i];
      ++idx;
    }
  }

  cout << "YES" << endl;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      if(j > 0) cout << " ";
      cout << graph[j][i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	vector<int>p(n);
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> p.at(i);
	}
	int cnt = 0;
	for (i = 1; i < n - 1; i++)
	{
		if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1))
			cnt++;
		else if (p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1))
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
        int N,X,Y,i,j,d;
        cin >> N >> X >> Y;
        --X; --Y;
        vector<int> ans(N);
        for(i=0;i<N;i++){
                for(j=i+1;j<N;j++){
                        d = min(abs(j-i),abs(X-i)+abs(Y-j)+1);
                        d = min(d, abs(Y-i)+abs(X-j)+1);
                        ans[d]++;
                }
        }
        for(i=1;i<N;i++) cout << ans[i] << endl;
        return 0;
}

Measured memory_bytes: 256
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 3e5+123;
int n,a[100],ans;

void _case_()
{
   cin >> n;
   for(int i=0;i<n;i++)
       cin >> a[i];
   sort(a,a+n);
   for(int i=0;i<n;i++)
       for(int j=0;j<i;j++)
           for(int k=0;k<j;k++)
           {
               if (a[i] != a[j] and a[j] !=a[k] and a[k]+a[j]>a[i])
                   ans++;
           }
   cout << ans el;
}

int main()
{

    optimize();
    //_test_
      _case_();
    return 0;

}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int cmp(int a,int b){
    if(a!=b) return a>b;
}
int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3,cmp);
    cout<<a[0]*10+a[1]+a[2];
}

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

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long

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;
}

const long long INF = 1LL << 60;
ll dp[100005];

int main()
{
    int n, a, b, c, d, ans = 0;
    // ll h[100005];
    // scanf("%d", &n);
    scanf("%d%d", &a, &b);
    printf("%d\n", max(a + b, max(a - b, a * b)));
}

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


string s, t;
int dp[3010][3010];

int main() {
  cin >> s >> t;
  memset(dp,0,sizeof(dp));
  rep(i,s.size()) {
    rep(j,t.size()) {
      if(s[i]==t[j]) dp[i+1][j+1] = dp[i][j]+1;
      else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
    }
  }
  string ans;
  int i = s.size(), j = t.size();
  while(i>0&&j>0) {
    if(s[i-1]==t[j-1]) {
      ans += s[i-1];
      i--; j--;
    }
    else if(dp[i][j-1] < dp[i-1][j]) i--;
    else j--;
  }
  reverse(rng(ans));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 39004
import sys
N, M, X, Y = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
x.sort()
y.sort()
if X < Y:
    num = 0
    for Z in range(X+1, Y+1):
        num += 1
        if x[-1] < Z and y[0] >= Z:
            print('No War')
            sys.exit()
    if num == Y-X:
        print('War')
else:
    print('War')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<cstdlib>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,k) for(int i=0;i<k;i++)
ll n, m[22][22] = {}, i, j, k,h, o, l=0, z, sam = 0, p, q;
ll a[200005] = {} , inf = 1000000000000;
ll b[100005] = {};
ll g[10005];

string s[22];
ll t[100005], xx[100005];
char ss,st;
const int MAX =100005;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	cin >>h>>n;
	rep(i, n) {
		cin >> a[i] >> b[i];		
	}
	rep(i, 10003)g[i] = MOD;
	g[0] = 0;

	rep(i, h) rep(j, h) {
		k = i + a[j];
		if (k > h)k = h;
		if (g[k] > g[i] + b[j])g[k] = g[i] + b[j];
		
	}


	cout << g[h];
	return 0;
}

Measured memory_bytes: 4480
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
vector<int> G[200001];
void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >>m;
    for(int i=0;i<m;i++){
        int temp1, temp2;
        cin>>temp1>>temp2;
        add_edge(temp1,temp2);
    }
    for(int node:G[1]){
        for(int noden:G[node]){
            if(noden==n){
                cout<<"POSSIBLE"<<"\n";
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<"\n";

}


Measured memory_bytes: 12016
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int n, N, sn = 0, a = 0;
	cin >> n;
	N = n;
	while (N >= 10) {
		N /= 10;
		a++;
	}
	N = n;
	for (int i = a; i >= 0; i--) {
		int x = 1;
		FOR(j, i)x *= 10;
		sn += N / x;
		N %= x;
	}

	if (n%sn)cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(s) freopen(s".in", "r", stdin), freopen(s."out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 2200 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

/*


题意：每次从1~n往两边加数 每次 取的时候从两边取问第k个是1的情况 一共有多少是成立的

首先 我们可以通过观察得出 我1~n加数的这个数列 一定是一个v字形的这么一个序列 然后1在最中间 那么这样的话 我取到1的话是不是说明我前面的k-1一定可以是一个降序序列或者是两个降序序列 那么求一下这个个数我可以dp一下 设f[i][j]表示我已经填了前1~i这么多个位置了 我前面填过的数中最小的是j那我可以知道我现在其实是假设有两个栈 然后分别取数的方案数 比如 我取9 8 7 2

这样 如果下一个数一定要比我大的话 方案数 必须只能转移到当前空缺位置 的最大 否则就是无效的

或者可以选择转移到所有比我小的地方 累积一下方案数

相当于我这个dp要求这样的 有多少个 那么f[i+1][j]自然可以由上一层的f[i][j+1]+f[i+1][j+2]+….得到啊 然后针对这个做一个前缀和优化 变成n^2的情况然后转移的时候要注意一些细节 比如如果k是0的情况

然后那么只要前面k个都确定了 剩下的我是不是还是随便选啦 可以当作是dp 就是每次从两边选一个的方案数一共是多少 那么前面k个确定了 后面我随便放 方案数就是2^(n-k-1)种方案数 为什么呢 因为这次一定剩下的是一条递增的序列了 我想怎么取就怎么取

最后统计答案的时候我只需要把前k-1位的所有情况都取出来 然后后n-k让他随便排 乘一乘就好

*/

int f[N][N], s[N] ;
int n, k, ans ;

signed main(){
    scanf("%d%d", &n, &k) ;
    f[0][n + 1] = 1 ; s[n + 1] = 1 ;
	per(i, n, 1) s[i] = s[i + 1] + f[0][i] ;
	rep(i, 1, k - 1) {
		rep(j, 1, n - i + 1) f[i][j] = s[j] ;
		s[n + 1] = f[i][n + 1] ;
		per(j, n, 1) s[j] = (s[j + 1] + f[i][j]) % MOD ;
	}
	rep(i, 2, n + 1) (ans += f[k - 1][i]) %= MOD ;
	rep(i, 1, n - k - 1) (ans *= 2) %= MOD ;
	printf("%d\n", ans) ;


	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/



Measured memory_bytes: 18688
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return ;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int cnt[200010];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();
	for(int i=2;i<=n;i++)
	{
		int d=read();
		cnt[d]++;
	}
	for(int i=1;i<=n;i++)pr2(cnt[i]);
	return 0;
}

Measured memory_bytes: 2260
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let (_, K) = read!(usize, i64);
    let A = read![[i64]];
    let N = A.len();

    let mut u = 0_i64;
    let mut pair = 0_i64;
    for i in 0..N {
        for j in i + 1..N {
            if A[i] > A[j] {
                u += 1;
            }
        }

        for j in 0..N {
            if A[j] > A[i] {
                pair += 1;
            }
        }
    }
    debug!(u, pair, K * (K - 1) / 2);

    let v = (K * (K - 1) / 2) % P * pair % P;

    println!("{}", (u * K % P + v) % P)
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include <bitset>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<string>
typedef long long ll;
using namespace std;

int arr[200];
int main() {
	int n;
	int res = 0;
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + 2 * n);
	for (int i = 0; i < 2 * n; i = i + 2) {
		res += arr[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_map>
typedef long long int ll;
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<" "<<x<<"\n";
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
    cr7
        ll a, b, c, d; bool cr = 1, tr = 1;
    cin >> a >> b >> c >> d;
    for (ll i = 0; a!=0 || c!=0; i++) {
        if (i % 2 == 0) {
            c -= b;
            if (c <= 0) {
                cr = 0;
                break;
            }
        }
        else {
            a -= d;
            if (a <= 0) {
                tr = 0;
                break;
            }
        }
    }
    if (cr == 0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
const ll N = 2005;
const ll mod = 1e9+7;
ll num1[N],num2[N],a[N];
int main(){
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i-1;j++){
            if(a[i]<a[j]) num1[i]++;
        }
        for(int j=1;j<=n;j++){
            if(a[i]<a[j]) num2[i]++;
        }
    }
    for(int i=1;i<=n;i++){
        ans+=((k*(k-1)/2)%mod*num2[i]%mod+k%mod*num1[i]%mod)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int n, a, b;
  cin >> n >> a >> b;

  int sum = 0;
  for(int i = 1; i <= n; i++){
    int s = 0;
    int j = i;
    while(j != 0){
      s += j % 10;
      j /= 10;
    }
    if(s >= a && s <= b){
      sum += i;
    }
  }

  cout << sum << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

#define l first
#define r second

const int N = 1e5 + 10;

pi operator + (pi a, pi b) {
  if (a.l > b.r) return pi(a.l - b.r, a.r + b.r);
  if (a.r < b.l) return pi(b.l - a.r, a.r + b.r);
  return pi(0, a.r + b.r);
}

vector<int> g[N]; 
pi lim[N];
int siz[N], n, sum[N], dep[N];
char s[N];

void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  sum[u] = (s[u] == '1') ? dep[u] : 0;
  siz[u] = (s[u] == '1') ? 1 : 0; 
  lim[u] = pi(0, 0);
  for (auto v : g[u]) if (v != fa) {
    dfs(v, u);
    siz[u] += siz[v];
    lim[v].l += siz[v];
    lim[v].r += siz[v];
    lim[u] = lim[u] + lim[v];
    sum[u] += sum[v];
  }
//  cout << u << " " << lim[u].l << " " << lim[u].r << endl;
}

int main() {
  n = read();
  scanf("%s", s + 1);
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dep[0] = -1;
  int ans = n * n + 1;
  for (int i = 1; i <= n; i++) {
    dfs(i, 0);
    if (lim[i].l == 0 && sum[i] % 2 == 0) {
      ans = min(ans, sum[i] / 2);
//      cout << i << " ++ " << sum[i] << endl;
    }
  } 
  if (ans == n * n + 1) ans = -1;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	int a[3] = {0}, i, Count = 0;
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	while(a[0]!=a[1]||a[0]!=a[2]||a[1]!=a[2]){
		if(a[0]+2 <= a[1]){
			a[0]+=2;
		}else{
			a[0]+=1;
			a[1]+=1;
		}
		sort(a,a+3);
//		if(!(a[0]!=a[1]||a[0]!=a[2]||a[1]!=a[2])){
//			break;
//		}
		Count++;
//		for(i = 0; i < 3; i++){
//			cout << a[i] << " ";
//		}
//		cout<< endl;
	}
	cout << Count << endl;
	return 0;
} 
// 1 
// 1

Measured memory_bytes: 256
from collections import deque
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
q=deque()
q.append(a[0])
for i in range(1,n):
    x=q.popleft()
    ans+=x
    q.append(a[i])
    q.append(a[i])
print(ans)

Measured memory_bytes: 32512
a, b = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    n0 = str(i)
    n1 = ""
    for j in range(len(n0)):
        n1 = n0[j] + n1
    if n0 == n1:
        cnt += 1
print(cnt)

Measured memory_bytes: 2940
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().ToList().ConvertAll(Convert.ToInt32);
            if ( s[0] * s[1]  % 2 == 0){
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");
            }
            
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int const Max = 10010;
set<int> ys[Max];

constexpr int sq(int x) { return x * x; }

int main(){
  for(int N, M, R; cin >> N >> M >> R && N;) {
    rep(i, Max) ys[i].clear();

    rep(i, N) {
      int x, y; scanf("%d%d", &x, &y);
      ys[x].insert(y);
    }

    int ans = 0;
    for(;M--;) {
      int x, y; scanf("%d%d", &x, &y);
      REP(px, max(0, x - 4 * R), min(Max, x + 4 * R + 1)) {
        const int py = y - 4 * R;
        auto iter = ys[px].lower_bound(py);
        while(iter != ys[px].end() && *iter <= y + 4 * R) {
          ans += sq(px - x) + sq(*iter - y) <= 16 * R * R;
          iter ++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 8204
#include <stdio.h>
int a[1000],b[1000];
int main(){
	int N,M,i,c=1;
	while(1){
		c=1;
		scanf("%d %d",&N,&M);
			if(N==0&&M==0){
				return 0;
			}
		for(i=0;i<N;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<M;i++){
			scanf("%d",&b[i]);
		}
		for(i=0;i<M;i++){
			c+=b[i];
			if(c>=N){
				printf("%d\n",i+1);
				break;
			}
			c+=a[c-1];
			if(c>=N){
				printf("%d\n",i+1);
				break;
			}
			
		}
	}
}

Measured memory_bytes: 608
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll n;cin>>n;
  bool mae=false;
  bool usiro=false;
  if(n%100>=1 &&n%100<=12)usiro=true;
  if(n/100>=1 &&n/100<=12)mae=true;
  if(mae&&usiro)cout<<"AMBIGUOUS"<<endl;
  if(!(mae) &&!(usiro))cout<<"NA"<<endl;
  if(!(mae) &&usiro)cout<<"YYMM"<<endl;
  if(mae && !(usiro))cout<<"MMYY"<<endl;
}
          

Measured memory_bytes: 256
(defconstant *n* (read))
(defconstant *m* (read))
(defconstant *x* (read))
(defconstant *y* (read))

(defmacro set-lst (n)
  `(loop for i from 1 to ,n
        collect (read)))

(defconstant *x-n* (nth 0 (sort (set-lst *n*) #'>)))
(defconstant *y-m* (nth 0 (sort (set-lst *m*) #'<)))

(defun calc (x y z)
  (cond ((and (< x z) (>= y z) (< *x* z) (>= *y* z))
         t)
        ((> z *y*)
         nil)
        (t (calc x y (1+ z)))))

(if (calc *x-n* *y-m* (1+ *x*))
    (princ "No War")
    (princ "War"))

Measured memory_bytes: 13156
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

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

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

items = []
for i in range(N):
    items.append(list(map(int, input().split())))

ans = 0

for item in items:
    tmp = 0
    for i in range(M):
        a = item[i]
        b = b_list[i]
        tmp += a * b
    if tmp + C > 0:
        ans +=1
print(ans)


Measured memory_bytes: 3060
#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 pb          push_back
#define ff          first
#define ss          second
#define ll          int64_t
#define ld          long double
#define mod         1000000007
#define mod2        998244353
#define inf         1000000000000007
#define pi          3.14159265358979323846
#define nl          cout<<"\n"
#define dbg(x)      cerr<<#x<<" = "<<x<<"\n"
#define all(v)      v.begin(),v.end()
#define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

template<typename T,typename U> static inline void amin(T &x,U y)   {if(y<x)x=y;}
template<typename T,typename U> static inline void amax(T &x,U y)   {if(x<y)x=y;}  

ll lcm(ll a,ll b)       {return (a*b)/__gcd(a,b);} 
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
ll mpow(ll x,ll y,ll p) {ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;} 
string dec_bin_32(ll n) {string s;for(ll i=31;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
string dec_bin_64(ll n) {string s;for(ll i=63;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
ll mod_inv(ll a,ll m)   {ll m0=m,y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;} 

//-------------------------------L_I_Erq34-------------------------------

const ll N=100007;
vector<ll> v[N];
ll dist[N];

ll dfs(ll cur)
{
	if(dist[cur])
		return dist[cur];
	for(ll i:v[cur])
		dist[cur]=max(dist[cur],dfs(i)+1);
	return dist[cur];
}

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n>>m;
	forn(i,0,m)
	{
		cin>>l>>r;
		l--,r--;
		v[l].push_back(r);
	}
	ll ans=0;
	forn(i,0,n)
		ans=max(ans,dfs(i));
	cout<<ans<<"\n";
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


Measured memory_bytes: 7936
#include <stdio.h>
#include <algorithm>

typedef long long LLONG;

int main(void) {
  LLONG L, R;
  scanf(" %lld %lld", &L, &R);
  
  LLONG min = 2020;
  
  LLONG endNum = std::min(R, L + 2019);
  for(LLONG l = L; l < endNum; l++) {
    LLONG ans = 0;
    for(LLONG r = l + 1; r <= endNum; r++) {
    	ans = (l * r) % 2019;
      	min = std::min(min, ans);
    }
  }
  
  printf("%lld\n", min);
}

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


int minCost(vector<int>&v,int index,vector<int>&cost){
    
    if(cost[index]!=-1){
        return cost[index];
    }
    
    if(index<=0){

        return cost[index] = 0;
    }
    else if(index==1){
        return cost[index] = abs(v[1]-v[0]);
    }
    else {
        int o,t;
        o = abs(v[index] - v[index-1]);
        t = abs(v[index]-v[index-2]);
        return cost[index] = min(o+minCost(v,index-1,cost),t+minCost(v,index-2,cost));
    }
}


int32_t main(){
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        v.push_back(x);
    }
    vector<int> cost;
    for(int i=0;i<n;i++){
        cost.push_back(-1);
    }
    cout<<minCost(v,v.size()-1,cost)<<endl;
    return 0;
}

Measured memory_bytes: 5108