akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, a[100001], b[100001], c[200005];
long long sum[200005];
void checkmin(long long &x, long long y)
{
    if (x > y)
    {
        x = y;
    }
}
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    long long ans, sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &a[i], &b[i]);
        c[2 * i - 1] = a[i];
        c[2 * i] = b[i];
        sum1 += a[i];
        sum2 += b[i];
    }
    ans = min(sum1, sum2);
    sort(c + 1, c + 2 * n + 1);
    for (int i = 1; i <= 2 * n; i++)
    {
        sum[i] = sum[i - 1] + c[i];
    }
    for (int i = 1; i <= n; i++)
    {
        int x = min(a[i], b[i]), y = max(a[i], b[i]), pos1 = lower_bound(c + 1, c + 2 * n + 1, x) - c, pos2 = lower_bound(c + 1, c + 2 * n + 1, y) - c;
        if (pos1 <= n - 2)
        {
            if (pos2 <= n - 1)
            {
                checkmin(ans, sum[n]);
            }
            else
            {
                checkmin(ans, sum[n - 1] + y);
            }
        }
        else
        {
            checkmin(ans, sum[n - 2] + x + y);
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 6972
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
		printf("%d\n", a * b);
	} else{
		puts("-1");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define EPS 1e-8
#define equals(a,b) fabs((a) - (b)) < EPS

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct Point3D {
	double x, y, z;

	Point3D() : x(0), y(0), z(0) {}

	Point3D(double x, double y, double z) : x(x), y(y), z(z) {}

	Point3D operator+(const Point3D &o) const { return Point3D(x+o.x, y+o.y, z+o.z); }

	Point3D operator-(const Point3D &o) const { return Point3D(x-o.x, y-o.y, z-o.z); }

	Point3D operator*(const double m) const { return Point3D(x*m, y*m, z*m); }

	Point3D operator/(const double d) const { return Point3D(x/d, y/d, z/d); }

	bool operator==(const Point3D &o) const { return fabs(x-o.x) < EPS && fabs(y-o.y) < EPS; }
};

ostream& operator << (ostream& os, const Point3D& p) {
	os << "(" << p.x << ", " << p.y << ", " << p.z << ")";
	return os;
}

double dot(Point3D a, Point3D b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
Point3D cross(Point3D a, Point3D b) { return Point3D(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); }

double norm(Point3D p) { return dot(p, p); }
double abs(Point3D p) { return sqrt(norm(p)); }

struct Line {
	Point3D a, b;

	Line() : a(Point3D(0, 0, 0)), b(Point3D(0, 0, 0)) {}

	Line(Point3D a, Point3D b) : a(a), b(b) {}
};

ostream& operator << (ostream& os, const Line& l) {
	os << "(" << l.a.x << ", " << l.a.y << ", " << l.a.z <<  ")-(" << l.b.x << "," << l.b.y << ", " << l.b.z <<  ")";
	return os;
}

Point3D project(Line l, Point3D p) {
	Point3D base = l.b - l.a;
	double t = dot(base, p-l.a) / dot(base, base);
	return l.a + base * t;
}

struct Ball {
	Point3D p;
	double r;

	Ball() : p(Point3D(0, 0, 0)), r(0.0) {}

	Ball(Point3D p, double r) : p(p), r(r) {}
};

ostream& operator << (ostream& os, const Ball& b) {
	os << "(" << b.p.z << ", " << b.p.y << ", " << b.p.z << " :" << b.r << ")";
	return os;
}

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

	vector<Ball> v(n);
	vector<ll> cost(n);
	rep(i, n) {
		cin >> v[i].p.x >> v[i].p.y >> v[i].p.z >> v[i].r >> cost[i];
	}

	rep(i, q) {
		ll ans = 0;
		Point3D s, t;
		cin >> s.x >> s.y >> s.z >> t.x >> t.y >> t.z;

		Line line(s, t);

		rep(j, n) {
			Point3D proj = project(line, v[j].p);

			if(abs(line.b - line.a) >= abs(proj - line.a) && abs(line.a - line.b) >= abs(proj - line.b)) {
				if(abs(proj - v[j].p) < v[j].r + EPS) {
					ans += cost[j];
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F         first
#define S          second
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e9+1;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);


void solve(){

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

  int x=a-2*b;
  cout<<max(0,x);
  
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int x,k;
  cin>>k>>x;
  int lb = max(-1000000,x-k+1);
  int ub = min(1000000,x+k-1);
  int i;
  for(i=lb;i<=ub;i++)
    cout<<i<<" ";
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "algorithm"

typedef struct {
	int a;
	int b;
}Magic;

int main(void) {
	int h, n;
	std::cin >> h;
	std::cin >> n;
	std::vector<Magic> magic(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> magic[i].a;
		std::cin >> magic[i].b;
	}

	std::vector<int> num(h + 1);

	for (int i = 1; i <= h; ++i) {
		int min = -1;
		for (int j = 0; j < n; ++j) {
			int tmp;
			if (magic[j].a >= i)
				tmp = magic[j].b;
			else
				tmp = num[i - magic[j].a] + magic[j].b;
			if (min == -1 || tmp < min)
				min = tmp;
		}
		num[i] = min;
	}

	std::cout << num[h];
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  int n, k; cin >> n >> k;
  vector<ll> h; h.resize(n);
  for(int i=0; i<n; i++) cin >> h[i];
  sort(h.begin(), h.end(), greater<ll>());
  ll ans=0;
  for(int i=k; i<n; i++){
    ans += h[i];
  }
  cout << ans << "\n";
}

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;

	if (a * b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
}


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

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k,s,i;
    cin>>n>>k>>s;
    vector<ll>v;
    for(i=0;i<k;i++)
    v.push_back(s);
    while(i<n)
    {
    	if(s!=1000000000)
    	v.push_back(s+1);
    	else
    	v.push_back(s-1);
    	i++;
	}
    for(i=0;i<n;i++)
    cout<<v[i]<<"\n";

}

Measured memory_bytes: 2292
#include<iostream>
#include<cmath>
using namespace std;
int dyf[11][11];
int main()
{

	int n, d,ans=0;
	double asdf; 
	cin>>n>>d;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
		{
			cin>>dyf[i][j];	
		}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			asdf=0;
			for(int k=1;k<=d;k++)
			{
				asdf+=(dyf[i][k]-dyf[j][k])*(dyf[i][k]-dyf[j][k]);
			}
			asdf=sqrt(asdf);
			if(floor(asdf)==asdf)
				ans++;
		}
	}
	cout<<ans;
	return 0;
	
}        

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    ll ans = 0,sum = 0;
    rep(i,n) {
        if (sum*2 < a[i]) {
            ans = 0;
        }
        sum += a[i];
        ++ans;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 4024
n, k = input().split()
n = int(n) #友人の数
k = int(k) #基準の高さ
h = input().split()
result = 0
#各人の身長を基準の高さと比較
for i in range(n):
  if k <= int(h[i]):
    result += 1
  else:
    result -= 0
print(result)

Measured memory_bytes: 9988
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define NOTUSED 0
using Graph = vector<vector<int>>;

int gcd(int x,int y){   // x>=y
    if(x%y==0){
        return y;
    }else{
        return gcd(y,x%y);
    }
}

int main(){
    int x,y;
    cin>>x>>y;
    
    if(x<y){
        swap(x,y);
    }

    cout<<gcd(x,y)<<endl;
}


Measured memory_bytes: 3084
#include<stdio.h>
int fun(int n){
  int ans;
  if(n % 2 == 0){
    ans = n / 2;
  }else{
    ans = 3 * n + 1;
  }
  return ans;
}
int main(){
  int s,a[1000000];
  scanf("%d",&s);
  a[1] = s;
  for(int i = 2;i < 1000000;i++){
    a[i] = fun(a[i - 1]);
    for(int j = 1;j < i;j++){
      if(a[i] == a[j]){
        printf("%d",i);
        return 0;
      }
    }
  }
}


Measured memory_bytes: 128
#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; }

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

  ll k;
  cin >> k;

  vector<vector<string>> ss('z'-'a'+1);
  map<string, bool> seen;
  for (ll i = 0; i < s.size(); ++i) {
    for (ll j = 1; j <= min(s.size()-i, ull(10)); ++j) {
      auto c = s.substr(i, j);
      if (seen.count(c)) continue;
      seen[c] = true;
      ss[c[0]-'a'].push_back(c);
    }
  }

  for (ll i = 0; i < 'z'-'a'+1; ++i) {
    sort(ss[i].begin(), ss[i].end());
    for (ll j = 0; j < ss[i].size(); ++j) {
      --k;
      if (k == 0) {
        cout << ss[i][j] << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

int main() {
	int N;
	std::cin >> N;

	std::vector<int> A(N);
	for(int &a : A) {
		std::cin >> a;
	}

	std::sort(A.begin(), A.end(), [](int a, int b) {
		return a < b;
	});

	int result;
	while(true) {
		const int n = A[0];
		for(auto itr = A.begin() + 1; itr != A.end();) {
			*itr %= n;
			if(*itr == 1) {
				result = 1;
				goto RESULT;
			} else if(*itr == 0) {
				itr = A.erase(itr);
			} else {
				itr++;
			}
		}

		if(A.size() == 1) {
			result = A[0];
			break;
		}

		std::sort(A.begin(), A.end(), [](int a, int b) {
			return a < b;
		});
	}

RESULT:
	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

int main(void) {
    ll n, i, j;
    ll r;
    cin >> r;
    
    
    if(r<1200) {
        cout << "ABC" << endl;
        return 0;
    }else if(r<2800) {
        cout << "ARC" << endl;
        return 0;
    }else {
        cout << "AGC" << endl;
        return 0;
    }
    
    
    
    
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int a,b,c,K; cin>>a>>b>>c>>K;

  bool f=false;
  rep(i, K+1)rep(j, K+1)rep(k,K+1){
    if(i+j+k>K)continue;
    if(a*pow(2,i) < b*pow(2,j) && b*pow(2,j)<c*pow(2,k) )f=true;
  }

  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}



Measured memory_bytes: 3952
#include <stdio.h>

int main(){
	int high[10],i,j,temp;
	for(i=0;i<10;i++){
		scanf("%d",&high[i]);
	}
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(high[i]>high[j]){
				temp=high[i];
				high[i]=high[j];
				high[j]=temp;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",high[i]);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int k;
   cin>>k;

   set<long int> s;
   long int num = 0;

   for(long int i = 0; true; i++){
     num = num * 10 + 7;
     long int rem = num % k;
     if(rem == 0)
        return cout<<i + 1,0;

    if(s.find(rem) != s.end())
      return cout<<"-1",0;

     s.insert(rem);
     num = rem;
   }
   return 0;
}

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

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

int main(){
    ll n,k;
    cin >> n >> k;
    ll x=n%k;

    /*
    if(n%k==0){
        cout << "0" << endl;
        return 0;
    }
    */

    while(true){
        if(abs(x-k)<x) x=abs(x-k);
        else break;
    }

    cout << x << endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heappop, heappush, heapify
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist
 
N, X, Y = MAP()
 
graph = defaultdict(list)
 
for i in range(N-1):
    graph[i].append((i+1, 1))
    graph[i+1].append((i, 1))
 
graph[X-1].append((Y-1, 1))
graph[Y-1].append((X-1, 1))
 
a = dijkstra(graph, 0)
count = defaultdict(int)
for i in range(N):
    a = dijkstra(graph, i)
    
    # print(a[i+1:])
    for c in a[i+1:]:
        count[c] += 1
# print(count)
 
for i in range(1, N):
    print(count[i])

Measured memory_bytes: 121368
def count(n):
    cnt = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a + b + c + d == n:
                        cnt += 1
    print(cnt)

while True:
    try:
        n = int(input())
        count(n)
    except EOFError:
        break



Measured memory_bytes: 5592
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=100000+5;
const int INF=0x7fffffff;
const int inf=100000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
map<ll,int>vis;
ll sum=0;
ll a[MAX_N];
int main()
{
    int n;
    cin>>n;
    int i;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        sum+=a[i];
        vis[a[i]]++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        vis[c]+=vis[b];
        sum+=(ll)(c-b)*vis[b];
        vis[b]=0;
        cout<<sum<<endl;

    }
}


Measured memory_bytes: 10248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n;
ll a[N];
ll gcd(ll a,ll b){
	return !b?a:gcd(b,a%b);
}
int main(){
	cin>>n;
	ll g=1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		g=g/gcd(g,a[i])*a[i];
	} 
	cout<<g<<endl;
	return 0;
}

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

int main() {
  int n, p;
  while (cin >> n >> p, n) {
    int a[50] = {0};

    bool f = false;
    for (int i = 0; ; ++i) {
      if (p) {
        p--;
        a[i % n]++;

        if (p == 0) {
          int cnt = 0;
          for (int j = 0; j < n; ++j) {
            if (a[j]) cnt++;
          }

          if (cnt == 1) {
            cout << i % n << endl;
            f = true;
          }
        }
      } else {
        p += a[i % n];
        a[i % n] = 0;
      }

      if (f) break;
    }
  }
}

Measured memory_bytes: 2952
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int d[N];
    REP(i, N){
        cin >> d[i];
    }

    sort(d, d+N);

    int dif = d[N/2]-d[N/2-1];
    cout << dif << endl;
}

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

using namespace std;

const int N = 2020;
const int Mod = 1e9 + 7;

int a[N];
int b[N];
int Dp[N][N];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

int add(int x, int y)
{
    return add_self(x, y), x;
}

void sub_self(int& x, int y)
{
    if((x -= y) < 0)    x += Mod;
}

int sub(int x, int y)
{
    return sub_self(x, y), x;
}

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

    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int j = 1; j <= m; j++) scanf("%d", b + j);

    for(int i = 0; i <= n; i++) Dp[i][0] = 1;
    for(int j = 0; j <= m; j++) Dp[0][j] = 1;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            Dp[i][j] = add(Dp[i - 1][j], Dp[i][j - 1]);

            if(a[i] != b[j])    sub_self(Dp[i][j], Dp[i - 1][j - 1]);
        }
    }

    cout << Dp[n][m] << endl;
}


Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    int num[n];
    rep(i,n){
        cin >> num[i];
    }
    int count = 0;
    for(int i=1;i<n-1;i++){
        if(num[i-1] < num[i] && num[i] < num[i+1]){count++; continue;}
        if(num[i-1] > num[i] && num[i] > num[i+1]){count++; continue;}
    }
    cout << count << endl;
}

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

int main() {
  
  int N,a,b,c,d;
  
  cin >> N;
  
  a = N/1000, b = (N%1000)/100, c = ((N%1000)%100)/10, d = ((N%1000)%100)%10 ;
  
  if (a == b && b == c) {
    cout << "Yes" << endl;
  }
  else if (b == c && c == d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
       
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)
    a *= -1
    a //= 2
    a *= -1
    heapq.heappush(A, a)

A = [-1 * a for a in A]
print(sum(A))


Measured memory_bytes: 14180
A = []
for i in range(3):
  A.extend(list(map(int, input().split())))

N = int(input())
B = [int(input()) for i in range(N)]

for i in B:
  if i in A:
    A[A.index(i)] = 0

if A[0] == A[3] == A[6]:print("Yes")
elif A[1] == A[4] == A[7]:print("Yes")
elif A[2] == A[5] == A[8]:print("Yes")
elif A[0] == A[1] == A[2]:print("Yes")
elif A[3] == A[4] == A[5]:print("Yes")
elif A[6] == A[7] == A[8]:print("Yes")
elif A[0] == A[4] == A[8]:print("Yes")
elif A[2] == A[4] == A[6]:print("Yes")
else:print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <array>
using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

enum FACE { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM }; // 1..6
typedef array<int, 6> Dice;

FACE tbl[6][4] = {
  { TOP, BACK, BOTTOM, FRONT },
  { TOP, RIGHT, BOTTOM, LEFT },
  { TOP, FRONT, BOTTOM, BACK },
  { TOP, LEFT, BOTTOM, RIGHT },
  { FRONT, RIGHT, BACK, LEFT },
  { FRONT, LEFT, BACK, RIGHT }
};

enum MOVE { TOP_TO_BACK, TOP_TO_RIGHT, TOP_TO_FRONT, TOP_TO_LEFT, FRONT_TO_RIGHT, FRONT_TO_LEFT };

void rotate(Dice &d, FACE t[4]) {
  int tmp = d[t[3]];
  d[t[3]] = d[t[2]]; d[t[2]] = d[t[1]]; d[t[1]] = d[t[0]]; d[t[0]] = tmp;
}

vector<Dice> generate_all(Dice dice) {
  vector<Dice> res;
  for(int i = 0; i < 6; ++i) {
    for(int j = 0; j < 4; ++j) {
      res.emplace_back(dice);
      rotate(dice, tbl[FRONT_TO_RIGHT]);
    }
    if(i % 2 == 0) rotate(dice, tbl[TOP_TO_BACK]);
    else rotate(dice, tbl[TOP_TO_RIGHT]);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  Dice d;
  cin >> d[TOP];
  cin >> d[FRONT];
  cin >> d[RIGHT];
  cin >> d[LEFT];
  cin >> d[BACK];
  cin >> d[BOTTOM];
  string s; cin >> s;
  for(char c : s) {
    if(c == 'S') {
      rotate(d, tbl[TOP_TO_FRONT]);
    }
    if(c == 'E') {
      rotate(d, tbl[TOP_TO_RIGHT]);
    }
    if(c == 'W') {
      rotate(d, tbl[TOP_TO_LEFT]);
    }
    if(c == 'N') {
      rotate(d, tbl[TOP_TO_BACK]);
    }
  }
  cout << d[TOP] << endl;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

struct str {
	ll res, px, py;
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<int> p(n * n);
	rep(i, n * n) cin >> p[i];
	vector<vector<ll>> dis(n, vector<ll>(n));
	vector<vector<bool>> ex(n, vector<bool>(n, true));
	rep(i, n) {
		rep(j, n) {
			dis[i][j] = min({ i,n - 1 - i,j,n - 1 - j });
		}
	}
	ll ans = 0;
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };
	rep(i, n * n) {
		int x = (p[i] - 1) / n;
		int y = (p[i] - 1) % n;
		ans += dis[x][y];
		ex[x][y] = false;
		int change = inf;
		if (x != 0) chmin(change, dis[x - 1][y] + ex[x - 1][y]);
		if (x != n - 1) chmin(change, dis[x + 1][y] + ex[x + 1][y]);
		if (y != 0) chmin(change, dis[x][y - 1] + ex[x][y - 1]);
		if (y != n - 1) chmin(change, dis[x][y + 1] + ex[x][y + 1]);
		chmin(dis[x][y], change);
		queue<str> que;
		que.push({ dis[x][y],x,y });
		while (!que.empty()) {
			str q = que.front(); que.pop();
			rep(d, 4) {
				int nx = q.px + dx[d];
				int ny = q.py + dy[d];
				if (0 <= nx && nx < n && 0 <= ny && ny < n&&dis[q.px][q.py] + ex[q.px][q.py] < dis[nx][ny]) {
					dis[nx][ny] = dis[q.px][q.py] + ex[q.px][q.py];
					que.push({ dis[nx][ny],nx,ny });
				}
			}
		}

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

Measured memory_bytes: 6304
#include<iostream>
#include<vector>
#include<ctime>
#include<chrono>
#include<random>
using namespace std;
using ll = long long;

int d;
vector<vector<int>> s(365,vector<int>(26));
vector<int> c(26);

auto start=chrono::system_clock::now();
inline double get_time(){
    auto end=chrono::system_clock::now();
    auto dur=end-start;
    double msec=chrono::duration_cast<chrono::microseconds>(dur).count();
    return msec;
}

ll calc(vector<int> t){
    ll score=0;
    vector<int> last(26);
    for(int i=0;i<(int)t.size();i++){
        last[t[i]]=i;
        for(int j=0;j<26;j++) score-=c[j]*(i+1-last[j]);
        score+=s[i][t[i]];
    }
    return score;
}

void solve(){
    vector<int> v(d);
    srand(time(NULL));
    for(int i=0;i<d;i++) v[i]=rand()%26;
    ll score=calc(v);
    while(get_time()<1850000){
        int i=rand()%d;
        int q=rand()%26;
        int old=v[i];
        v[i]=q;
        ll new_score=calc(v);
        if(score>new_score) v[i]=old;
        else score=new_score;
    }
    for(int k : v) cout<<k+1<<endl;
}

int main(){
    cin>>d;
    for(int i=0;i<26;i++){
        cin>>c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin>>s[i][j];
        }
    }
    solve();
}

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

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
*/

int checkpoint_num=0;
void pcheck(){
    cout << "----------------" << endl << checkpoint_num << endl << "----------------" << endl;
    checkpoint_num +=1;
}

template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
}

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
}



int main(void){
    int N,A,B,C;
    scanf("%d %d %d %d",&N,&A,&B,&C);
    vector<int> l;
    for (int i =0; i < N; ++i){
        int temp;
        scanf("%d",&temp);
        l.push_back(temp);
    }

    long long ans = 100000000000000000000;

    for (int i = 0; i < pow(4,N); ++i){
        vector<int> temp(3,0);
        vector<int> joint(3,-1);
        int copy = i*1;
        for (int j = 0;j<N;++j){
            int s=0;

            s += copy&3;
            copy = copy >> 2;
            if (s==0){
                continue;
            }else{
                temp[s-1]+=l[j];
                joint[s-1]+=1;
            }
        }
        if (temp[0]==0||temp[1]==0||temp[2]==0){
            continue;
        }
            int cost =0;
            cost += abs(A-temp[0]);
            cost += abs(B-temp[1]);
            cost += abs(C-temp[2]);

            for (int k = 0; k <3; ++k){
                if (joint[k] > 0){
                    cost += joint[k]*10;
                }
            }
            if (cost < ans){
                ans = cost;
            }

    }
    cout << ans << endl;

};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
void solve()
{
    vector < int > ans(9,0);
    int x,res=0;
    while(n--)
    {
        cin>>x;
        ans[(x/400>=8?8:x/400)]++;
    }
    for (x=0;x<8;x++)
        if (ans[x]) res++;
    cout<<(res?res:1)<<" "<<res+ans[8]<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

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

using namespace std;
#define ll long long
#define ld long double

ll sum(ll n) {
    return n*(n+1)/2;
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    ll n;
    cin >> n;    
    ll res = sum(n) - sum(n/3)*3 - sum(n/5)*5+sum(n/15)*15;
    cout << res << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N;

int main(){
	cin >> N;
	vector<double> vec(N);

	rep(i, N)  cin >> vec[i];
	sort(vec.begin(), vec.end());

	double cur = vec[0];
	for(ll i = 1; i < N; i++) {
		cur = (cur + vec[i])/2.0;
	}

	printf("%.20f\n", cur);

}

Measured memory_bytes: 3808
def i_input(): return int(input())


def i_map(): return map(int, input().split())


def i_list(): return list(i_map())


def i_row_list(N): return [i_list() for _ in range(N)]


n = i_input()
d = i_row_list(n)
ans = 'No'
cnt = 0
for d1, d2 in d:
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt > 2:
        ans = 'Yes'
        break

print(ans)


Measured memory_bytes: 9096
r, c = map(int, input().split())
nums = []
for i in range(r):
	nums.append(list(map(int, input().split())))
c_nums = [0 for i in range(c)]
for r_nums in nums:
	print(' '.join(list(map(str, r_nums))), sum(r_nums))
	index = 0
	for r_num in r_nums:
		c_nums[index] += r_num
		index += 1
print(' '.join(list(map(str, c_nums))), sum(c_nums))



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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9 + 7;

const int dx[] = {0, 0,1,-1,1,-1, 1,-1};
const int dy[] = {1,-1,0, 0,1,-1,-1, 1};

const int N = 5e3 + 5;
const long long INF = 1e18;

int add(int a, int b){
        return (a + b) % mod;
}
int mul(int a, int b){
    return  (1ll * a * b) % mod;
}
int fp(int b, int p){
        int ret = 1;
        while(p){
            if(p & 1)
                    ret = mul(ret,b);
            b = mul(b,b);
            p >>= 1;
        }
        return ret;
}

int f[N];
int inv[N];
void init(){
    f[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <N; ++i){
        f[i] = mul(i,f[i - 1]);
        inv[i] = fp(f[i],mod - 2);
    }
}
int nCr(int n , int r){
    return mul(f[n],mul(inv[n-r],inv[r]));

}

int dp[2005][2005][4];
int solve(int blue, int red,int lstBlue){

        if(blue < 0 || red < 0)
                return 0;
        if(blue == 0 and red == 0)
                return 1;
        int &ret = dp[blue][red][lstBlue];
        if(~ret)
            return ret;
        ret = 0;
        if(lstBlue == 2){ // didn't put any ball yet
            ret = add(ret, solve(blue - 1,red,1));
            ret = add(ret, solve(blue,red - 1,0));
        }else if(lstBlue == 1){ // last ball was blue
            ret = add(ret,solve(blue,red - 1,0));
        }else{ // last ball was red
            ret = add(ret, solve(blue , red - 1,0));
            ret = add(ret, solve(blue - 1,red,1));
        }
        return ret;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    init();
    int n , k;
    cin >> n >> k;
    memset(dp,-1,sizeof dp);
    for(int i = 1; i <= k; ++i){
        if(n - k + 1 >= i and k >= i)
            cout << mul(solve(i,n - k , 2),nCr(k - 1, i - 1)) << '\n';
        else cout << 0 << '\n';
    }
    return 0;
}


Measured memory_bytes: 63232
N, K = map(int, input().split())
P = list(map(int, input().split()))

EP = [(p+1)*0.5 for p in P]


ans = sum(EP[:K])
now = ans
for i in range(N-K):
  now = now - EP[i] + EP[i+K]
  ans = max(ans, now)


print(ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
 
  int main(){
 lint N,ans=0,a=0,b=0,count=0;
 string s;
 cin >>N;
    rep(i,N){
        cin>>s;
        if(s[0]=='B'&&s[s.size()-1]=='A'){
            count++;
            a--;
            b--;
        }
        rep(j,s.size()-1){
            if(j==0&&s[j]=='B')b++;
             if(j==(s.size()-2)&&s[j+1]=='A')a++;
            if(s[j]=='A'&&s[j+1]=='B')ans++;
          
        }
     
    }
  if(count==0)  ans+=min(a,b);
  else if(a+b>0)ans+=(count+min(a,b));
 else if(a+b==0)ans+=count-1;
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
const int MAX_W = 10000;
using namespace std;

int s = MAX_W;

int minCostSort(vector<int>& A) {
    int ret = 0;

    vector<bool> V(A.size());
    vector<int> B = A;
    vector<int> T(MAX_W+1);
    for (auto i = 0; i < A.size(); i++) {
        V[i] = false;
    }
    sort(B.begin(), B.end());
    for (auto i = 0; i < A.size(); i++) {
        T[B[i]] = i;
    }

    for (auto i = 0; i < A.size(); i++) {
        if (V[i]) continue;

        int cur = i;
        int S = 0;
        int m = MAX_W;
        int an = 0;
        while (1) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ret += min(S + (an-2)*m, m + S + (an+1)*s);
    }
    return ret;
}

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

    vector<int> W(n);
    for (int i = 0; i < n; i++) {
        cin >> W[i];
        s = min(s, W[i]);
    }

    int ans = minCostSort(W);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

vector<int> g[200001];
pair<int, int> c[200001];
int vis[200001], R, expc;

inline int mux(set<int> &st){
	int i = 0;
	for (set<int>::iterator it = st.begin(); it != st.end(); ++it){
		if (i == *it)++i;
		else return i;
	}
	return i;
}

void go(int v){
	vis[v] = 1;
	set<int> st1, st2;
	bool bad = false;
	f(i, 0, g[v].size()){
		int u = g[v][i];
		if (vis[u] == 1){
			R = u;
			bad = true;
			continue;
		}
		if (vis[u] == 0)go(u);
		st1.insert(c[u].first);
		st2.insert(c[u].second);
	}
	c[v] = make_pair(mux(st1), mux(st2));
	if (bad)++c[v].second, expc = c[v].first;
	vis[v] = 2;
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n + 1){
		int t;
		scanf("%d", &t);
		g[t].push_back(i);
	}
	f(i, 1, n + 1)if (vis[i] == 0)go(i);
	if (R == 0 || c[R].first != expc || c[R].second == expc)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 42368
#include<stdio.h>
char str[2];
int main(){
	int a;
	scanf("%d",&a);
	long long v=0;
	for(int i=0;i<a;i++){
		int b,c;
		scanf("%d%s%d",&b,str,&c);
		if(str[0]=='(')v+=c;
		else v-=c;
		if(v==0)printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 1020
"""AtCoder Beginner Contest 178.

D
"""

import sys


def input() -> str:  # noqa: A001
    """Input."""
    return sys.stdin.readline()[:-1]


def main():
    """Run."""
    mod = 1000000007
    s = int(input())

    a = [0] * (s + 1)
    a[0] = 1

    for i in range(3, s + 1):
        a[i] = a[i - 3] + a[i - 1]

    print(a[s] % mod)


main()


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

map<int,int>mmp;
vector<int>g[N];
int d[N],fa[N],pd[N],f[N],n,sz[N];

void dfs1(int x,int s,int dep){
	pd[s]+=dep;
	for(int i=0;i<g[x].size();++i) dfs1(g[x][i],s,dep+1);
}

void dfs2(int x){
	for(int i=0;i<g[x].size();++i){
		pd[g[x][i]]=f[x]-2*sz[g[x][i]]+n;
		dfs2(g[x][i]);
	} 	
}

main(){
	int x,mx=0,cnt=0,a,i;
	scanf("%lld",&n);
	for(i=1;i<=n;++i) scanf("%lld",&d[i]),f[i]=d[i],mmp[d[i]]=i;
	for(i=1;i<=n;++i) sz[i]=1;
	sort(d+1,d+n+1);
	for(i=n;i>1;--i){
		a=mmp[d[i]];
		x=d[i]-(n-sz[a])+sz[a];
		if(x>=d[i]) return printf("-1")&0;
		if(!mmp[x]) return printf("-1")&0;
		fa[a]=mmp[x];
		sz[mmp[x]]+=sz[a];
	}
	for(i=1;i<=n;++i) if(fa[i]) g[fa[i]].push_back(i);
	//judge
	int y=mmp[d[1]];
	dfs1(y,y,0);
	dfs2(y);
	for(i=1;i<=n;++i) if(pd[i]!=f[i]) return printf("-1")&0;
	for(i=1;i<=n;++i) if(fa[i]) printf("%lld %lld\n",fa[i],i);
}

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

int main(void) {
	string S;
	cin >> S;
	long long K;
	scanf("%lld", &K);
	for (int i = 0; i < K; i++) {
		if (S[i] != '1') {
			cout << S[i] << "\n";
			return 0;
		}
	}
	cout << "1\n";

	return 0;
}


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

using namespace std;

//  樹形図のノード
struct node {   
	int val;	//  特定桁の値
	int depth;	//  ノードの深さ
	int sum;	//  ノードが示す10進数の値

	node(int _val, int _depth, int _sum = 0)
	 : val(_val), depth(_depth), sum(_sum) {} 
};

bool is_753_num(int num, int limit) {
	if (num > limit) {
		return false;
	}

	int q = num;
	int mod = 0;
	int num_of_3 = 0;
	int num_of_5 = 0;
	int num_of_7 = 0;

	while (q != 0) {
		mod = q % 10;
		switch (mod) {
		case 3:
			num_of_3++;
			break;
		case 5:
			num_of_5++;
			break;
		case 7:
			num_of_7++;
			break;
		}
		q /= 10;
	}

	if (num_of_3 >= 1 && num_of_5 >= 1 && num_of_7 >= 1) {
		return true;
	}	
	return false;
}

int num_of_digits(int target) {
	if (target == 0) {
		return 1;
	}

	int result = 0;
	while (target != 0) {
		target = target / 10;
		result++;
	}
	return result;
}

int traverse_tree_by_dfs(int start, int limit) {
	int result = 0;
	int digits = num_of_digits(limit);

	stack<node> st;
	st.push(node(start, 0));

	while(!st.empty()) {
		node cur = st.top();
		st.pop();

		cur.sum += (static_cast<int>(pow(10, cur.depth)) * cur.val);

		if (is_753_num(cur.sum, limit)) {
			result++;
		}

		if (cur.depth + 1 < digits) {
			st.push(node(3, cur.depth + 1, cur.sum));
			st.push(node(5, cur.depth + 1, cur.sum));
			st.push(node(7, cur.depth + 1, cur.sum));
		}
	}

	return result;
}

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	int ans = traverse_tree_by_dfs(3, N)
			+ traverse_tree_by_dfs(5, N)
			+ traverse_tree_by_dfs(7, N);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
x, y, a, b, c = map(int, input().split())
rs = [int(i) for i in input().split()]
gs = [int(i) for i in input().split()]
ws = [int(i) for i in input().split()]

rs.sort(reverse=True)
gs.sort(reverse=True)
ws.sort(reverse=True)
weight = 0
rs = rs[:x]
rs = [0] + rs
gs = gs[:y]
gs = [0] + gs
ws = [0] + ws
r = 0
g = 0
w = 0
while r + g + w < x + y:
  if r < x:
    w1 = weight + rs[r + 1]
  else:
    w1 = 0
  if g < y:
    w2 = weight + gs[g + 1]
  else:
    w2 = 0
  if w < c:
    w3 = weight + ws[w + 1]
  else:
    w3 = 0
  weight = max(w1, w2, w3)
  if weight == w1:
    r += 1
  elif weight == w2:
    g += 1
  elif weight == w3:
    w += 1
print(weight)

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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>

const ll mod=1e9+7;

void solve()
{
    int n;
    sfi(n)

    ll arr[n];
    f(i,0,n)
    	sfl(arr[i])

    ll var=0;

    f(i,0,n)
    	var=var^arr[i];

    f(i,0,n)
    {
    	ll temp=var^arr[i];

    	pfls(temp)
    }

    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    solve();
    
    return 0;
}

Measured memory_bytes: 5296
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

typedef long long ll;
const int maxn=100010;
int n,x,y,z;
struct node
{
	int a,b;
	bool operator <(const node &t)const
	{
		return a-b>t.a-t.b;
	}
}s[maxn];
ll suma[maxn],sumb[maxn],ans,mx;
priority_queue<int,vector<int>,greater<int> >q;

int read()
{
	int x=0;
	char c=getchar();
	while (c<48||c>57)
		c=getchar();
	while (c>=48&&c<=57)
		x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}

int main()
{
	int i,c;
	x=read(),y=read(),z=read();
	n=x+y+z;
	for (i=1;i<=n;i++)
	{
		s[i].a=read(),s[i].b=read(),c=read();
		s[i].a-=c,s[i].b-=c;
		ans+=c;
	}
	sort(s+1,s+n+1);
	for (i=1;i<=max(x,n-y);i++)
	{
		suma[i]=suma[i-1]+s[i].a;
		q.push(s[i].a);
		if ((int)(q.size())>x)
		{
			suma[i]-=q.top();
			q.pop();
		}
	}
	while (!q.empty())
		q.pop();
	for (i=n;i>=min(x+1,n-y+1);i--)
	{
		sumb[i]=sumb[i+1]+s[i].b;
		q.push(s[i].b);
		if ((int)(q.size())>y)
		{
			sumb[i]-=q.top();
			q.pop();
		}
	}
	mx=-1e15;
	for (i=x;i<=n-y;i++)
		mx=max(mx,suma[i]+sumb[i+1]);
	printf("%lld\n",ans+mx);
	return 0;
}

Measured memory_bytes: 2560
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		Point2D.Double p[];
		String str[];
		
		p = new Point2D.Double[4];
		while (sc.hasNext()) {
			str = sc.nextLine().split(" ");
			for (int i = 0; i < 4; i++) {
				p[i] = new Point2D.Double(Double.valueOf(str[2 * i]), Double.valueOf(str[2 * i + 1]));
			}
			
			if (p[0].x <= p[3].x && p[2].x <= p[1].x) {
				if (p[0].y <= p[3].y && p[2].y <= p[1].y) {
					System.out.println("YES");
				} else if (p[2].y <= p[1].y && p[0].y <= p[3].y) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} else if (p[2].x <= p[1].x && p[0].x <= p[3].x) {
				if (p[0].y <= p[3].y && p[2].y <= p[1].y) {
					System.out.println("YES");
				} else if (p[2].y <= p[1].y && p[0].y <= p[3].y) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 11000