akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    ll n; cin >> n;
    ll a[n];
    rep(i, n){
        cin >>a[i];
    }

    ll vmax = 0;
    ll imax = 0;
    rep(i, n){
        if(vmax < a[i]){
            vmax = a[i];
            imax = i;
        }
        vmax = max(vmax, a[i]);
    }

    ll k = 0;
    double vmin = 1e18;
    rep(i, n){
        if(i == imax) continue;
        double d = abs(a[i] - vmax/2.0);

        if(d < vmin){
            vmin = d;
            k = a[i];
        }
    }

    cout << vmax << " " << k << endl;

    return 0;
}

Measured memory_bytes: 1024
#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;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        char ch;
        cin>>ch;
        if(ch>='A'&&ch<='Z')
        {
            cout<<"A";
        }
        else cout<<"a";
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <limits>
#include <cassert>

using namespace std;

#define	MAXN 200000
int N, X;
int x;
long long sum_x[MAXN + 1];

void solve() {
	unsigned long long ans;
	cin >> N >> X;
	sum_x[0] = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> x;
		sum_x[i] += sum_x[i - 1] + x;
	}

	unsigned long long E_min = numeric_limits<unsigned long long>::max();
	for (int k = 1; k <= N; k++) // k = (ゴミをゴミ箱に入れる回数)
	{
		unsigned long long E_k = 0;

		const int q_k = N / k;
		const int r_k = N % k;
		const int top_num_in_k_groups = q_k - 2;
		// from 1 to r
		E_k += max(0, top_num_in_k_groups + 1) * (sum_x[r_k] - sum_x[0]);
		for (int i = 0; i < top_num_in_k_groups; i++)
		{
			// from start_index within k
			const int num_i = top_num_in_k_groups - i;
			const int start_index = r_k + i * k;
			E_k += num_i * (sum_x[start_index + k] - sum_x[start_index]);
		}
		E_k *= 2;

		E_k += (long long)k * X; //ゴミ箱に入れる
		E_min = min(E_min, E_k);
	}
	E_min += 5 * sum_x[N];
	E_min += (long long)N * X;
	ans = E_min;

	cout << ans << endl;
	return;
}



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

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

typedef struct edge {
  ll to;
  ll cost;
} edge;
typedef vector<vector<edge>> G; // graph
typedef vector<Pll> GR; // graph result (cost, vertex num)

GR dijkstra(G &g, ll s) { // O(ElogV)
  priority_queue<Pll, vector<Pll>, greater<Pll>> q;
  GR res(g.size(), mkp(1e18, 0));
  
  res[s] = mkp(0, s);
  q.push(res[s]);

  while (!q.empty()) {
    auto p = q.top();
    q.pop();

    ll cost = p.first;
    ll pos = p.second;
    if (res[pos].first < cost) continue;

    each (j, g[pos]) {
      ll to = j.to;
      ll to_cost = j.cost + cost;
      if (to_cost >= res[to].first) continue;
      res[to].first = to_cost;
      q.push(mkp(to_cost, to));
    }
  }
  return res;
}

int main() {
  ll h, w;
  cin >> h >> w;

  G g(10);
  for (ll i = 0; i < 10; ++i) {
    for (ll j = 0; j < 10; ++j) {
      ll cost;
      cin >> cost;
      g[i].push_back(edge{.to=j, .cost=cost});
    }
  }

  ll ans = 0;
  for (ll i = 0; i < h; ++i) {
    for (ll i = 0; i < w; ++i) {
      ll n;
      cin >> n;
      if (n == -1) continue;
      if (n == 1) continue;
      auto res = dijkstra(g, n);
      ans += res[1].first;
    }
  }

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	long long ans = 1;
	for (int i = 0; i < N; i++) {
		if (i == 0) ans *= K;
		else ans *= (K - 1);
	}
	cout << ans << endl;
}

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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n&1) return cout << "No", 0;
	cout << (s.substr(0,n/2) == s.substr(n/2,n/2) ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int P, Q, R;
  cin >> P >> Q >> R;

  cout << min({P+Q,P+R,Q+R}) << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

void main(void){
  int N,K,A[200000],i;
  
  scanf("%d %d",&N,&K);
  
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  
  for(i=0;i<N-K;i++){
    if(A[i]<A[i+K])
      puts("Yes");
    else
      puts("No");
  }
}
    

Measured memory_bytes: 2404
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int N, M;
ll dp[111111];
ll ans[111111];

auto comp = [](int a, int b){return dp[a] > dp[b];};

void defdp(vector<vector<int>> A){
	priority_queue<
		int,
		vector<int>,
		decltype(comp)
		>W(comp);
	W.push(1);
	while(!W.empty()){
		int now = W.top();
		W.pop();
		for(auto v : A[now]){
			//if(H.find(v) == H.end()){
				//dp[v] = min(dp[v], dp[now]+1);
				//W.push(v);
			//}
			if(dp[v] != -1)continue;
			dp[v] = dp[now]+1;
			ans[v] = now;
			W.push(v);
		}
	}
}

signed main()
{
	cin >> N >> M;
	vector<vector<int>> A(N+1);
	REP(i, M){
		int a, b;
		cin >> a >> b;
		A[a].PB(b);
		A[b].PB(a);
	}
	REP(i, N+1){
		dp[i] = -1;
	}
	dp[1] = 0;
	defdp(A);
	cout << "Yes" << "\n";
	for(int i=2; i<N+1; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 17356
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    string s, t; cin >> s >> t;
    int cnt = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;


    return 0;
}

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

int main() {
	int N, M, i, j, k, l, flag;
	scanf("%d %d", &N, &M);
	char A[N][N], B[M][M];
	for (i = 0; i < N; i++) {
		scanf("%s", A[i]);
	}
	for (i = 0; i < M; i++) {
		scanf("%s", B[i]);
	}
	for (i = 0; i <= N - M; i++) {
		for (j = 0; j <= N - M; j++) {
			flag = 0;
			for (k = 0; k < M; k++) {
				for (l = 0; l < M; l++) {
					if (A[i + k][j + l] != B[k][l]) {
						flag = 1;
						break;
					}
				}
			}
			if (flag == 0) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
# C - Splitting Pile
N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)
sum_a = tmp - sum_s
ans = abs(sum_s - sum_a)

for i in range(1,N):
    sum_a = tmp - sum_s
    if ans > abs(sum_s - sum_a):
        ans = abs(sum_s - sum_a)
        sum_s += a[i]
    else:
        sum_s += a[i]
print(ans)

Measured memory_bytes: 23800
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int Q;
  cin >> Q;
  string p, q;
  p = q = "";
  bool status = true;
  
  while (Q--) {
   	int t;
    cin >> t;
    if (t == 1){
    	if (status == true) status = false;
    	else status = true;
    } else {
      int y;
      cin >> y;
      char x;
      cin >> x;
      if (status && y == 1) {
        p += x;
      } else if (status && y == 2){
        q += x;
      } else if (!status && y == 1) {
        q += x;
      } else {
        p += x;
      }
    }
    //cout << p << " " << status << " " << q << endl;
  }
  reverse(p.begin(), p.end());
  string ans = p + s + q;
  if (!status) {
   	reverse(ans.begin(), ans.end()); 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1348
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int heapSize = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");
        Node[] node = new Node[heapSize + 1];
        for(int i = 1; i <= heapSize; i++){
            node[i] = new Node(i);
            node[i].key = Integer.parseInt(input[i-1]);
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <=heapSize; i++){
            if(2*i <= heapSize){
                node[i].left = node[2*i];
                node[2*i].parent = node[i];
            }
            if(2*i + 1 <= heapSize){
                node[i].right = node[2*i + 1];
                node[2*i + 1].parent = node[i];
            }
            sb.append("node ").append(i).append(": ");
            sb.append("key = ").append(node[i].key).append(", ");
            if(node[i].parent != null){
                sb.append("parent key = ").append(node[i].parent.key).append(", ");
            }
            if(node[i].left != null){
                sb.append("left key = ").append(node[i].left.key).append(", ");
            }
            if(node[i].right != null){
                sb.append("right key = ").append(node[i].right.key).append(", ");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }

}
class Node{
    int id, key;
    Node left, right, parent;
    Node(int id){
        this.id = id;
    }
}

Measured memory_bytes: 24352
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {

            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();

            int mx = 0;
            int mn = 1000000001;


            for (int i = 0; i < N; i++) {
                int x = fs.nextInt();
                if (mx < x) mx = x;
                if (x < mn) mn = x;
            }

            System.out.println(mx - mn);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int N;
vector<int> p;
vector<vector<int>> c;
vector<int> a, a_inv;
vector<int> a_sub;
vector<int> is_confirm, is_leaf, is_progeny, progeny_count, candidate_v;

int do_confirm(){
	for(int i = N - 1; i >= 0; i--){
		int count = 0;
		for(int j = 0; j < c[i].size(); j++){
			count += is_confirm[c[i][j]];
		}
		if(count == c[i].size()){
			is_leaf[i] = 1;
			if(a[i] == i){
				is_confirm[i] = 1;
			}
		}
	}
	return is_confirm[0];
}

void dfs(int a_v){
	if(is_confirm[a_v] == 0){
		is_progeny[a_inv[a_v]] = 1;
		if(is_leaf[a_v] == 0){
			for(int i = 0; i < c[a_v].size(); i++){
				dfs(c[a_v][i]);
			}
		}
	}
}

int decide(){
	if(is_leaf[a[0]] == 1){
		return a[0];
	}
	for(int i = 0; i < N; i++){
		is_progeny[i] = 0;
		progeny_count[i] = 0;
	}
	dfs(a[0]);
	for(int i = N - 1; i > 0; i--){
		progeny_count[i] += is_progeny[i];
		progeny_count[p[i]] += progeny_count[i];
	}
/*	printf("is_progeny:");
	for(int i = 0; i < N; i++){
		printf("%d ", is_progeny[i]);
	}
	printf("\n");
	printf("progeny_count:");
	for(int i = 0; i < N; i++){
		printf("%d ", progeny_count[i]);
	}
	printf("\n");
*/	candidate_v.assign(0, -1);
	for(int i = 1; i < N; i++){
		if(is_progeny[i] == 1 && progeny_count[i] == 1){
			candidate_v.push_back(i);
		}
	}
//	return candidate_v[0];
	return candidate_v[rand() % candidate_v.size()];
}

void insersion(int v){
	int V = v;
	for(; v >= 0; v = p[v]){
		a_sub[v] = a[v];
	}
	for(v = V; v > 0; v = p[v]){
		a[p[v]] = a_sub[v];
	}
	a[V] = a_sub[0];
	for(v = V; v >= 0; v = p[v]){
		a_inv[a[v]] = v;
	}
}

int main(){
//	srand((unsigned)time(NULL));
	int i;
	scanf("%d", &N);
	p.assign(N, -1);
	c.assign(N, vector<int>(0));
	for(i = 1; i < N; i++){
		scanf("%d", &p[i]);
//		p[i] = rand() % i;
//		printf("p[%d] = %d\n", i, p[i]);
		c[p[i]].push_back(i);
	}
	a.assign(N, 0);
	a_inv.assign(N, 0);
	a_sub.assign(N, 0);
/*	for(i = 0; i < N; i++){
		a[i] = i;
		swap(a[i], a[rand() % (i + 1)]);
	}
*/	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		a_inv[a[i]] = i;
	}
	is_confirm.assign(N, 0);
	is_leaf.assign(N, 0);
	is_progeny.assign(N, 0);
	progeny_count.assign(N, 0);
	vector<int> ans(0);
	while(do_confirm() == 0){
/*		printf("a:");
		for(i = 0; i < N; i++){
			printf("%d ", a[i]);
		}
		printf("\n");
		printf("a_inv:");
		for(i = 0; i < N; i++){
			printf("%d ", a_inv[i]);
		}
		printf("\n");
		printf("is_confirm:");
		for(i = 0; i < N; i++){
			printf("%d ", is_confirm[i]);
		}
		printf("\n");
		printf("is_leaf:");
		for(i = 0; i < N; i++){
			printf("%d ", is_leaf[i]);
		}
		printf("\n");
*/		int v = decide();
//		printf("v = %d\n", v);
		ans.push_back(v);
		insersion(v);
//		printf("\n");
	}
	printf("%d\n", ans.size());
	if(ans.size() > 8000){
		return 0;
	}
	for(i = 0; i < ans.size(); i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 512
#include"cstdio"
#include"iostream"
#include"algorithm"
using namespace std;
int a[200005],b[200005],c[200005],d[200005];
int main(){
	int N,M,i=0,j=0,k=0,p=0;
scanf("%d%d",&N,&M);
	for(i=0;i<M;i++)
	{
scanf("%d%d",&a[i],&b[i]);
	}
	for(i=0;i<M;i++)
	{
	if(a[i]==N) d[j]=b[i],j++;
	if(b[i]==N) d[j]=a[i],j++;
	if(a[i]==1) c[k]=b[i],k++;
	if(b[i]==1) c[k]=a[i],k++;
	}
sort(c,c+k);
sort(d,d+j);
i=0;
	for(p=0;p<j;p++)
	{
	if(c[i]==d[p])
	{
printf("POSSIBLE\n");
	return 0;
	}
	if(c[i]<d[p]&&i<k) i++,p--;
	if(c[i]<d[p]&&i>=k)
	break;
	}
printf("IMPOSSIBLE\n");
	return 0;
}

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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int MOD = 1000000007;

ll N;
ll a[3010];

ll dp[3100][3100];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N;
	rep(i, N)cin >> a[i];
	for (int len = 1; len <= N; len++) {
		for (int i = 0; i + len <= N; i++) {
			int j = i + len;
			if ((N - len) % 2 == 0) {
				dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
			}
			else {
				dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
			}
		}
	}
	cout << dp[0][N] << endl;

	return 0;
}

Measured memory_bytes: 50172
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;

ll ds(ll digit) {
	ll res = 0;
	while (digit != 0) {
		res += digit % 10;
		digit /= 10;
	}
	return res;
}
ll MOD = 1000000007;
int main() {
	ll N;
	cin >> N;
	ll T[N];
	ll M;
	ll k;
	ll sum;
	for (ll i = 0; i < N; ++i) {
		cin >> T[i];
	}
	cin >> M;
	ll P[M], X[M];
	for (ll i = 0; i < M; ++i) {
		cin >> P[i] >> X[i];
		sum = 0;
	}
	for(ll i=0; i<N; ++i){
      sum+=T[i];
    }
  	for(ll j=0; j<M; ++j){
      cout<<sum-(T[P[j]-1]-X[j])<<endl;
                   }
                   }






Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL

using namespace std;
using llong = long long;

int main()
{
	IOS;

	int k;
	string s;
	cin >> k;
	cin >> s;
	int i;
	int minn = (k < s.length()) ? k : s.length();
	for (i = 0; i < minn ; i++)
	{
		cout << s[i];
	}
	if (s.length() > k) cout << "...";

	return 0;
}

Measured memory_bytes: 3644
package main

import (
	"fmt"
//	"strconv"
//	"sort"
//	"math"
//	"regexp"
)


var a,b,c int

func main(){
	fmt.Scan(&a,&b,&c)

	m := make(map[int]int)
	m[a]++
	m[b]++
	m[c]++

	fmt.Println(len(m))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=1e5+5;
const ll MAXLG=__lg(MAXN)+2;


ll n,k;
ll x[MAXN];
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n >> k;
    REP (i,n) {
        cin >> x[i];
    }

    ll ans = INF;
    for (ll l=0;l+k<=n;l++) {
        ans = min(ans,abs(x[l])+abs(x[l+k-1]-x[l]));
        ans = min(ans,abs(x[l+k-1])+abs(x[l+k-1]-x[l]));
    }

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


Measured memory_bytes: 1024
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        char map[]= new char[3];
        map = scanString().toCharArray();
        if (map[0] == '7' || map[1] == '7'  || map[2] == '7' ) {
            out.print("Yes");
        } else {
            out.print("No");
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    double r; cin >> r;
    cout << 2*r*M_PI << endl;
}

Measured memory_bytes: 3788
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int N,L;
  cin >> N >> L;
  int c[N];
  int i;
  
  for(i=0;i<N;i++){
    c[i]=L;
    L++;
  }
  int d[N];
  for(i=0;i<N;i++){
    d[i]=c[i]*c[i];
  }
  int temp=d[0];
  int tempid=0;
  for(i=1;i<N;i++){
    if(temp>d[i]){temp=d[i]; tempid=i;}
  }
  int sum=0;
  for(i=0;i<N;i++){
   if(i!=tempid) sum+=c[i];  
  }
  cout << sum <<endl;
  
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, m, q, a[50], b[50], c[50], d[50];

int ans;
int A[10];
void dfs(int id, int l) {
  if (id == n) {
    int t = 0;
    for (int i = 0; i < q; i++)
      if (A[b[i]-1] - A[a[i]-1] == c[i])
        t += d[i];
    if (t > ans) ans = t;
  } else {
    for (int i = l; i <= m; i++) {
      A[id] = i;
      dfs(id + 1, i);
    }
  }
}
int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
// C.

#include <iostream>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int n, m, a, b;
	cin >> n >> m;
	vector<int> h(n), good(n, 1);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> a >> b;
		--a, --b;
		if (h[a] <= h[b]) {
			good[a] = 0;
		}
		if (h[b] <= h[a]) {
			good[b] = 0;
		}
	}
	int ans = accumulate(good.begin(), good.end(), 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4048
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = [0] * (X * Y)
for i in range(X):
  for j in range(Y):
    AB[i * Y + j] = A[i] + B[j]

AB = sorted(AB, reverse = True)[:K]
#print(AB)
ABC = []
for i in range(len(AB)):
  for j in range(Z):
    ABC.append(AB[i] + C[j])
    
ABC = sorted(ABC, reverse = True)[:K]

for i in range(K):
  print(ABC[i])


    

Measured memory_bytes: 220292
import sys

n,m=map(int,next(sys.stdin).split())
adj=[[] for _ in range(n)]
for _ in range(m):
    ln=next(sys.stdin)
    a,b=map(int,ln.split())
    a,b=a-1,b-1
    adj[a].append(b)
    adj[b].append(a)

ans=0
vis=[0]*n
for i in range(n):
    if vis[i]:
        continue
    vis[i]=1
    k=0
    stk=[i]
    while stk:
        u=stk.pop()
        k+=1
        for v in adj[u]:
            if vis[v]:
                continue
            vis[v]=1
            stk.append(v)
    ans=max(ans,k)

print(ans)


Measured memory_bytes: 107032
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int K = stdIn.nextInt();
        stdIn.close();
        
        long sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += gcd(gcd(i, j), k);
                }
            }
        }
        
        System.out.println(sum);
    }

    // GCDメソッド
    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 27300
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<59)

signed main(){
    int n;
    cin>>n;
    vector<pii> v(n);
    rep(i,n){
        int t;
        cin>>t;
        v[i] = pii(t,i+1);
    }
    
    sort(all(v));
    
    set<int> st;
    st.insert(0);
    st.insert(n+1);
    
    int sum = 0;
    for(auto e:v){
        int p = e.second;
        int v = e.first;
        st.insert(p);
        auto it = st.find(p);
        int l = *(--it);
        rep(i,2)it++;
        int r = *(it);
     
        sum += v*((p-l)*(r-p));
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 12800
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100005
 
using namespace std;

const int INF = 1e9 + 5;

void solve() {
	int n, k;
	sc(n); sc(k);

	int h[n];
	f(i,0,n) {
		sc(h[i]);
	}

	vec<int> dp(n + 1, INF);
	dp[0] = 0;
	for(int i=0; i<n-1; ++i) {
		for(int j = i + 1; j <= i + k; ++j) {
			if(j < n) {
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	cout << dp[n-1] << el;
}


int main() {
    // freopen("inp.txt", "r", stdin);
    int ccc = 1;
    // sc(ccc);
    while(ccc--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 1024
a1,a2,a3=gets.chomp.split.map(&:to_i)
puts [(a2-a1).abs+(a3-a2).abs,(a3-a1).abs+(a2-a3).abs,(a1-a2).abs+(a3-a1).abs,(a3-a2).abs+(a1-a3).abs,(a1-a3).abs+(a2-a1).abs,(a2-a3).abs+(a1-a2).abs].min


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

int main(void)
{
	char str[27];
	int len;
	int i, j;
	
	scanf("%s", str);
	
	for(len=strlen(str),i=0; i<len; i++)
		for(j=0; j<len; j++){
			if(i == j)
				continue;
			
			if(str[i] == str[j]){
				printf("no\n");
				
				return 0;
			}
		}
	
	printf("yes\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>

using namespace std;
int a, b;

int main() {
  cin >> a >> b;
  string s;
  s = to_string(a) + to_string(b);
  int c = stoi(s);
  bool ans = false;
  for (int i=1; i<10000; i++) {
    if (c == i*i) {
      cout << "Yes" << endl;
      return 0;
    }
    if (c < i*i) {
      break;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)

    if op == "+":
            print(str(a+b))

    elif op == "-":
            print(str(a-b))

    elif op == "*":
            print(str(a*b))

    elif op == "/":
            print(str(a//b))

    elif op == "?":
        break


Measured memory_bytes: 5592
s = list(input())

cnt = 0
cnA = 0
i = 0
while i < len(s) - 1:
    #print(i, cnA)
    if s[i:i + 2] == ["B", "C"]:
        cnt += cnA
        i += 1
    elif s[i] == "A":
        cnA += 1
    else:
        cnA = 0
    i += 1

print(cnt)


Measured memory_bytes: 4840
#include<iostream>
#include<queue>
#include<deque>
#include<vector>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
#include<unordered_set>
#include<unordered_map>

#define pi 3.141592653
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt","w",stdout);
#define ii pair<int,int> 
#define fast_io cin.tie(0), cin.sync_with_stdio(false);
#define inf 0x3f3f3f3f
#define f first
#define s second
 
using namespace std;
typedef long long ll;	
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 1e7 + 100; 
const int MAX = 5e5 + 100;

using namespace std;
 


int n;

int main (){
  
 
  map <int,int > m;
  
  cin >> n;
  
  ll sum = 0;
  for(int i = 0 ;i< n;i++) {
    int x; cin >> x;
    sum += x;
    m[x]++;
  }
  
  int q; cin >> q;
  
  for(int i = 0 ;i < q;i++){ 
    ll bi, ci;
    cin >> bi >> ci;
    sum -= m[bi] * 1LL  * bi;
    sum += m[bi] * 1LL  * ci;
    m[ci] += m[bi];
    m[bi] = 0;
    cout << sum << '\n';
  }
  
  return 0;
  
}


Measured memory_bytes: 7556
from itertools import product

n, k = map(int, input().split())

zero = n // k
c = zero * zero * zero

if k % 2 == 0:
    half = k // 2
    d = 0
    for i in range(1, n+1):
        if i % k == half:
            d += 1
    c += (d * d * d)

print(c)


Measured memory_bytes: 3060
#!/usr/bin/env pypy3

import itertools


def compute_min_num(n, k):
    res = float("inf")
    seqs = itertools.product((True, False), repeat=n)
    for ops in seqs:
        x = 1
        for is_a in ops:
            if is_a:
                x *= 2
            else:
                x += k
        res = min(res, x)
    return res


def main():
    n = int(input())
    k = int(input())
    print(compute_min_num(n, k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
#include <iostream>

using namespace std;

int main()
{
   int N,M,Ai;
   int r=0;
   cin>>N>>M;
   for(int i=1;i<=M;i++)
   {
       cin>>Ai;
       r+=Ai;
   }
   int t=N-r;
   if(t>=0)
   {
       cout<<t;
   }
   else
   {cout<<-1;}
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long ll;
const int mod=1000000007;
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;
    int a[100010],b[100010];
    cin >> n;
    fill(a,a+100010,0);
    fill(b,b+100010,0);
    lol(i,n){
        int v;
        cin >> v;
        if(i%2==0)a[v]++;
        else b[v]++;
    }
    int mode,max;
    mode=max=0;
    for(int i=0;i<100010;i++){
        if(a[i]>max){
            mode=i;
            max=a[i];
        }
    }
    int mode1,max1;
    max1=mode1=0;
    for(int i=0;i<100010;i++){
        if(b[i]>max1){
            mode1=i;
            max1=b[i];
        }
    }
    sort(a,a+100010);
    sort(b,b+100010);
    if(mode==mode1){
        if(a[100008]<b[100008]){
            cout <<n-max-b[100008] << endl;
        }
        else cout <<n-max1-a[100008] << endl;
    }
    else cout <<n-max-max1 << endl;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s=null;
		String p=null;
		int flag=0;
		try {
			s=br.readLine().toLowerCase();
			p=br.readLine().toLowerCase();
		} catch (Exception e) {
			System.err.println("Error");
			// TODO: handle exception
		}
		s=s+s;
		for(int i=0;i<s.length()/2;i++){
			String str=s.substring(i, i+p.length());
			if(str.equals(p)) {
				flag=1;
			}
		}
		
		if(flag==1) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

#pragma GCC optimize("Ofast")

#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<endl
#define dnew cerr<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define f first
#define s second
#define endl '\n'

using namespace std;




signed main () { //[J][O][L][S][K][E][Y]
      int n,k; cin>>n>>k;
      int a=1, ans=0;
      while (a<=n) {
            a*=k;
            ans++;
      }

      cout<<ans;
      return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (SZ(s) <= k) {
	  cout << s << endl;
	} else {
	  cout << s.substr(0, k) << "..." << endl;
	}
  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    long long x, y;
    scanf("%lld%lld", &x, &y);
    if(x % 3 == 0 || y % 3 == 0)
    {
        cout << "0" << endl;
        return 0;
    }
//    if(x < y) swap(x, y);

    long long s1 = 0, s2 = 0, s3 = 0;
    long long ans = 0;

    s1 = floor(x * 1.0 / 3.0) * y;
    s3 = ceil(x * 1.0 / 3.0) * y;
    ans = s3 - s1;

    s1 = floor(y * 1.0 / 3) * x;
    s3 = ceil(y * 1.0 / 3) * x;
    if(ans > s3 - s1) ans = s3 - s1;

    s3 = floor(x * 1.0 / 2) * y;
    s1 = ceil(x * 1.0 / 2) * floor(y * 1.0 / 2);
    if(ans > s3 - s1) ans = s3 - s1;
//    printf("s1 = %lld s3 = %lld\n", s1, s3);
//    cout << ans << endl;

    s3 = floor(y * 1.0 / 2) * x;
    s1 = ceil(y * 1.0 / 2) * floor(x * 1.0 / 2);
    if(ans > s3 - s1) ans = s3 - s1;
//    printf("s1 = %lld s3 = %lld\n", s1, s3);
    long long num = 0;
    if(x % 2 == 0)
    {
        num = x / 2 * (y - floor(y * 1.0 / 3) * 3);
        if(num >= 0 && ans > num) ans = num;
//        cout << num << endl;
        num = x / 2 * (ceil(y * 1.0 / 3) * 3 - y);
        if(num >= 0 && ans > num) ans = num;
//        cout << num << endl;
    }
    else
    {
        num = x / 2 * (ceil(y * 1.0 / 3) - y);
        if(num >= 0 && ans > num) ans = num;
        num = x / 2 * (y - floor(y / 3) * 3) + y - floor(y / 3);
        if(num >= 0 && ans > num) ans = num;
    }
    if(y % 2 == 0)
    {
        num = y / 2 * (x - floor(x * 1.0 / 3) * 3);
        if(num >= 0 && num >= 0 && ans > num) ans = num;
//        cout << num << endl;
        num = y / 2 * (ceil(x * 1.0 / 3) * 3 - x);
        if(num >= 0 && ans > num) ans = num;
//        cout << num << endl;
    }
    else
    {
        num = y / 2 * (ceil(x * 1.0 / 3) - x);
        if(num >= 0 && ans > num) ans = num;
        num = y / 2 * (x - floor(x / 3) * 3) + x - floor(x / 3);
        if(num >= 0 && ans > num) ans = num;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int l = 0;
  int r = 100000;
  for(int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    l = max(l, L);
    r = min(r, R);
  }
  if (r - l < 0) {
    cout << 0 <<endl;
  }
  else {
    cout << r - l + 1 <<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
min = 99999999
tai = 0

for i in range(1,101):
  tai = 0
  for j in range(0,N):
    tai = tai + (X[j] - i)**2
  
  if tai < min:
    min = tai

print(min)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int,input().split()))

for i in range(N-1,-1,-1):
    A[i] = sum(A[i::i+1]) % 2

s = sum(A[0:N])
print(s)

n = 1
for i in range(N):
    if A[i] == 1:
        if n == s:
            print(i+1)
            break
        else:
            print(i+1,end=' ')
            n += 1


Measured memory_bytes: 7148
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d,e,sum;
    cin>>a>>b>>c>>d>>e;
    if(a<0){
        sum=(-a)*c;
        a=0;
    }
    if(a==0){
        sum+=d;
    }
    sum+=(b-a)*e;
    cout<<sum<<endl;
}



Measured memory_bytes: 3096
#include<cstdio>
#define max(a,b) (a>b?a:b)
#define MaN 200005
#define lson 
int n,m,a[MaN],l,ans=0;
int ton[MaN],mip[MaN],cnt[MaN];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){scanf("%d",&a[i]);ton[a[i]]++;}
	for(int i=1;i<=n;i++){
		mip[i+1]--;
		if(i+1-ton[i]<1){
			mip[1]+=1+ton[i]-i;
			mip[2]-=ton[i]-i;
			continue;
		}
		mip[i+1-ton[i]]++;
	}
	for(int i=1;i<=n;i++){
		cnt[i]=cnt[i-1]+mip[i];
		if(cnt[i]==0) ans++;
	}
	int x,y,ls;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		if(a[x]==y){
			printf("%d\n",ans);
			continue;
		}
		if(!cnt[max(y-ton[y],1)]) ans--;
		cnt[max(y-ton[y],1)]++;
		cnt[max(a[x]+1-ton[a[x]],1)]--;
		if(!cnt[max(a[x]+1-ton[a[x]],1)]) ans++;
		ton[a[x]]--;ton[y]++;
		a[x]=y;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    const int m = 100010;
    vector<int> a(m, 0);
    REP(i, N){
        int b;
        cin >> b;
        a[b]++;
    }
    int ma = 0;
    for (int i = 1; i < m-1; i++) {
        chmax(ma, a[i-1]+a[i]+a[i+1]);
    }
    pr(ma);
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
 
static class Program
{
    static void Main(string[] args)
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        //入力
        var list = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        var N = list[0];
        var K = list[1];
        var list2 = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
        var list3 = new double[N + 1];
        list3[0] = 0;
        for(int i = 0; i < N; i++){
          list3[i + 1] = list3[i] + list2[i];
        }
        var max = 0.0;
        var maxIndex = 0;
        double result = 0.0;
        for(int i = 0; i + K <= N; i++){
          var sum = list3[i + K] - list3[i];
          if(sum > max){
            max = sum;
            maxIndex = i;
          }
        }
        for(int j = 0; j < K; j++){
            result += (list2[maxIndex + j] + 1) / 2;
            
        }
        Console.WriteLine(result.ToString());

        Console.Out.Flush();
    }

}

Measured memory_bytes: 34524
open Batteries

let sqrt_int x = int_of_float @@ sqrt @@ float_of_int x

let pow_below n x =
  let rec aux acc  =
    if acc > x then []
    else
      acc :: (aux @@ ( * ) n acc)
  in
  aux n

let lower_than x =
  let num_exp_below =
    let rec aux n =
      if n =1 then
        [1]
      else
        (pow_below n x) @ (aux @@ pred n)
    in
    let num = sqrt_int x in
    List.sort compare @@ aux num in
  num_exp_below

let main () =
  int_of_string @@ input_line stdin
  |> lower_than
  |> List.rev
  |> List.hd
  |> print_int

let () = main ()


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

#define A first
#define B second

const int MAXN = 2e5+5;
const int inf = (1<<30);

int n, ans[MAXN], rev[MAXN], l[MAXN], r[MAXN], p[MAXN];
vector<int> g[MAXN], s, ord, m;
pii t[4*MAXN];

void init(int l = 0, int r = n-1, int node = 1) {
	if (l == r) {
		t[node] = pii(inf, l);
		return;
	}
	int mid = (l+r)/2;
	init(l, mid, 2*node);
	init(mid+1, r, 2*node+1);
	t[node] = min(t[2*node], t[2*node+1]);
}

void upd(int v, int x, int l = 0, int r = n-1, int node = 1) {
	if (l == r) {
		t[node] = pii(v, x);
		return;
	}

	int mid = (l+r)/2;
	if (x <= mid)
		upd(v, x, l, mid, 2*node);
	else
		upd(v, x, mid+1, r, 2*node+1);
	t[node] = min(t[2*node], t[2*node+1]);
}

pii find(int a, int b, int l = 0, int r = n-1, int node = 1) {
	if (a == l && b == r)
		return t[node];
	int mid = (l+r)/2;
	if (b <= mid)
		return find(a, b, l, mid, 2*node);
	if (a >= mid+1)
		return find(a, b, mid+1, r, 2*node+1);
	return min(find(a, mid, l, mid, 2*node), find(mid+1, b, mid+1, r, 2*node+1));
}

void dfspos(int v, int f = -1) {
	l[v] = ord.size();
	ord.push_back(v);
	for (int u : g[v])
		if (u != f)
			dfspos(u, v);
	r[v] = ord.size()-1;
	if (f != -1)
		p[v] = f;
}

void dfs(int v, int f = -1) {
	if (v == 0) {
		m.push_back(v);
		for (int u : g[v])
			upd(u, l[u]);
		for (int u : g[v]) {
			dfs(u, v);
			while (!s.empty())
				s.pop_back();
		}

		return;
	}

	int y = m.back(); //we are going to take all things <= y in the tree
	if (v > m.back()) {
		m.push_back(v);
		s.push_back(v);
		for (int u : g[v])
			if (u != p[v]) {
				upd(u, l[u]);
				// cout << v << " upd " << u << ' ' << l[u] << endl;
		}
	}
	while (true) {
		pii t = find(l[v], r[v]);
		// cout << v << ' ' << l[v] << ' ' << r[v] << endl;
		// cout << v << ' ' << t.A << ' ' << t.B << endl;
		if (t.A >= y)
			break;
		upd(inf, t.B);
		s.push_back(t.A);
		for (int u : g[t.A])
			if (u != p[t.A])
				upd(u, l[u]);
	}

	ans[v] = s.size();
	for (int u : g[v])
		if (u != f) {
			dfs(u, v);
			while (s.size() > ans[v]) {
				int h = s.back();
				s.pop_back();
				for (int u : g[h])
					if (p[u] != h)
						upd(inf, l[u]);
				upd(h, l[h]);
			}
		}
	if (m.back() == v)
		m.pop_back();
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;

	for (int i = 0; i < n-1; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfspos(0);
	init();
	dfs(0);
	for (int i = 1; i < n; ++i)
		cout << ans[i] << ' ';
	cout << endl;
}

Measured memory_bytes: 40056