akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
#define REP(i,n) for(long long i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
ll INF = 1LL << 60;

void solve(long long X, long long Y, long long Z, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    vll D, E;
    REP(x, X)
        REP(y, Y)
            D.push_back(A[x]+B[y]);
    sort(ALL(D)); reverse(ALL(D));
    REP(i, min(K, (ll)D.size())){
        E.push_back(D[i]);
    }
    vll ans;
    REP(i, E.size()){
        REP(j, C.size())
            ans.push_back(E[i]+C[j]);
    }
    sort(ALL(ans)); reverse(ALL(ans));
    REP(i, K){
        cout << ans[i]<<endl;
    }

}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(X);
    for(int i = 0 ; i < X ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(Y);
    for(int i = 0 ; i < Y ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(Z);
    for(int i = 0 ; i < Z ; i++){
        scanf("%lld",&C[i]);
    }
    solve(X, Y, Z, K, std::move(A), std::move(B), std::move(C));
    return 0;
}


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

int main(){
  int N;
  string s;
  cin >> N >> s;
  int ans=0;
  for (int i=0;i<=N-3;i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      ans++;
    }
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 3560
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#define f first
#define s second
#define ms(a, b) memset(a,b,sizeof(a))
typedef long long ll;

using namespace std;

char _;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);

    int N,M,C,sum=0;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> C;
        sum+=C;
    }
    if(sum>N){
        cout << "-1" <<"\n";
    }
    else{
        cout << N-sum << "\n";
    }

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;


void solve()
{
	int n,k;
	cin>>n>>k;
	int a[n],i,ans=0;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=0;i<k;i++)
		ans+=a[i];
	cout<<ans<<endl;
	
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n>>m>>l;
    	vi a,b;
    	rs(a,n);
    	rs(b,m);
    	// rs(c,n);
    	cin>>a>>b;
    	ll mini=hell,minib=hell,mi=hell;
    	for(i=0;i<n;i++)
    		mini=min(mini,a[i]);
    	for(i=0;i<m;i++)
    		minib=min(minib,b[i]);
    	mi=mini+minib;
    	for(i=0;i<l;i++)
    	{
    		ll x,y,z;
    		cin>>x>>y>>z;
    		x--;y--;
    		mi=min(mi,a[x]+b[y]-z);
    	}
    	mi=max(0ll,mi);
    	cout<<mi;
    }
    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int xNum = sc.nextInt();
			int yNum = sc.nextInt();
			int xPositon = sc.nextInt();
			int yPosition = sc.nextInt();

			List<Integer> xPointList = new ArrayList<>();
			// xlist

			int currentXPoint;
			for (int i = 0; i < xNum; i++) {
				currentXPoint = sc.nextInt();
				xPointList.add(currentXPoint);
			}

			List<Integer> yPointList = new ArrayList<>();
			// ylist
			int currentYPoint;
			for (int i = 0; i < yNum; i++) {
				currentYPoint = sc.nextInt();
				yPointList.add(currentYPoint);
			}

			xPointList.add(xPositon);
			yPointList.add(yPosition);
			//max X
			Optional<Integer> optMaxX = xPointList.stream().max((a, b) -> a.compareTo(b));
			int maxX = optMaxX.get();
			//min Y
			Optional<Integer> optMinY = yPointList.stream().min((a, b) -> a.compareTo(b));
			int minY = optMinY.get();

			if (maxX < minY) {
				System.out.println("No War");
			}
			else {
				System.out.println("War");
			}

		}
		catch (Exception e) {
			// TODO: handle exception
		}
	}
}


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

int main(void){
    int N,A,B,C,D;
    scanf("%d",&N);
    A = N / 1000;
    B = N % 1000 / 100;
    C = N % 1000 % 100 / 10;
    D = N % 1000 % 100 % 10 /1; 

    // printf("%d+%d+%d-%d=%d",A,B,C,D,A+B+C-D);
    if(A+B+C+D == 7){
        printf("%d+%d+%d+%d=7",A,B,C,D); 
        return 0;
    }

    if(A+B+C-D == 7){
        printf("%d+%d+%d-%d=7",A,B,C,D); 
        return 0;
    }

    if(A+B-C+D == 7){
        printf("%d+%d-%d+%d=7",A,B,C,D); 
        return 0;
    }

    if(A+B-C-D == 7){
        printf("%d+%d-%d-%d=7",A,B,C,D); 
        return 0;
    }

    if(A-B+C+D == 7){
        printf("%d-%d+%d+%d=7",A,B,C,D); 
        return 0;
    }

    if(A-B+C-D == 7){
        printf("%d-%d+%d-%d=7",A,B,C,D); 
        return 0;
    }

    if(A-B-C+D == 7){
        printf("%d-%d-%d+%d=7",A,B,C,D); 
        return 0;
    }

    if(A-B-C-D == 7){
        printf("%d-%d-%d-%d=7",A,B,C,D); 
        return 0;
    }


}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    ll cnt=1;
    ll cnt2=0;
    ll ans=0;
    ll wx=0;
    rep(i,s.length()){
        if(s[i]=='W')wx++;
    }
    rep(i,s.length()){
        if(s[i]=='W'){
            ans+=wx*cnt2;
            wx--;
            cnt2=0;
        }
        else{
            cnt2++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a[6] = {};
	int n; cin >> n;
	rep(i, 0, n) {
		double h; cin >> h;
		rep(j, 0, 6) {
			double b = 165.0 + 5.0*j;
			if (h < b) { a[j]++; break; }
			else if (j == 5) { a[5]++; }
		}
	}
	rep(i, 0, 6) {
		cout << i + 1 << ":";
		rep(j, 0, a[i]) {
			cout << "*";
		}
		cout << endl;
	}
	return 0;
}

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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

signed main() {
  int n;cin>>n;
  bitset<10001> bit(1);
  rep(i,n) {
    int s;cin>>s;
    bit |= bit<<s;
  }
  int ans = 0;
  for (int i = 10000; i >= 0; i--) {
    if (i%10==0) continue;
    if (bit.test(i)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 

 
signed main(){
    int n,k;
    cin>>n>>k;
    int  m=sqrt(n);
     int p[2][m],al[2]={},al3;
    
    int q;
    for(int i=0;i<m;i++)p[0][i]=1;
    for(int i=0;i<m;i++)p[1][i]=n/(i+1) ;
       for(int j=0;j<m;j++)al[1]=(al[1]+p[1][j])%MOD;
    for(int i=2;i<k;i++){
       al[0]=0,al[1]=0,al3=0;
          for(int j=0;j<m;j++)al[(i-1)%2]=(al[(i-1)%2]+p[(i-1)%2][j])%MOD;
        for(int j=0;j<m;j++)al[i%2]=(al[i%2]+p[i%2][j])%MOD;
        for(int j=m-1;j>=0;j--){
            q=p[i%2][j];
            p[i%2][j]=(al[(i-1)%2]+al[i%2]*(n/(j+1) -m)+al3)%MOD;
            al[i%2]=(al[i%2]-q+MOD)%MOD;
            al3=(al3+q*(n/(j+1) -m))%MOD;

        }
    }
    int ans=0;
    //for(int i=0;i<m;i++)cerr<<p[0][i]<<' '<<p[1][i]<<endl;
    for(int i=0;i<m;i++)ans=(ans+p[(k-1)%2][i]+p[(k-2)%2][i]*(n/(i+1)-m))%MOD;
  
    cout<<ans;
    return 0;
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
#E - Hopscotch Addict
import sys 
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = map(int, readline().split())
graph = [[[] for _ in range(3)] for _ in range(N+1)]
for i in range(M):
    x,y = map(int,readline().split())
    graph[x][0].append((y,1))
    graph[x][1].append((y,2))
    graph[x][2].append((y,0))
S,G = map(int,readline().split())
dist = [[-1]*3 for _ in range(N+1)]
dist[S][0] = 0
root = (S,0)

q = deque([root])
def bfs(q):
    while q:
        x,t = q.popleft()
        for nx,nt in graph[x][t]:
            if dist[nx][nt] != -1:
                continue
            dist[nx][nt] = dist[x][t] + 1
            q.append((nx,nt))
            
bfs(q)
if dist[G][0] == -1:
    print(-1)
else:
    print(dist[G][0] // 3)

Measured memory_bytes: 134980
#include<stdio.h>
#include<stack>
#include<queue>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if((a+b)==c)
	printf("Yes\n");
	else if((a+c)==b)
	printf("Yes\n");
	else if((c+b)==a)
	printf("Yes\n");
	else 
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int n, m, flag, voteSum;
	double l;
	int ai[1000];
	int i;

	scanf("%d%d", &n, &m);

	voteSum = 0;

	/* お菓子の種類ごとに獲得票を合計する */
	for (i = 0; i < n; i++)
	{
		scanf("%d", &ai[i]);
		voteSum += ai[i];
	}

	l = voteSum / (4.0 * m);
	flag = 0;

	/* 選択対象のお菓子を数える */
	for (i = 0; i < n; i++)
	{
		if (ai[i] >= l)
		{
			flag++;
		}
	}

	if (flag >= m)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 1592
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int num[1010][1010];
int main()
{
	int N;
	cin >> N;
	int c = 1;
	for (int i = 0; i < 1000; i++) {
		for (int j = 0; j <= i; j++) {
			num[i][j] = c;
			c++;
		}
	}
	for (ll i = 1; i < 100010; i++) {
		if (i * (i + 1) / 2 == N) {
			cout << "Yes" << endl << i + 1 << endl;
			int cnt = 0;
			for (int t = 0; t < i; t++) {
				cout << i << " ";
				for (int j = 0; j < cnt; j++) {
					cout << num[cnt][j] << " ";
				}
				for (int k = cnt; k < i; k++) {
					cout << num[k][cnt] << " ";
				}
				cout << endl;
				cnt++;
			}
			cout << i << " ";
			for (int j = 0; j < i; j++) {
				cout << num[j][j] << " ";
			}
			cout << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

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

  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v.at(i) = make_pair(x, y);
  }

  // 初期順列
  vector<int> order(n);
  for (int i = 0; i < n; i++) {
    order.at(i) = i;
  }

  // 順列全探索
  double sum = 0;
  int pattern = 0;
  do {
    for (int i = 1; i < n; i++) {
      pair<int, int> current = v.at(order.at(i-1));
      pair<int, int> next = v.at(order.at(i));

      int x1 = current.first;
      int y1 = current.second;
      int x2 = next.first;
      int y2 = next.second;

      int dist = (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1);
      sum += sqrt(double(dist));
    }
    pattern++;
  } while (next_permutation(order.begin(), order.end()));

  double ans = sum / pattern;
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 3764
#include <stdio.h>
#include <math.h>

int main(){
  double r, m;
  int n, i, j, a[3];
  while(scanf("%d%d%d", &a[0], &a[1], &a[2]) && a[0] && a[1] && a[2]){
    for(i = 0;i < 3;i++)
      for(j = i + 1; j < 3;j++)
        if(a[i] > a[j])
          a[i] += a[j], a[j] = a[i] - a[j], a[i] -= a[j];
    m = sqrt(a[0] * a[0] + a[1] * a[1]);
    scanf("%d", &n);
    for(i = 0;i < n;i++){
      scanf("%lf", &r);
      puts(m < 2 * r ? "OK":"NA");
    }
  }
  return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int N;
  float x,sum=0;
  string u;
  cin >> N;

  for(int i=0;i<N;i++){
    cin >> x >> u;
    if(u == "JPY") sum += x;
    if(u == "BTC") sum += 380000 * x;
  }

  cout << sum << endl;
  

}


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

//とりあえずsrcも持っとくとよい
struct NODE{
	int src,dst,cost,damage;
	NODE(int src,int dst,int cost,int damage) : src(src) , dst(dst) , cost(cost) , damage(damage) {}
};
bool operator < (const NODE &a,const NODE &b){
	return a.damage > b.damage; // gyaku for dijkstra
}
int main(){
	int N,M,L;
	while(cin >> N >> M >> L && N){
		vector< vector<NODE> > g(N); // NODEの構造をEdgeに流用
		for(int i = 0 ; i < M ; i++){
			int a,b,c,d;
			cin >> a >> b >> c >> d;
			a--,b--;
			g[a].push_back(NODE(a,b,c,d));
			g[b].push_back(NODE(b,a,c,d));
		}
		priority_queue<NODE> Q;
		Q.push(NODE(0,-1,L,0)); // dstはQのほうでは使わない
		int done[101][101] = {};
		
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if( done[q.src][q.cost]++ ) continue;
			if( q.src == N - 1 ){
				cout << q.damage << endl;
				break;
			}
			for(int i = 0 ; i < g[q.src].size() ; i++){
				int useCost = g[q.src][i].cost;
				if( useCost <= q.cost ){ //use
					Q.push(NODE(g[q.src][i].dst,-1,q.cost-useCost,q.damage));
				}
				Q.push(NODE(g[q.src][i].dst,-1,q.cost,q.damage+g[q.src][i].damage)); // no use
			}
		}
	}
}

Measured memory_bytes: 1916
var
  n,k,i,j,t,s:longint;
  a:array[0..1000] of longint;
begin
  readln(n,k);
  for i:=1 to n do read(a[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if a[i]<a[j] then begin t:=a[i];a[i]:=a[j];a[j]:=t;end;
  for i:=1 to k do
    inc(s,a[i]);
  write(s);
end.


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void YN(bool f){ cout << (f ? "YES" : "NO");}
void yn(bool f){ cout << (f ? "yes" : "no");}
void YeNo(bool f) {cout << (f ? "Yes" : "No");}
signed main(){
    string s; cin >> s;
    string t; t = s;
    reverse(all(t));
    int N = s.size();
    vector<int>disl(N,0LL);
    vector<int>disr(N,0LL);
    vector<int>ans(N,0LL);
    for(int i = 0; i < N; ++i){
        disl[i] = (s[i] == 'L') + (i ? disl[i - 1] : 0 );
        disr[i] = (t[i] == 'R') + (i ? disr[i - 1] : 0);
    }
    for(int i = 0; i < N; ++i){
        if(s[i] == 'R'){
            auto itr = upper_bound(all(disl),disl[i]);
            int idx = itr - disl.begin();
            if(itr == disl.end()){
                ans.back() += 1;
            } else {
                int dis = idx - i;
                ans[idx - (dis % 2)]++;
            }
                
        } else {
            auto itr = upper_bound(all(disr), disr[N - 1 - i]);
            int idx = (itr - disr.begin());
            if(itr == disr.end()){
                ans.front() += 1;
            } else {
                int dis = idx - (N - 1 - i);
                ans[N - 1 - (idx - (dis % 2))]++;
            }
        }
    }
    for(int i = 0; i < N; ++i){
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 3072
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 10000006
#define eps 1e-10
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
#define fir first
#define sec second
#define it_s_too_hard main
#define I_can_t_solve_it solve
//const long long inf=1LL<<62;
const double inf=1e9+9;
const int Mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
inline int dcmp(ld x){ if(fabs(x)<=eps) return 0; return x<0?-1:1;}
inline int scan(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline ll scan(ll x){
	int f=1;char ch=getchar();x=0;
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct Point{
	double x,y;
	Point(double x=0,double y=0):x(x),y(y) {}
	Point operator - (const Point &a)const { return Point(x-a.x,y-a.y);}
	Point operator * (const double &a)const{return Point(x*a,y*a);  }
	bool operator != (const Point &a)const{ return dcmp(x-a.x)!=0 || dcmp(y-a.y)!=0; }
	bool operator == (const Point &a)const{ return dcmp(x-a.x)==0 && dcmp(y-a.y)==0; }
	void read(){scanf("%lf%lf",&x,&y);}
};
double Dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
double dis(Vector a){
	return sqrt(Dot(a,a));
}
double Cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}
int n;
void I_can_t_solve_it(){
	n=scan();
	if(n<1200) cout<<"ABC"<<endl;
	else if(n<2800) cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
}
int it_s_too_hard(){
	int t=1;
	For(i,1,t){
		I_can_t_solve_it();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String S = sc.next();
		int[] abc = new int[26];
		for(int j = 0; j < S.length(); j++)
			abc[S.charAt(j)-97] += 1;
		StringBuilder ans = new StringBuilder();
		for(int i = 1; i < n; i++) {
			S = sc.next();
			int[] nextabc = new int[26];
			for(int j = 0; j < S.length(); j++)
				nextabc[S.charAt(j)-97] += 1;
			for(int j = 0; j < 26; j++)
				abc[j] = Math.min(abc[j], nextabc[j]);
		}
		for(int i = 0; i < 26; i++) {
			for(int j = 0; j < abc[i]; j++)
				ans.append((char)(i+97));
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define INT long long int
#define oo 987654321
#define MOD 1000000007
using namespace std;
INT a, b, c;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b>>c;
    if( a == b and b == c ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c);
	
	printf("%d\n", n - (a + b - c));
	return 0;
}



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

using namespace std;

int main() {
	string S;
	cin >> S;
	int count = 0;

	for (int i = 0; i < 3; i++) {
		if (S[i] == 'A')count++;
	}
	if (count == 0 || count == 3)cout << "No";
	else cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#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 INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //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(){
    string N;
    cin >> N;
    int L = N.length();

    vector<ll> dp0(L+1), dp1(L+1);
    dp0[0] = 0;
    dp1[0] = 2;
    for (ll i = 1; i < L+1; i++) {
        dp0[i] = min(dp0[i-1], dp1[i-1]) + (N[i-1] - '0');
        if(N[i-1] == '9'){
            dp1[i] = dp1[i-1] + 9 - (N[i-1] - '0');
        }
        else{
            dp1[i] = min(min(dp0[i-1] + (N[i-1] - '0') + 2, dp1[i-1] + (N[i-1] - '0') + 2), dp1[i-1] + 9 - (N[i-1] - '0'));
        }
    }

    printf("%lld\n", min(dp0[L], dp1[L]));

    


}

Measured memory_bytes: 20076
import numpy as np

H, N = map(int, input().split())
AB = np.array([list(map(int, input().split())) for i in range(N)])
A = AB[:, 0]
B = AB[:, 1]

dp = np.array([0]*(H+1))

for i in range(1, H+1):
    dp[i] = min(dp[np.maximum(i - A, 0)] + B)

print(dp[-1])

    


Measured memory_bytes: 12684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
const ll L = 2e5 + 5;
ll arr[L];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    set <ll> as;
    map <ll, ll> m;
    for (ll i = 1; i <= n; i++) {
    	cin >> arr[i];
    	arr[i] -= i;
    	as.insert(arr[i]);
    	m[arr[i]]++;
    }
    vector <ll> vec;
    for (auto it : as) {
    	vec.pb(it);
    }
    vector <ll> lef(sz(vec));
    vector <ll> rit(sz(vec));
    vector <ll> ctl(sz(vec));
    vector <ll> ctr(sz(vec));
    ctl[0] = 0;
    ctr[sz(vec) - 1] = 0;
    for (ll i = 1; i < sz(vec); i++) {
    	ctl[i] = ctl[i - 1] + m[vec[i - 1]];
    }
    for (ll i = sz(vec) - 2; i >= 0; i--) {
    	ctr[i] = ctr[i + 1] + m[vec[i + 1]];
    }
    lef[0] = 0;
    rit[sz(vec) - 1] = 0;
    for (ll i = 1; i < sz(vec); i++) {
    	lef[i] = lef[i - 1] + m[vec[i - 1]] * vec[i - 1];
    }
    for (ll i = sz(vec) - 2; i >= 0; i--) {
    	rit[i] = rit[i + 1] + m[vec[i + 1]] * vec[i + 1];
    }
    ll ans = 1e18;
    for (ll i = 0; i < sz(vec); i++) {
    	ll temp = ctl[i] * vec[i] - lef[i] + rit[i] - ctr[i] * vec[i];
    	ans = min(ans, temp);
    }
    cout << ans << endl;
	return 0;
}

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

using namespace std;

const int N =  1e5+10;
using ll = long long;

int freq[N*2], a[N*2];

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

	int n;
	cin >> n;
	
	for (int i = 0 ; i < n; i++) cin >> a[i], ++freq[a[i]];
	
	ll ans = 0;
	
	for (int i = 0 ; i <= n; i++) 
		ans += (ll)freq[i]*(freq[i]-1)/2;

	for (int i = 0 ; i < n; i++) 
		cout << ans - freq[a[i]] + 1 << '\n';
	
	return 0;
}


Measured memory_bytes: 3712
import Data.Char
countChar :: [Char] -> Char -> Integer
countChar [] chr     = 0
countChar (x:xs) chr = (if (x==chr) || (x==toUpper chr) then 1 else 0) + (countChar xs chr)
main = do{
    str <- getContents;
    let{
        count = [ chr : " : " ++ (show (countChar str chr)) | chr<-['a'..'z'] ];
    };
    mapM_ putStrLn $ count;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int N=2e5+5;
int n,A,B,cnt,ans1,ans2,num,c[N],w[N],jc[N],inv[N],fa[N],a[N],id[N],sum[N],xu[N];
vector<int>b[N];
struct node{
	int val,id;
}xjh[N];
char buf[1<<21],*p1=buf,*p2=buf;
inline int gc()
{
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
	int res=0,f=0;
	char c;
	c=gc();
	while(!isdigit(c))
	{
		if(c=='-')f=1;
		c=gc();
	}
	while(isdigit(c))
	{
		res=res*10+c-48;
		c=gc();
	}
	if(f)return -res;
	else return res;
}
int find(int x)
{
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
int kuai(int a,int b)
{
	if(b==1)return a;
	int x=kuai(a,b/2);
	if(b%2==0)return x*x%mod;
	else return x*x%mod*a%mod;
}
bool cmp(node a,node b)
{
	return a.val<b.val;
}
signed main()
{
	n=read();A=read();B=read();
	for(int i=1;i<=n;i++)
	{
		c[i]=read(),w[i]=read();
		xu[i]=c[i];
	}
	sort(xu+1,xu+n+1);
	int len=unique(xu+1,xu+n+1)-xu-1;
	for(int i=1;i<=len;i++)xjh[i].val=1e18;
	for(int i=1;i<=n;i++)
	{
		c[i]=lower_bound(xu+1,xu+len+1,c[i])-xu;
		if(xjh[c[i]].val>w[i])
		{
			xjh[c[i]].val=w[i];
			xjh[c[i]].id=i;
		}
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=n;i++)
		if(w[i]+xjh[c[i]].val<=A)fa[find(i)]=xjh[c[i]].id;
	sort(xjh+1,xjh+len+1,cmp);
	for(int i=1;i<=n;i++)
		if(c[i]!=c[xjh[1].id]&&w[i]+xjh[1].val<=B)fa[find(i)]=xjh[1].id;
	for(int i=1;i<=n;i++)
		if(c[i]==c[xjh[1].id]&&w[i]+xjh[1].val<=A)fa[find(i)]=xjh[1].id;
	for(int i=1;i<=n;i++)
		if(c[i]==c[xjh[1].id]&&w[i]+xjh[2].val<=B)fa[find(i)]=xjh[1].id;
	jc[0]=1ll;
	for(int i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;
	inv[1]=1ll;
	for(int i=2;i<=n;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=n;i++)inv[i]=inv[i]*inv[i-1]%mod;
	for(int i=1;i<=n;i++)
	{
		if(!a[find(i)])
		{
			id[find(i)]=++cnt;
			a[find(i)]=1;
		}
		sum[id[find(i)]]++;
		b[id[find(i)]].push_back(c[i]);
	}
	for(int i=1;i<=cnt;i++)sort(b[i].begin(),b[i].end());
	ans1=1ll;
	for(int i=1;i<=cnt;i++)
	{
		ans2=jc[sum[i]];
		num=1ll;
		for(int j=1;j<sum[i];j++)
			if(b[i][j]!=b[i][j-1])
			{
				ans2=ans2*inv[num]%mod;
				num=1ll;
			}
			else num++;
		
		ans2=ans2*inv[num]%mod;
		ans1=ans1*ans2%mod;
	}
	cout<<ans1;
	return 0;
}
/*
3 7 5
1 3
1 4
2 2
*/

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

int main(){
    int K, S;
    cin >> K >> S;
    int ans =0;

    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            int k = S - i - j;
            if ( k>=0 && k<=K){
                ans +=1;
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
 string s;
 int count = 0;
 
 cin >> s;
 
 for(int i = 0; i < s.size(); i++){
  if(i % 2 != 0){
   if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
    continue;
   }
   else{
    count++;
    break;
   }
  }
  else if(i % 2 == 0 || i == 0){
   if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
    continue;
   }
   else{
    count++;
    break;
   }
  }
 }
 
 if(count == 0){
  cout << "Yes" << endl;
 }
 else{
  cout << "No" << endl;
 }
 
 return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,T;
    R(N,T);
    int an=1e9;
    REP(i,N){
        int x,y;
        R(y,x);
        if(x<=T){
            an=min(an,y);
        }
    }
    if(an<=1e5)W(an);
    else W("TLE");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long value = 0;
        
        for (long i = 1; i <= n; i++) {
            if (i % 3 != 0 && i % 5 != 0) value += i;
        }
        
        System.out.println(value);
    }
}


Measured memory_bytes: 27188
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int e[15][15];
int dp2[1<<15];
int dfs2(int b){
  if(~dp2[b]) return dp2[b];
  if(b==0) return dp2[0]=0;
  //cout<<bitset<15>(b)<<endl;
  int res=0;
  for(int i=0;i<n;i++){
    if((b>>i)&1){
      int nb=b^(1<<i);
      int tmp=0;
      for(int j=0;j<n;j++){
	if(e[i][j]<0) continue;
	if((b>>j)&1) tmp+=e[i][j];
      }
      //cout<<tmp<<endl;
      res=max(res,dfs2(nb)+tmp);
    }
  }
  //cout<<bitset<15>(b)<<":"<<res<<endl;
  return dp2[b]=res;
}
int dp[15][1<<15];
int dfs(int v,int b);
int rec(int v,int b,int k,int p){
  int res=INT_MIN;
  for(int i=p;i<n-1;i++){
    if(((b>>i)&1)||((k>>i)&1)) continue;
    res=max(res,rec(v,b,k|(1<<i),i+1));
    //if(v==0) cout<<res<<endl;
  }
  for(int i=0;i<n;i++){
    if(((b>>i)&1)||((k>>i)&1)) continue;
    if(e[v][i]<0) continue;
    res=max(res,dfs(i,b|k)+e[v][i]+dp2[k]);
  }
  return res;
}
int dfs(int v,int b){
  if(~dp[v][b]) return dp[v][b];
  //cout<<v<<":"<<bitset<15>(b)<<endl;
  if(v==n-1){
    int nb=(~b)&((1<<n)-1);
    return dp[v][b]=dp2[nb];
  }
  return dp[v][b]=rec(v,b,(1<<v),0);
}
  
signed main(){
  cin>>n>>m;
  memset(e,-1,sizeof(e));
  int sum=0;
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    e[a][b]=e[b][a]=c;
    sum+=c;
    //cout<<c<<endl;
  }
  //cout<<sum<<endl;
  memset(dp2,-1,sizeof(dp2));
  dfs2((1<<n)-1);
  assert(dp2[(1<<n)-1]==sum);
  //cout<<dp2[0]<<endl;
  memset(dp,-1,sizeof(dp));
  cout<<sum-dfs(0,0)<<endl;
  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
cs int N = 2e5 + 50;
int n; ll a[N], b[N], c[N];
bool chk(int i, int j, int k){
	return (a[j]-a[i]) * (k-i) <= (a[k]-a[i]) * (j-i);
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	for(int i=1; i<=n; i++) scanf("%lld",&b[i]);
	int pt = 0;
	for(int i=1; i<=n; i++) if(a[pt] < a[i]) pt = i;
	static ld rm[N];
	rm[0] = a[pt]; int bn=0;
	for(int i=pt+1; i<=n; i++) rm[++bn] = a[i];
	for(int i=1; i<=pt; i++) rm[++bn] = a[i];
	for(int i=0; i<=n; i++) a[i] = rm[i];
	rm[0] = b[pt]; bn=0;
	for(int i=pt+1; i<=n; i++) rm[++bn] = b[i];
	for(int i=1; i<=pt; i++) rm[++bn] = b[i];
	for(int i=0; i<=n; i++) b[i] = rm[i];
	for(int i=2; i<=n; i++) c[i] = 2 * (c[i-1] + b[i-1]) - c[i-2];
	for(int i=1; i<=n; i++) a[i] -= c[i];
	static int sta[N]; int top=0;
	for(int i=0; i<=n; i++){
		while(top>1 && chk(sta[top-1],sta[top],i)) --top;
		sta[++top] = i; 
	} ld ans = 0;
	for(int i=1; i<top; i++){
		ll d = sta[i+1] - sta[i];
		ans += a[sta[i]] * (d+1) + a[sta[i+1]] * (d-1);
	} ans = ans * 0.5;
	for(int i=0; i<n; i++) ans += c[i];
	printf("%.12lf",(double)ans/n); return 0;
}

Measured memory_bytes: 12188
#include <iomanip>
#include <limits>
#include <thread>
#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <list>
#include <functional>
#include <bitset>
#include <complex>
#include <tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;
typedef complex<D> P;
const ll E = 1e18 + 7;
const ll MOD = 1000000007;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fill(x, y) memset(x, y, sizeof(x))
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
template <class... A>
void prints() { cout << endl; }
template <class... A>
void prints_rest() { cout << endl; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

template <class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    if ( (A+B) % 2 == 0) {
        prints((A+B) / 2);
    }
    else prints("IMPOSSIBLE");

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
 
typedef struct node{
 struct node *right;
 struct node *left;
 struct node *parent;
 int key;
}*Node;
  
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int i,n,x;
  char S[20];

  scanf("%d", &n);
     
  for ( i = 0; i < n; i++ ){
    scanf("%s", S);
      if ( S[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( S[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent= y;
  if(y==NIL){
    root = z;
  }
  else if(z->key<y->key){
    y->left =z;
  }
  else{
    y->right =z;
  }
}
   
void inorder(Node A){
  if(A != NIL){
    inorder(A->left);
    printf(" %d",A->key);
    inorder(A->right);
  }
}
   
void preorder(Node A){
  if(A!=NIL){
    printf(" %d",A->key);
    preorder(A->left);
    preorder(A->right);
  }
}

Measured memory_bytes: 24040
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<memory.h>
#include<map>
#include<set>
#include<queue>
using namespace std;
inline bool odd(int k) {return k&1;}
int main()
{
	int a[3];
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	if(odd(a[2]-a[1]))
	{
		if(odd(a[1]-a[0]))printf("%d",(a[2]-a[0])/2+(a[2]+1-a[1])/2+1);
		else printf("%d",(a[2]*2-a[0]-a[1])/2);
	}else
	{
		if(odd(a[1]-a[0]))printf("%d",(a[2]-a[0]+1)/2+(a[2]-a[1])/2+1);
		else printf("%d",(a[2]*2-a[0]-a[1])/2);
	}
}

Measured memory_bytes: 888
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        res = 0
        for z in range(d):
            res += (x[i][z]-x[j][z])**2
        if math.sqrt(res)==math.floor(math.sqrt(res)):
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
n,a,b=map(int,input().split())
s=input()
p,pb=0,0
for i,j in enumerate(s,start=1):
  if j=="a" and p<a+b:
    p+=1
    print("Yes")
  elif j=="b" and p<a+b and pb<b:
    p+=1
    pb+=1
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 55000
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] ary = new int[n];
		for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		}
		output(ary);
		for (int i=1; i<ary.length; i++) {
			int key = ary[i];
			int j = i - 1;
			while (j>=0 && ary[j]>key) {
				ary[j+1] = ary[j];
				j--;
			}
			ary[j+1] = key;
			output(ary);
		}
	}
	static void output(int[] a) {
		for (int i=0; i<a.length; i++) {
			System.out.print(a[i]);
			if(i<a.length-1)
				System.out.print(" ");
			else 
				System.out.println();
		}
	}
}

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

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

    int cnt = 0;
    for (int i = 1; i <= (n - 2); ++i)
    {
        if (p[i-1] < p[i] && p[i] < p[i+1])
        {
            cnt += 1;
        }
        else
        if (p[i-1] > p[i] && p[i] > p[i+1])
        {
            cnt += 1;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

int64_t mod = 998244353 ;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int count(vector<vector<char> > &s, int x, int y,int h, int w){
    int re = 0 ;
    for (int i = max(x-1,0); i < min(h,x+2); i++)
    {
        for (int j = max(y-1,0); j < min(y+2,w); j++)
        {
            if (s.at(i).at(j) == '#')
            {
                re ++ ;
            }
            
        }
        
    }
    return re ;
}

int main(){
    int h,w ;
    cin >> h >> w ;
    vector<vector<char> > s(h,vector<char>(w)) ;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> s.at(i).at(j) ;
        }
        
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s.at(i).at(j) == '.')
            {
                s.at(i).at(j) = '0' + count(s,i,j,h,w) ;
            }
            
        }
        
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << s.at(i).at(j) ;
        }
        cout << endl ;
    }
    
    
}

Measured memory_bytes: 3648
#pragma comment(linker, "/STACK: 2000000")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define double long double
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 1000000007;
string s;
int k, dp[101][5][2];//0 - < n, 1 = n

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>s>>k;
	int n=s.size();
	dp[0][0][1]=1;
	for(int i=1; i<=n; i++){
		char cur=s[i-1];
		for(char nxt='0'; nxt<='9'; nxt++){
			for(int kk=0; kk<=k; kk++){
				for(int ctrl=0; ctrl<=1; ctrl++){
					if(!(ctrl==1 && nxt>cur)) dp[i][kk+(nxt!='0')][((ctrl==1 && nxt==cur) ? 1 : 0)]+=dp[i-1][kk][ctrl];
				}
			}
		}
	}
	cout<<dp[n][k][0]+dp[n][k][1];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

const int INF=1e9+7;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ll under=0LL;
  ll top=0LL;
  ll ans=0LL;
  for (int i=0;i<n;i++){
    int r=n,l=-1;
    while(r-l > 1){
      int mid=(r+l)/2;
      if (a[mid] >= b[i]){
        r=mid;
      }
      else{
        l=mid;
      }
    }
    top=l+1;
    int ub=n,lb=-1;
    while(ub-lb > 1){
        int mid=(ub+lb)/2;
        if (c[mid] > b[i]){
          ub=mid;
        }
        else{
          lb=mid;
        }
    }
    under=n-ub;
    //printf("top = %d under = %d ans = %d\n",top,under,ans); 
    ans+=(top*under);
  } 
  cout << ans << endl;
  //printf("%d\n",ans);
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  while(1){
    C = C - B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A = A - D;
    if(A <= 0){
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3528