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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    ll n;
    cin >> n;

    ll ans = n / 500 * 1000;
    n %= 500;
    ans += n / 5 * 5;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>


using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
//const ll MOD=1000000007;
const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

ll mod_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

//二項係数
const int MAX = 2010000;
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;
}
// 前処理 COMinit();
// 計算例 cout << COM(100000, 50000) << endl;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,M,K; cin>>N>>M>>K;
  COMinit();
  
  ll ans=0;
  rep(i,K+1){
    ans+=COM(N-1,i)*M%MOD*mod_pow(M-1,N-i-1)%MOD;
    ans%=MOD;
  }

  cout<<ans<<'\n';
  
  return 0;
}


Measured memory_bytes: 50744
import copy

shop_num = int(input().rstrip())

# business hour
shop_data = {}
for i in range(shop_num):
	shop_data[i] = input().rstrip().split(' ')

# benefit
shop_benefit = {}
for i in range(shop_num):
	shop_benefit[i] = input().rstrip().split(' ')

patterns = [0, 1, 2, 3];

targets = []
for pattern1 in patterns:
	list1 = []
	if pattern1 == 1:
		list1.append(0)
	elif pattern1 == 2:
		list1.append(1)
	elif pattern1 == 3:
		list1.append(0)
		list1.append(1)

	for pattern2 in patterns:
		list2 = copy.deepcopy(list1)
		if pattern2 == 1:
			list2.append(2)
		elif pattern2 == 2:
			list2.append(3)
		elif pattern2 == 3:
			list2.append(2)
			list2.append(3)
		for pattern3 in patterns:
			list3 = copy.deepcopy(list2)
			if pattern3 == 1:
				list3.append(4)
			elif pattern3 == 2:
				list3.append(5)
			elif pattern3 == 3:
				list3.append(4)
				list3.append(5)
			for pattern4 in patterns:
				list4 = copy.deepcopy(list3)
				if pattern4 == 1:
					list4.append(6)
				elif pattern4 == 2:
					list4.append(7)
				elif pattern4 == 3:
					list4.append(6)
					list4.append(7)
				for pattern5 in patterns:
					list5 = copy.deepcopy(list4)
					if pattern5 == 1:
						list5.append(8)
					elif pattern5 == 2:
						list5.append(9)
					elif pattern5 == 3:
						list5.append(8)
						list5.append(9)

					targets.append(copy.deepcopy(list5))

ben_list = []
for target in targets:
	if (len(target) <= 0):
		continue;
	ben = 0
	for key in shop_data:
		count = 0
		for time in range(10):
			data = int(shop_data[key][time])
			if time in target:
				if data == 1:
					count += 1

		ben += int(shop_benefit[key][count])

	ben_list.append(ben)

print(max(ben_list))

Measured memory_bytes: 3956
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        repn[u - 1].append((v - 1, w))
        repn[v - 1].append((u - 1, w))
    
    """
    Greedyに隣接する頂点ごとに色を塗っていけばよい
    """

    color = [-1] * N
    color[0] = 0
    q = [0]
    while q:
        v = q.pop()
        for u, w in repn[v]:
            if color[u] != -1:
                continue
            if w % 2 == 0:
                color[u] = color[v]
            else:
                color[u] = (1 + color[v]) % 2
            q.append(u)
    for ans in color:
        print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    int n,m,s,u,v,a,b,c,d;
    scanf("%d %d %d",&n,&m,&s);
    vector<vector<vector<int>>> graph(n);
    int maxSilver = 0;
    for(int i=0;i<m;i++) {
        scanf("%d %d %d %d",&u,&v,&a,&b);
        u--;v--;
        graph[u].push_back({v,a,b});
        graph[v].push_back({u,a,b});
        maxSilver += a;
    }
    vector<vector<int>> cities;
    for(int i=0;i<n;i++) {
        scanf("%d %d",&c,&d);
        cities.push_back({c,d});
    }
    vector<vector<ll>> dist(n,vector<ll> (maxSilver+1,1e18));
    s = min(maxSilver,s);
    auto cmp = [&](vector<ll>& a, vector<ll>&b) {
        return a[0] > b[0];
    };
    priority_queue<vector<ll>, vector<vector<ll>>, decltype(cmp)> pq(cmp);
    pq.push({0,0,s}); // time,city,silver
    dist[0][s] = 0;
    vector<ll> bestRes(n,1e18);

    while(!pq.empty()) {
        vector<ll> cur = pq.top(); pq.pop();
        ll time = cur[0], city = cur[1], silver = cur[2];
        if(time > dist[city][silver]) continue;
        dist[city][silver] = time;
        for(auto& edge : graph[city]) {
            if(silver < edge[1]) continue;
            ll silverLeft = silver - edge[1];
            ll nextTime = time + edge[2];
            if(nextTime >= dist[edge[0]][silverLeft]) continue;
            dist[edge[0]][silverLeft] = nextTime;
            bestRes[edge[0]] = min(bestRes[edge[0]], nextTime);
            pq.push({nextTime, edge[0], silverLeft});
        }
        // buy silver
        ll nextSilver = min(silver + cities[city][0], (ll)maxSilver);
        ll nextTime = time + cities[city][1];
        if(nextTime < dist[city][nextSilver]) {
            dist[city][nextSilver] = nextTime;
            pq.push({nextTime, city, nextSilver});
        }
    }

    for(int i=1;i<n;i++) printf("%lld\n", bestRes[i]);
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N, K; cin >> N >> K;
	vll cmp;
	for (ll i = 1; i < 50000; i++) {
		if (i*i > N) break;
		cmp.push_back(i);
		cmp.push_back(N/i);
	}
	cmp.push_back(0);

	sort(begin(cmp), end(cmp));
	ll M = cmp.size();

	auto dp = makeVector(K, M, 0ll);
		
	for (int i = 1; i < M; i++) {
		dp[0][i] = cmp[i] - cmp[i-1];
		(dp[0][i] += dp[0][i-1]) %= mod;
	}
	
	for (int i = 1; i < K; i++) {
		for (int j = 1; j < M; j++) {
			int idx = M-j;
			dp[i][j] = (dp[i-1][idx] * (cmp[j] - cmp[j-1])) % mod;
			(dp[i][j] += dp[i][j-1]) %= mod;
		}
	}
	cout << dp[K-1][M-1] << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 53764
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    long double ans1 = 0;
    rep(i,n){
        long double t = 1;
        rep(j,n)if(i != j)t *= a[j];
        ans1 += t;
    }
    long double ans2 = 1;
    rep(i,n)ans2 *= a[i];
    cout << shosu(10) << ans2/ans1 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;



int main(){
	ll n; cin>>n;
	
	if(n==2){
		cout<<1;
		return 0;
	}
	
	ll cont=2;
	
	for(ll i=2; i*i<=n; i++){
		if(n%i==0){
			ll d1=i;
			ll d2=n/i;
			
			ll temp=n;
			while(temp%d1==0) temp/=d1;
			
			if(temp%d1==1) cont++;
			 
			if(d1!=d2){
				temp=n;
				while(temp%d2==0) temp/=d2;
				
				if(temp%d2==1) cont++;
			}
		}
	}
	
	for(ll i=2; i*i<=n-1; i++){
		if((n-1)%i==0){
			cont++;
			if(i!=(n-1)/i) cont++;
		}
	}
	
	cout<<cont;
			
			
	return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] strNum = br.readLine().split(" ");
        String[] strPrice = br.readLine().split(" ");
        int n = Integer.parseInt(strNum[0]);
        int k = Integer.parseInt(strNum[1]);
        Integer[] price = new Integer[n];
        
        for(int i = 0; i < price.length; i++){
            price[i] = Integer.valueOf(strPrice[i]);
        }
        
        Arrays.sort(price);
        
        int sum = 0;
        
        for(int i = 0; i < k; i++){
            sum += price[i];
        }
        
        out.println(sum);
        out.close();
        
    }
}

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

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

    string S, T;
    cin >> S >> T;

    cout << T + S << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(char *x, char *y);

int main(void)
{
	char cup[3];
	char input[4];
	char i;

	cup[0] = 1;
	while (scanf("%s", input) != EOF){
		swap(&cup[input[0] - 'A'], &cup[input[2] - 'A']);
	}

	for (i = 0; i < 3; i++){
		if (cup[i] == 1){
			printf("%c\n", i + 'A');
			break;
		}
	}

	return (0);
}

void swap(char *x, char *y)
{
	char tmp = *x;
	*x = *y;
	*y = tmp;
}

Measured memory_bytes: 540
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

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


double g(double i){
    return 1.0/i;
}

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    double s=0;
    rep(i,n) {
        s += g((double)a[i]);
    }
    
    double ans = 0.0;
    ans = g(s);
    cout << setprecision(16)<< ans << endl;
    
    


}


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

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

  string s;
  cin >> s;
  int l, r;
  l = s.find_first_of('A');
  r = s.find_last_of('Z');
  cout << r - l + 1 << '\n';
  return 0;
}

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

using namespace std;

int main()
{
    int n;

    cin>>n;
    vector<int> v(n),dp(n+1);

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

    dp[0]=0;

    for(int i=1;i<=n;i++)
        dp[i]=INT_MAX;

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

    cout <<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	while (1)
	{
		int n;
		cin >> n;

		if (n == 0)
		{
			break;
		}

		for (int i = 0; i < n; i++)
		{
			int a, b, c;
			cin >> a >> b >> c;

			string r = "C";
			if (a == 100 || b == 100 || c == 100 || (a + b + c >= 240) || (a + b >= 180))
			{
				r = "A";
			}
			else if ((a + b + c >= 210) || (a + b + c >= 150 && (a >= 80 || b >= 80)))
			{
				r = "B";
			}

			cout << r << endl;
		}
	}

}



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

#define INT int
#define REP(i,a,b) for(INT i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
int n,m;
string blue[100];
string red[100];
cin >> n;
rep(i,n) cin >> blue[i];
cin >> m;
rep(i,m) cin >> red[i];

int maxPoint = 0;

rep(i,n){
	int point = 0;
	rep(j,n) if(blue[j] == blue[i]) point++;
	rep(j,m) if(red[j] == blue[i]) point--;
	if(point > maxPoint) maxPoint = point;
}

cout << maxPoint <<endl;

return 0;
}


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

int solve(int n, vector<int> &v)
{
  if(v[n] == 0)
    v[n] = solve(n-1, v) + solve(n-2, v);
  return v[n];
}

int main()
{
  vector<int> fib(45);
  fib[0] = fib[1] = 1;
  int n; cin>>n;
  solve(n, fib);
  cout << fib[n]<<"\n";
}


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

int n, m;
long long ans = 0;
std::vector<int> brokenList(1, -1);

int main(){
    std::cin >> n >> m;
    for(int idx = 0; idx < m; ++ idx){
        int num;
        std::cin >> num;
        brokenList.push_back(num);
    }
    std::sort(brokenList.begin(), brokenList.end());

    int bIdx = 0;
    std::vector<int> cntList(n + 1, 0);
    cntList[0] = 1;
    for(int now = 0; now < n; ++ now){
        for(; bIdx < m && brokenList[bIdx] < now; ++ bIdx);
        if(brokenList[bIdx] == now){
            continue;
        }

        cntList[now + 1] += cntList[now];
        cntList[now + 1]  %= 1000000007;
        if(now < n - 1){
            cntList[now + 2] += cntList[now];
            cntList[now + 2] %= 1000000007;
        }
    }

    std::cout << cntList[n] << std::endl;
}


Measured memory_bytes: 1144
// AOJ 2878 Graph
// 2018.4.14 bal4u
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define QMAX 1000000
typedef struct { long long t; int s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, long long t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define MAX 100002
int hi[MAX], *to[MAX], *d[MAX];
long long dist[MAX];

long long dijkstra(int n, int start, int goal)
{
	int i, s, e;
	long long t, nt;

	memset(dist, 0x10, n << 3);
	qsize = 0;
	enq(start, 0), dist[start] = 0;
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
		if (s == goal) break; 
		if (dist[s] < t) continue;
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], nt = t + d[s][i];
			if (dist[e] > nt) dist[e] = nt, enq(e, nt);
		}
	}
	return t;
}

int main()
{
	int N, M, s, t, i, j, k, a, b, c, x;
	int *memo;

	N = in(), M = in(), s = in()-1, t = in()-1;
	memo = malloc(M<<4);
	j = 0; for (i = 0; i < M; i++) {
		memo[j++] = a = in()-1, memo[j++] = b = in()-1, memo[j++] = c = in()-1;
		memo[j++] = in();
		hi[a]+=2, hi[b]+=2, hi[c]+=2;
	}
	for (i = 0; i < N; i++) if (hi[i]) {
		to[i] = malloc(hi[i]<<2), d[i] = malloc(hi[i]<<2);
	}

	memset(hi, 0, N<<2);
	j = 0; for (i = 0; i < M; i++) {
		a = memo[j++], b = memo[j++], c = memo[j++], x = memo[j++];
		k = hi[a], hi[a]+=2;
		to[a][k] = b, d[a][k++] = x, to[a][k] = c, d[a][k] = x;
		k = hi[b], hi[b]+=2;
		to[b][k] = a, d[b][k++] = x, to[b][k] = c, d[b][k] = x;
		k = hi[c], hi[c]+=2;
		to[c][k] = a, d[c][k++] = x, to[c][k] = b, d[c][k] = x;
	}
	printf("%lld\n", dijkstra(N, t, s));
	return 0;
}


Measured memory_bytes: 15904
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n>>s;
    std::deque<int> W;
    std::deque<int> E;
    int w_cnt=0,e_cnt=0;
    for (int i=0;i<n;i++) {
        if (s.at(i)=='W') {
            w_cnt++;
            W.emplace_back(w_cnt);
            E.emplace_back(e_cnt);
        } else if (s.at(i)=='E') {
            e_cnt++;
            E.emplace_back(e_cnt);
            W.emplace_back(w_cnt);
        }
    }
    int min_cnt=1000000;
    for (int j=0;j<n;j++) {
        int count=0;
        if (j==0) {
            count+=E[n-1];
        } else if (j==n-1) {
            count+=W[n-1];
        } else {
            //左側
            count+=W[j-1];
            //右側
            count+=E[n-1]-E[j];
        }
        if (count<min_cnt) {
            min_cnt=count;
        }
    }
    cout<<min_cnt<<endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		long long sum=0;
		vector<pair<int, int>>v, v2;
		set<int>s, s2;
		for(int i=1;i<=n;i++){
			int k, l, r;
			cin>>k>>l>>r;
			if(l<r) v.push_back({l-r, k});
			else v2.push_back({l-r, k});
			sum+=r;
		}
		for(int i=1;i<=v2.size();i++) s2.insert(i);
		for(int i=v2.size()+1;i<=n;i++) s.insert(i);
		sort(v.begin(), v.end());
		sort(v2.begin(), v2.end());
		reverse(v2.begin(), v2.end());
		for(auto [x, y]:v){
			auto it=s.upper_bound(y);
			if(it==s.end()) sum+=x;
			else s.erase(it);
		}
		for(auto [x, y]:v2){
			auto it=s2.upper_bound(y);
			if(it!=s2.begin()){
				it--;
				s2.erase(it);
				sum+=x;
			}
		}
		cout<<sum<<"\n";
	}
}


Measured memory_bytes: 14348
N = int(input())
A = str(N - 1)
B = '1'
ans = 10 ** 9
for i in range(1, (N // 2) + 1):
    tmpa = list(map(int, A))
    tmpb = list(map(int, B))
    tmp = sum(tmpa) + sum(tmpb)
    ans = min(ans, tmp)
    A = str(N - i - 1)
    B = str(i + 1)

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int size = scanner.nextInt();
		int[] heapArrays = new int[size + 1];
		for (int i = 1; i < size + 1; i++) {
			heapArrays[i] = scanner.nextInt();
		}
		for (int i = 1; i < size + 1; i++) {
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.append("node ").append(i).append(": ")
						 .append("key = ").append(heapArrays[i]).append(", ");
			if (i / 2 > 0) {
				stringBuilder.append("parent key = ").append(heapArrays[i / 2]).append(", ");
			}
			if (i * 2 < size + 1) {
				stringBuilder.append("left key = ").append(heapArrays[i * 2]).append(", ");
			}
			if (i * 2 + 1 < size +1) {
				stringBuilder.append("right key = ").append(heapArrays[i * 2 + 1]).append(", ");
			}
			System.out.println(stringBuilder.toString());
		}
	}
}

Measured memory_bytes: 27272
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int main(){
 int n; 
  cin >>n;
  int a[n];
  rep(i, n) cin >> a[i];
  int ans=0;
  for(int i = 1; i < n-1; i++){
   	 if(a[i] < a[i+1] && a[i] > a[i-1])
       ans++;
    else if(a[i] > a[i+1] &&a[i] < a[i-1])
       ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

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

  int K, S;
  std::cin >> K >> S;
  int ans = 0;
  for(int x=0; x <= K; x++)
    for(int y=0; y <= K; y++)
    { int z = S-x-y;
      if ( 0<=z and z<=K) ans +=1;
    }
  std::cout << ans << '\n';
}


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

int main(){
    //freopen("a.in", "r", stdin);
    int n; cin >> n;
    int arr[n];
    for(int i = 0; i<n; i++) cin >> arr[i];
    long long dp[n];
    dp[0] = 0;
    dp[1] = max(arr[0], arr[1]);
    long long pre[n];
    pre[0] = arr[0];
    for(int i = 2; i<n; i+=2) pre[i] = pre[i-2]+arr[i];
    for(int i = 2; i<n; i++){
        if(i % 2 == 0){
            dp[i] = max(arr[i]+dp[i-2], dp[i-1]);
        }
        else{
            dp[i] = max(arr[i]+dp[i-2], pre[i-1]);
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 7532
#include<stdio.h>
int main()
{
	int n,i,j,m;
	char a[1000][1000];
	while(~scanf("%d%d",&n,&m))
	{
		for(i=0;i<n;i++)
		   scanf("%s",a[i]);
		for(i=0;i<m+2;i++)
		printf("#");
		printf("\n");
		for(i=0;i<n;i++)
		{
			printf("#");
			printf("%s",a[i]);
			printf("#\n");
		}
		for(i=0;i<m+2;i++)
		printf("#");
		printf("\n");
	}
 } 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(scanf("%d %d",&n,&m),n){
		vvi in(n,vi(n));
		vvi pic(m,vi(m));
		rep(i,n)rep(j,n)scanf("%d",&in[i][j]);
		rep(i,m)rep(j,m)scanf("%d",&pic[i][j]);
		pii out(inf,inf);
		int N=n-m+1,M=n-m+1;
		rep(e,4){
			rep(i,n-m+1)rep(j,n-m+1){
				pii t(inf,inf);
				rep(k,m)rep(l,m)
					if(pic[k][l]!=-1){
						if(in[i+k][j+l]!=pic[k][l])goto en;
						t=min(t,pii(i+k,j+l));
					}
				out=min(out,t);
				N=out.first;
				M=out.second;
				goto end;
				en:;
				if(i==N&&j==M)goto end;
			}
			end:;
			if(e==3)break;
			vvi tmp=pic;
			rep(i,m)rep(j,m)pic[i][j]=tmp[j][m-i-1];
		}
		if(out.first==inf)cout<<"NA"<<endl;
		else cout<<out.second+1<<" "<<out.first+1<<endl;
	}
}

Measured memory_bytes: 1296
#include<iostream>
#include<cstdio>
#include<ctime>


//math
//------------------------
template<class T>inline T sqr(T x){ return x*x; };



int a,b;


int solve1(int a,int b){
	return a*b;
}
int solve2(int a, int b){
	return 2 * (a + b);
}






int main(){
	std::clock_t start = clock();
	std::cin >> a >> b;
	printf("%d %d\n", solve1(a, b), solve2(a, b));
	//printf("time is %d",(clock()-static_cast<double>(start)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int a,b;

int main(){
	cin>>a>>b;
	if(a%2==1&&b%2==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
readline=sys.stdin.readline

H,W=map(int,readline().split())
grid=[None]*H
for i in range(H):
  grid[i]=readline().rstrip()

INF=10**10
dp=[[INF for i in range(W)] for j in range(H)]
curwhite=True

# 下もしくは右に進み、白から黒に行ったら反転数を+1する
# 自分より大きい値だったら上書きする

from collections import deque
q=deque()
# h,w,今までに反転した数,今まで白だったか
q.append([0,0,0,curwhite])
while q:
  y,x,num,curwhite=q.popleft()
  if grid[y][x]=="#":
    # 黒だった場合
    if curwhite:
      curwhite=False
      # 今まで白だった場合
      num+=1
      if dp[y][x]>num:
        dp[y][x]=num
      else:
        continue
    else:
      # 今まで黒だった場合
      if dp[y][x]>num:
        dp[y][x]=num
      else:
        continue
  else:
    # 白だった場合
    if curwhite:
      # 今まで白だった場合
      if dp[y][x]>num:
        dp[y][x]=num
      else:
        continue
    else:
      # 今まで黒だった場合
      curwhite=True
      if dp[y][x]>num:
        dp[y][x]=num
      else:
        continue
  if y+1<H:
    q.append([y+1,x,num,curwhite])
  if x+1<W:
    q.append([y,x+1,num,curwhite])

print(dp[-1][-1])


Measured memory_bytes: 4064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

#define inf  1000000007
#define ll long long
#define PA pair<int,int>
#define PPAP pair<int,PA>
#define  MP make_pair
#define  PB push_back

using namespace std;
long long  mod = 1000000007;

int main(){
	int n,m,k;
	cin >> n >> m >> k;
	bool flag = 0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i*m+j*n-i*j*2==k){
				flag = 1;
			}
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
fn main() {
    let (a,b,c) = get!(i32,i32,i32);

    println!("{}", if c-(a-b) > 0 {c-(a-b)} else {0});
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		String s=sc.next();

		char[]c=s.toCharArray();
		 
		int a= 0;
		for(int i = 0; i <= n-3; i ++) {
			if(c[i]=='A'&&c[i+1]=='B'&&c[i+2]=='C') {
				a++;
			}
		}
 	    System.out.println(a);
	}	
}

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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	long long x=0,y=0;
	long long ans=0;
	for(long long i=0;i<n;i++){
		if((i==0 && s.at(i)=='L') || (i==n-1 && s.at(n-1)=='R')) continue;

		if(s.at(i)=='R' && s.at(i+1)=='R') ans++;
		if(s.at(i)=='L' && s.at(i-1)=='L') ans++;
	}

	if(s.at(n-1)=='R') y++;
	for(long long i=0;i<n-1;i++){
		if(i==0 && s.at(i)=='L') y++;
		if(s.at(i)=='R' && s.at(i+1)=='L') x++;
	}

	ans+=min(x,k)*2;
	k-=x;
	ans+=min(y,max(k,(long long)0));
	cout<<min(ans,n-1)<<endl;

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}


Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <iostream>
#include <string.h>
#include <map>
#include <set>
#include <functional>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    int n = 1000000;
	vector<bool> is_prime(n, true);
    vector<int> count(n);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<n; i++){
        if(is_prime[i]){
            for(int j=i; j<n; j+=i)
                is_prime[j] = false;
            count[i]++;
        }
        count[i] += count[i-1];
    }
    
    int a;
    while(cin>>a){
        cout << count[a] << endl;
    }
    
	return 0;
}

Measured memory_bytes: 5164
import java.util.Scanner;

class Main
{

	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int value = scan.nextInt();
		int W = value;
		value = scan.nextInt();
		int H = value;
		value = scan.nextInt();
		int x = value;
		value = scan.nextInt();
		int y = value;
		value = scan.nextInt();
		int r = value;
		
		if((x-r < 0 || x+r > W)||(y-r < 0 || y+r > H))
		{
			System.out.println("No");
		}
		else
		{
			System.out.println("Yes");
		}
		
	}

}



Measured memory_bytes: 26392
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    string s ;
    cin>>s;
    string s1 = "ABC";
    string s2 = "ARC";
    if(s==s1)
    {
        cout<<s2;
    }
    else
{
    cout<<s1;
}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);
    for (ll i = 0; i < N; i++) {
        cin >> t[i];
    }
    ll ans = 0;
    for (ll i = 0; i < N-1; i++) {
        ans += min(t[i] + T, t[i+1]);
        ans -= t[i];
    }
    ans += T;
    printf("%lld\n", ans);
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
  cout << ( (max({a,b,c,d,e})-min({a,b,c,d,e})<=k) ? "Yay!" : ":(" )<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        long long ans = 0;
        int i = 0;
        long long hoge = 1;
        string str = "";
        while (true) {
                if (((1LL << i) & n) && (((1LL << i) & ans) == 0)) {
                        ans += hoge;
                        str += "1";
                } else if ((((1LL << i) & n) == 0) && ((1LL << i) & ans)) {
                        ans += hoge;
                        str += "1";
                } else {
                        str += "0";
                }
                hoge *= -2;
                i ++;
                if (i == 62) break;
        }
        int p = -1;
        for (int i = (int) str.size() - 1; i >= 0; i --) {
                if (str[i] == '1') {
                        p = i + 1;
                        break;
                }
        }
        if (p == -1) {
                cout << 0 << endl;
        } else {
                str = str.substr(0, p);
                reverse(str.begin(), str.end());
                cout << str << endl;
        }
        return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<utility>
#include<iostream>
using namespace std;
int main(){
    int n,k,a[200010],i;
    long long int ans=0;
    scanf("%d %d\n",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n, greater<int>());
    for(i=k;i<n;i++){
        ans=ans+a[i];
    }
    printf("%lld\n",ans);
  return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var K = int.Parse(Console.ReadLine());
            var subd = new List<string>();

            for (var i = 0; i < K; i++)
            {
                for (var j = 0; j < S.Length - i; j++)
                {
                    subd.Add(S.Substring(j, i + 1));
                }
            }
            var sub = subd.OrderBy(s => s).Distinct().ToList();
            Console.WriteLine(sub[K - 1]);
        }
    }
}

Measured memory_bytes: 15840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;







int main() {

    ld a,b;
    cin>>a>>b;
    fin(ll(a*b));

}




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

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

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

  if (s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)  //  rep
#define repr(i,a,n) for(int i=a;i>n;i--)  //  repリバース
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9000000000000000000 //  巨大数INF
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  cout << lcm(2,n) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int max=0;
    int index=1;
    for(int i=1;i<=n;i++)
    {
        int temp=i;
        int result=0;
        while(temp%2==0){
            result++    ;
            temp=temp/2;
        }
        if(max<result){
            max=result;
            index=i;
        }
    }
    cout<<index;    
}

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

namespace AtCoder
{
    class ABC
    {
        static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());

            long m = 0, a = 0, r = 0, c = 0, h = 0;
            for(long i = 0; i < N; i++)
            {
                string S = Console.ReadLine();
                if (S[0] == 'M') m++;
                else if (S[0] == 'A') a++;
                else if (S[0] == 'R') r++;
                else if (S[0] == 'C') c++;
                else if (S[0] == 'H') h++;
            }

            long[] list = { m, a, r, c, h };
            long[] A = { 0, 0, 0, 1, 1, 2, 1, 0, 0, 0 };
            long[] B = { 1, 1, 1, 2, 2, 3, 3, 2, 2, 3 };
            long[] C = { 2, 3, 4, 3, 4, 4, 4, 3, 4, 4 };

            long ans = 0;
            for(long i = 0; i < 10; i++)
            {
                ans += list[A[i]] * list[B[i]] * list[C[i]];
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
A = list(map(int, input().split()))
A.sort()
Sum = 0
for i in range(len(A)):
    if i == 0:
        pass
    elif i == 1:
        Sum += A.pop()
    else:
        if i % 2 == 0:
            temp = A.pop()
            Sum += temp
        else:
            Sum += temp
print(Sum)

Measured memory_bytes: 31624
#include <iostream>
#include <vector>
using namespace std;
int const v = 200002;
vector< vector<int> > foo;
int main(void){
    int n, c, ans = 0;
    cin >> n >> c;
    foo.assign(c, vector<int>(v, 0));
    for(int i=0;i<n;i++){
        int s, t, u;
        cin >> s >> t >> u;
        u--;
        foo[u][s*2]++;
        foo[u][t*2]--;
    }
    for(int i=0;i<c;i++){
        for(int j=1;j<v;j++){
            foo[i][j] += foo[i][j-1];
        }
    }
    for(int i=0;i<c;i++){
        for(int j=0;j<v;j++){
            if(foo[i][j] == 0 && foo[i][j+1] > 0){
                foo[i][j]++;
            }
        }
    }
    for(int j=0;j<v;j++){
        int cnt = 0;
        for(int i=0;i<c;i++){
            if(foo[i][j] > 0) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 24576
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,w;
            cin>>n>>w;
            int ar[n+1],ar2[n+1];
            for(i=1;i<=n;++i)
                cin>>ar[i]>>ar2[i];
            int dp[n+1][w+1];
            mem(dp,-1);
            for(i=0;i<=n;++i)
                dp[i][0]=0;
            for(i=1;i<=n;++i)
            {
                for(j=w;j>=1;--j)
                {
                    if(j-ar[i]>=0 && dp[i-1][j-ar[i]]!=-1)
                    {
                        dp[i][j]=max(dp[i][j],dp[i-1][j-ar[i]]+ar2[i]);
                        //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
                    }
                    dp[i][j]=max(dp[i][j],dp[i-1][j]);
                }
            }

            int ans=0;
            for(i=0;i<=w;++i)
                ans=max(ans,dp[n][i]);
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 79232
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 

int ans=0;
void dfs(int I,auto &G,auto &C,auto &pq,auto &B)
{
	B[I]=1;
	if(!C[I]){C[I]=pq.top();pq.pop();}
	
	pqii nbr;
	for(int i=0;i<(int)G[I].size();i++)
	nbr.push({G[G[I][i]].size(),G[I][i]});
	
	while(nbr.size())
	{
		int J=nbr.top().second;nbr.pop();
		if(!B[J])dfs(J,G,C,pq,B);
	}
}
int32_t main()
{
	int n;cin>>n;
	vvi G(n+1);
	vi C(n+1);
	pqi pq;
	vb B(n+1);
	for(int i=1;i<=n-1;i++)
	{
		int u,v;cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;pq.push(x);
	}
	int mxi=1;
	for(int i=1;i<=n;i++)if(G[i].size() > G[mxi].size())mxi=i;
	dfs(mxi,G,C,pq,B);
	
	
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<(int)G[i].size();j++)ans+=min(C[i],C[ G[i][j] ]);
	}
	cout<<ans/2<<endl;
	
	for(int i=1;i<=n;i++)cout<<C[i]<<" ";
	cout<<endl;
	
}	


Measured memory_bytes: 1920
from sys import stdin
from bisect import bisect

N = int(stdin.readline().rstrip())
A = []
for i in range(N):
    A.append(int(input()))

dp = []
for a in A[::-1]:
    i = bisect(dp, a)
    if i < len(dp):
        dp[i] = a
    else:
        dp.append(a)
print(len(dp))

Measured memory_bytes: 8600
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define f(i,a) for(i=1;i<=a;i++)

int main() 
{
  int n,i,j,k;
  cin >> n;
  int flag =0;
  long long sum=0;
  f(i,n)
  { f(j,n) 
     {
         f(k,n)
         {
             sum += __gcd(i,__gcd(j,k));
         }}}
   cout << sum; 
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    int n; cin >> n;
    ll h[n]; rep(i,n) cin >> h[i];
    
    ll m = 0;
    rep(i,n) {
        if (m > h[i]) {
            cout << "No" << endl;
            return 0;
        }
        else m = max(m,h[i]-1);
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 4408
//*-- ILSH --*//
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
const ll inf=1e18+1e17;
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
vii graph[N];
int arr[N];
void dfs( int pos){
	if ( graph[pos].sz()==0)
		arr[pos]=0;
	for (int i=0;i<graph[pos].sz();i++){
		if ( arr[graph[pos][i]]==-1)
			dfs( graph[pos][i]);
		arr[pos]=max(1+arr[graph[pos][i]],arr[pos]);
	}
	
	
}
void solve() {
	int n,m;
	cin>>n>>m;
	memset( arr,-1,sizeof( arr));
	for (int i=0;i<m;i++){
		int aa,bb;
		cin>>aa>>bb;
		graph[aa].pb( bb);
	}
	for ( int i=1;i<=n;i++)
		if ( arr[i]==-1)
			dfs(i);
	cout<<*max_element( arr,arr+n+1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while ( t-- )
    	solve();    
}

Measured memory_bytes: 10880
using System;
class Program {
    static void Main(string[] args) {
        string s = Console.ReadLine();
        int count = int.Parse(s.Split(' ')[0]);
        int rate = int.Parse(s.Split(' ')[1]);
        if (count < 10) {
            rate = rate + 100 * (10 - count);
        }

        Console.WriteLine(rate);
    }
}

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

int main()
{
  ll n,m;
  cin>>n>>m;
  ll ar[m];
  ll sum=0;
  for(ll i=0;i<m;i++)
  {
 cin>>ar[i];
    sum+=ar[i];}
  if(n>sum)
    cout<<n-sum;
  else if(sum==n)cout<<0; 
    else cout<<-1;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int x,y,lst,n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int t,xx,yy;cin>>t>>xx>>yy;
		int d=abs(x-xx)+abs(y-yy);
		if(d>t-lst||(d^(t-lst))&1)
			return puts("No"),0;
		lst=t,x=xx,y=yy;
	}
	puts("Yes");
}


Measured memory_bytes: 256