akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

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


using ll = long long;

#define int ll


const int N = 2e6 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int r1, r2, c1, c2, f[N], rf[N], ans;
void add(int &a, int b) {
    a += b;
    if (a < 0) a += mod;
    a %= mod;
}
int mult(int a, int b) {
    a *= b;
    a %= mod;
    return a;
}
int power(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mult(res, a);
        }
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}
int inv(int x) {
    return power(x, mod - 2);
}
int c(int n, int k) {
    return mult(f[n], mult(rf[k], rf[n - k]));
}
int cnt(int a, int b) {
    int ret = 0;
    fo(i, 1, a, 1) ret += c(b + i + 1, i + 1), ret %= mod;
    return ret;
}
int subtr(int a, int b) {
    a -= b;
    if (a < 0) a += mod;
    a %= mod;
    return a;
}
main() {
    file("threesum");
    ios;
    cin >> r1 >> c1 >> r2 >> c2;
    f[0] = 1;
    fo(i, 1, 2e6 + 3, 1) f[i] = (f[i - 1] * i) % mod;
    rf[(int)2e6 + 3] = inv(f[(int)2e6 + 3]);
    foo(i, 2e6 + 2, 0, 1) {
        rf[i] = mult(rf[i + 1], i + 1);
    }
    fo(i, r1, r2, 1) add(ans, subtr(c(i + c2 + 1, i + 1), c(i + c1, i + 1)));
    cout << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**
min n = r1 + c1
max n = r2 + c2
min k = r1
max k = r2
sum of:
c(r1 + c1, r1) + c(r1 + 1 + c1, r1) + .. c(r1 + c2, r1) +
c(r1 + 1 + c1, r1 + 1)

c(r,r) + c(r + 1,r) + .. + c(n,r) == c(n+1,r+1)
*/


Measured memory_bytes: 31488
#include<iostream>
using namespace std;
int p;
int main(){
	while(true){
		cin>>p;if(p==0)break;
		p=1000-p;
		int a1=p/500;p-=500*a1;
		int a2=p/100;p-=100*a2;
		int a3=p/50;p-=50*a3;
		int a4=p/10;p-=10*a4;
		int a5=p/5;p-=5*a5;
		int a6=p/1;p-=1*a6;
		cout<<a1+a2+a3+a4+a5+a6<<endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include <cstdio>
const int N = 1000;

void trace(int A[], int n) {
	int i;
	for (i = 0; i < n; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionsort(int A[], int n) {
	int j, i, key;
	trace(A, n);
	for (i = 1; i<n; i++) {
		key = A[i];
		j = i - 1;
		while (j >= 0 && A[j]>key) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;
		trace(A, n);
	}
}

int main() {
	int n, i;
	int A[N + 1];
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	insertionsort(A, n);
	return 0;
}

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

using namespace std;
long long int dp[110][258][110][2],MOD=10E8+7;
int H,W,K;
long long int solve(int h,int w,int k,int f){
  if(dp[h][w][k][f] != -1){
   	return dp[h][w][k][f]; 
  }
  for(int i=0;i<W;i++){
   if(((w >> (i))&1) && ((w >> (i+1))&1)){
     return dp[h][w][k][f] = 0;
   }
  }
  if(h == H+1){
    if(k == K)
   		return dp[h][w][k][f] = 1;
    else
      	return dp[h][w][k][f] = 0;
  }


  int res = 0;
  	if((f && ((w >> (k-1))) & 1)){
    	res += solve(h,w,k+1,0);
  	}else if(f && k >= 2 && ((w >> (k-2)) & 1)){
    	res += solve(h,w,k-1,0);
  	}else{
  	if(h == H){
   		res += solve(h+1,w,k,1);
  	}else{
  		for(int i=0;i<(1 << (W-1));i++){
   			res = (res+solve(h+1,i,k,1))%MOD; 
  		}
  	}
	}
  return dp[h][w][k][f] = res;
}

int main(){
  cin >> H >> W >> K;
  for(int i=0;i<110;i++)
    for(int j=0;j<110;j++)
      for(int k=0;k<110;k++)
        for(int l=0;l<2;l++)
          dp[i][j][k][l] = -1;
  long long int res=0;
  for(int i=0;i<1<<(W-1);i++){
    res = (res+solve(1,i,1,1))%MOD;
  }
  cout << res << endl;
}

Measured memory_bytes: 46976
loop {
  h, w = gets.split(" ").map(&:to_i)
  if h == 0 && w == 0
    break
  end
  for i in 1..h
    for n in 1..w
      if (i+n)%2 == 1
        print "."
      else
        print "#"
      end
    end
    puts "\n"
  end
  puts "\n"
}

Measured memory_bytes: 8656
#include <utility>
#include <cstdio>
#include <set>
int fa[100005];
std::set<int> adj[100005];
std::set<std::pair<int, int> > more;
int getfa(int u)
{
	if (u == fa[u])
		return u;
	return fa[u] = getfa(fa[u]);
}
inline void add_edge(int u, int v)
{
	if (adj[u].count(v))
	{
		adj[u].erase(v);
		if (u > v)
			std::swap(u, v);
		more.insert({u, v});
	}
	else
		adj[u].insert(v);
}
int main()
{
	// freopen("AGC014-E.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		fa[i] = i;
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add_edge(--u, --v);
		add_edge(v, u);
	}
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add_edge(--u, --v);
		add_edge(v, u);
	}
	int rem = n - 1;
	while (!more.empty())
	{
		auto e = *more.begin();
		more.erase(e);
		auto u = getfa(e.first), v = getfa(e.second);
		if (adj[u].size() > adj[v].size())
			std::swap(u, v);
		fa[u] = v;
		for (auto x : adj[u])
		{
			adj[x].erase(u);
			add_edge(v, x);
			add_edge(x, v);
		}
		adj[u].clear();
		rem--;
	}
	puts(!rem ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 24064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
char s[maxn];
ll cnt,cc,ans,n;
int main(){
    scanf("%s",s);
    for(int i=0;s[i];n++,i++)
        if(s[i]=='B')
            cnt++;
    for(int i=0;s[i];i++){
        if(s[i]=='B'){
            ans += max(0ll,n-cnt-i);
            cnt--;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int a=read(),b=read(),c=read();
	if(c%__gcd(a,b))
		printf("NO");
	else
		printf("YES");
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void solve(ll a, ll b, ll c) { cout << min(min(a + b, b + c), c + a) << endl; }

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll a;
  scanf("%lld", &a);
  ll b;
  scanf("%lld", &b);
  ll c;
  scanf("%lld", &c);
  solve(a, b, c);
  return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  if (n % 2 == 0)
    Cout(-1);
  else {
    string co = "";
    while (1) {
      co += "7";
      ans = stoll(co);
      cnt++;
      if (ans % n == 0) {
        Cout(cnt);
        return 0;
      }
      ans %= n;
      co = to_string(ans);
      if (cnt >= 1000000 * 2) break;
    }
    if (cnt == 1000000 * 2) Cout(-1);
  }
  return 0;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
long long Array[200005];

long long FindAns( int N , long long length ){
    long long Ans = 1000000000000000000L , Left = 0LL , Right;
    
    for( int i = 1 ; i <= N ; ++i ){
        Left = Left + Array[i];
        Right = length - Left;
        Ans = min( Ans , abs( Left - Right ) );
    }

    return Ans;
}

int main(){
    int N , i;
    long long length = 0LL;
    scanf( "%d" , &N );

    for( i = 1 ; i <= N ; ++i ){
       scanf( "%lld" , Array + i );
        length = length + Array[i];
    }

    printf( "%lld\n" , FindAns( N , length ) );
    return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long ans;
long n;
long p[20];

int main(){
  scanf("%ld", &n);
  for(int i = 0; i < n; i++){
    scanf("%ld", p+i);
  }
  for(int i = 1; i < n-1; i++){
    if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
      ans++;
    }
  }
  printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }



void solve() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    
    vector<int> dp(n + 1);
    string ss;
    
    rep(i, n) {
        int add = 0;
        
        char now = '.';
        if (t[i] == 'r') now = 'p';
        else if (t[i] == 's') now = 'r';
        else now = 's';
        
        if (i < k || ss[i - k] != now) {
            if (t[i] == 'r') { add += p; ss += 'p'; }
            else if (t[i] == 's') { add += r; ss += 'r'; }
            else { add += s; ss += 's'; }
        } else {
            ss += '#';
        }
        chmax(dp[i + 1], dp[i] + add);
    }
    
    cout << dp[n] << endl;
    // cout << ss << endl;
    // rep(i, n + 1) cout << dp[i] << " "; cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    while (T--) {
        solve();
        // cout << (solve() ? "YES" : "NO") << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    int n;
    scanf("%d", &n);
    vector<int> ve(n+1);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &ve[i]);
    vector<int> dp(n+1, 0);
    dp[2] = abs(ve[2]-ve[1]);
    for (int i = 3; i <=n; ++i){
        dp[i] = min(dp[i-2]+abs(ve[i-2]-ve[i]), dp[i-1]+abs(ve[i-1]-ve[i]));
    }
    cout << dp[n];
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
    int ara[6],i;
    for(i=1;i<=5;i++)
    {
        cin>>ara[i];
    }
    for(i=1;i<=5;i++)
    {
        if(ara[i]==0)
        {
            printf("%d\n",i);return 0;
        }
    }
}



Measured memory_bytes: 3692
#include <bitset>
#include <algorithm>

using namespace std;

int main()
{
	const int MAX_VALUES = 101;
	bitset<MAX_VALUES> bits;
	bitset<MAX_VALUES> reversed;
	bits.set();
	reversed.set();
	int x, n, t;
	scanf("%d %d", &x, &n);
	if (n == 0) {
		printf("%d", x);
		exit(0);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &t);
		bits.reset(t);
		reversed.reset(MAX_VALUES - 1 - t);
	}
	if (bits[x]) {
		printf("%d", x);
		exit(0);
	}
	int rV = bits._Find_next(x);
	int lV = MAX_VALUES - 1 - reversed._Find_next(MAX_VALUES - 1 - x);
	int d1 = abs(rV - x);
	int d2 = abs(lV - x);
	if (d1 < d2) {
		printf("%d", rV);
	} else if (d2 < d1) {
		printf("%d", lV);
	} else {
		printf("%d", min(rV, lV));
	}
	return 0;
}

Measured memory_bytes: 3244
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main(){
	int a[3];
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	sort(a,a + 3);
	if(a[0] == 5 && a[1] == 5 && a[2] == 7) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
  bitset<64>b(0);
  //cout<<b<<endl;
  //cout<<(~b)<<endl;
  //cout<<(b<<1)<<endl;
  //cout<<(b>>1)<<endl;
  //cout<<(a&b)<<endl;
  //cout<<(a|b)<<endl;
  //cout<<(a^b)<<endl;
  int q,x,y;
  cin>>q;
  while(q--){
    cin>>x;
    if(x<4)cin>>y;
    if(x==0) cout<<b.test(y)<<endl;
    if(x==1) b.set(y);
    if(x==2) b.reset(y);
    if(x==3) b.flip(y);
    if(x==4) cout<<b.all()<<endl;
    if(x==5) cout<<b.any()<<endl;
    if(x==6) cout<<b.none()<<endl;
    if(x==7) cout<<b.count()<<endl;
    if(x==8) cout<<b.to_ullong()<<endl;
  }
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000000000000
using namespace std;
int freq[100005];
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d", &a);
	SET(freq, 0);
	for (i = 1; i <= a; i++) {
		scanf("%d", &b);
		freq[b]++;
	}
	c = 0;
	for (i = 1; i <= 100000; i++) {
		c = max(c, freq[i - 1] + freq[i] + freq[i + 1]);
	}
	printf("%d\n", c);
	return 0; 
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int[] a=cin.ArrayInt(N,0);
        Array.Sort(a);
        int min=a[0];
        int max=a[N-1];
        int Min=9999999;
        for(int i=min;i<=max;i++)
        {
            int sum=0;
            for(int j=0;j<N;j++)
            {
                sum+=((a[j]-i)*(a[j]-i));
            }
            Min=Math.Min(Min,sum);
        }
        Console.WriteLine(Min);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

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

int main(){
	list<int>L[114514];
	list<int>::iterator it;
	int n,q;
	cin>>n>>q;
	while(q--){
		int a,b,c;
		cin>>a;
		if(a==0){
			cin>>b>>c;
			L[b].push_back(c);
		}
		if(a==1){
			cin>>b;
			for(it=L[b].begin();it!=L[b].end();it++){
				if(it!=L[b].begin())cout<<' ';
				cout<<*it;
			}
			cout<<endl;
		}
		if(a==2){
			cin>>b>>c;
			L[c].splice(L[c].end(),L[b]);
		}
	}
}


Measured memory_bytes: 20516
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  int p = 700;
  if(s.at(0) == 'o') p += 100;
  if(s.at(1) == 'o') p += 100;
  if(s.at(2) == 'o') p += 100;
  cout << p << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	LL n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
	return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

string s1,s2,s3;
int main() {
    cin >> s1 >> s2 >> s3;
    printf("%c%c%c\n",s1[0],s2[1],s3[2]);
    return 0;
}

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

int main(){
	int m, d, d1, d10, ans = 0;
	cin >> m >> d;
	for (int i = 1; i <= m; i++){
		for (int j = 1; j <= d; j++){
			d1 = j % 10;
			d10 = j / 10;
			if (d1 > 1 && d10 > 1 && i == d1 * d10) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
x = int(input())

for i in range(1000):
    for j in range(1000):
        a = i**5
        b = j**5
        if a-b == x:
            print(i,j)
            exit()
        elif a+b == x:
            print(i,-j)
            exit()
        elif -a-b == x:
            print(-i,-j)
            exit()

Measured memory_bytes: 64308
N = int(input())
ans = list()
flag = [0] * 55556
flag[1] = 1
for i in range(1, 55556):
  if(flag[i] == 0):
    if(i%5 == 1):
      ans.append(i)
    p = i
    while(p <= 55555):
      flag[p] = 1
      p += i
print(*ans[:N])

Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()


int main(){
    int r,d,x;
    cin>>r>>d>>x;

    rep(i,0,10){
        x=r*x-d;
        cout<<x<<endl;
    }
}

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

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

const int MAXN = 1000;

int s[MAXN];

int main()
{
    s[0] = 0;
    REP(MAXN - 1) s[i+1] = s[i] + i + 1;

    int n;
    while(cin >> n && n)
    {
        int ans = 0;
        REP(n)for(int j= i+1;j<n;j++)if(s[j] - s[i] == n) ans++;

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  long long a = min(X / D, K);
  X -= a * D;
  K -= a;
  cout << ((K & 1) ? D - X : X) << endl;
  return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int n,i;
int a[2000001],dp[2000001];
main(){
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(i=2;i<=n;i++){
        dp[i+1]=min(dp[i]+abs(a[i+1]-a[i]),dp[i-1]+abs(a[i+1]-a[i-1]));
    }
    cout<<dp[n]<<endl;
}

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

int main()
{
	int A, B;
	double H, M;
	cin >> A >> B >> H >> M;

	H += M / 60;
	double th = 3 - H;
	if( H > 3 ) th = -(H - 3);
	if( H >= 9 ) th = 12 - H + 3;
	th *= M_PI * 2 / 12;
	double tm = 15 - M;
	if( M > 15 ) tm = -(M - 15);
	if( M >= 45 ) tm = 60 - M + 15;
	tm *= M_PI * 2 / 60;
	double ax = A * cos( th );
	double ay = A * sin( th );
	double bx = B * cos( tm );
	double by = B * sin( tm );
	double x = ax - bx;
	double y = ay - by;
	double ans = sqrt( x * x + y * y );

	cout << fixed << setprecision(12) << ans << endl;
}


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

const int N = 2e5 + 10;
typedef long long LL;

int n;
pair<int,int> p[N];
multiset<int> X, Y;

LL cal(){
    LL ret = (*X.rbegin() - *X.begin());
    ret = ret * (*Y.rbegin() - *Y.begin());
    return ret;
}

int main(){
    int a, b;
    while(~scanf("%d", &n)){
        X.clear();
        Y.clear();
        for(int i=0; i<n; i++){
            scanf("%d %d", &a, &b);
            if(a > b)   swap(a, b);
            p[i] = make_pair(a, b);
            X.insert(a);
            Y.insert(b);
        }
        sort(p, p+n);

        LL ans = cal();

        for(int i=0; i<n; i++){
            auto it = X.find(p[i].first);
            X.erase(it);
            it = Y.find(p[i].second);
            Y.erase(it);

            X.insert(p[i].second);
            Y.insert(p[i].first);

            ans = min(ans, cal());
        }
        printf("%lld\n", ans);
    }
    return 0;
}


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


int main(){

    string s;
    cin >> s;

    for(int i = 0; i < 3; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
li=list(map(int,input().split()))
a=0
for i in range(0,n):
  a=a+li[i]
total=0
k=0
while 2*total<=a:
  total=total+li[k]
  k=k+1
if 2*total==a:
  print(0)
else:
  if 2*total-a<=a-2*(total-li[k-1]):
    print(2*total-a)
  elif 2*total-a>a-2*(total-li[k-1]):
    print(a-2*(total-li[k-1]))

Measured memory_bytes: 26220
#include<bits/stdc++.h>
#define INF (1e9)
#define N 1005
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> P2;

int h, w, n, d[N][N][4];
string o, s[N];
int sy, sx;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
int B[N], A[N][4];

priority_queue<P2,vector<P2>,greater<P2> > q;

bool dijkstra(){
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      for(int k=0;k<4;k++) d[i][j][k]=INF;
  
  q.push(P2(P(0,0),P(sy,sx)));
  
  d[sy][sx][0]=0;

  bool res=false;
  
  while(!q.empty()){

    P2 t=q.top(); q.pop();

    int cost=t.first.first;
    int dir=t.first.second;
    int y=t.second.first;
    int x=t.second.second;

    if(d[y][x][dir]<cost) continue;
    
    if(s[y][x]=='G') res=true;

    for(int i=0;i<4;i++){

      if(cost==o.size()||A[cost][i]==INF) continue;

      if(d[y][x][i]>A[cost][i]+1){
	
	d[y][x][i]=A[cost][i]+1;

	q.push(P2(P(A[cost][i]+1,i),P(y,x)));
      }
      
    }
    
    int ny=y+dy[dir], nx=x+dx[dir];
    
    if(ny<0||nx<0||h<=ny||w<=nx) continue;
    if(s[ny][nx]=='#') continue;

    if(d[ny][nx][dir]>cost){

      d[ny][nx][dir]=cost;
      
      q.push(P2(P(cost,dir),P(ny,nx)));
    }
    
  }
  
  return res;
}

int main(){
  
  while(1) {
    
    cin>>h>>w>>n;
    if(!h&&!w&&!n) break;
  
    cin>>o;

    for(int i=0;i<h;i++){
    
      cin>>s[i];

      for(int j=0;j<w;j++)
	if(s[i][j]=='S') sy=i, sx=j;
    
    }

    int dir=0;
    
    for(int i=0;i<n;i++){
      
      if(o[i]=='L') dir=(dir+3)%4;
      else dir=(dir+1)%4;
      
      B[i]=dir;
     
    }
    
    int dir2[4];
    
    for(int i=0;i<4;i++) dir2[i]=INF;
    
    for(int i=n-1;i>=0;i--){
      
      dir2[B[i]] = min(dir2[B[i]],i);

      for(int j=0;j<4;j++) A[i][j] = dir2[j];
      
    }
    
    if(dijkstra()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

  }
  
  return 0;
}

Measured memory_bytes: 21692
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
string s;
int i,m,h;
int main(void){
  while(cin>>s){
    if(s=="-")break;
    cin>>m;
    for(i=0;i<m;i++){
      cin>>h;
      s=s.substr(h)+s.substr(0,h);
    }
    cout<<s<<endl;
  }
  return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
	int n, m;
	while (cin >> n >> m, n|m) {
		vector<pii> pds;
		rep(i, n) {
			int d, p;
			cin >> d >> p;
			pds.push_back(pii(p, d));
		}
		sort(ALL(pds));
		reverse(ALL(pds));
		rep(i, pds.size()) {
			if (m >= pds[i].second) {
				m -= pds[i].second;
				pds[i].second = 0;
			} else {
				pds[i].second -= m;
				m = 0;
				break;
			}
		}

		int ans = 0;
		rep(i, pds.size())
			ans += pds[i].first * pds[i].second;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1328
#include<iostream>
#include<algorithm>
#include<cstdio>

int main(){
	const int MAX_N = 100;
	const int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
	int d, n;

	std::cin >> d;
	for(int k=0;k<d;k++){
		std::cin >> n;

		if(k > 0){
			std::cout << std::endl;
		}

		if(n == 2){
			std::cout << "##\n# \n";
		}else{
			int x = 0, y = n-1, p = n-3, angle = 0;

			int cloth[MAX_N][MAX_N];
			for(int i=0;i<n;i++){
				std::fill(cloth[i], cloth[i]+n, 0);
			}
			
			for(int i=0;i<3;i++){
				cloth[y][x] = 1;
				for(int j=0;j<n-1;j++){
					x += dx[angle];
					y += dy[angle];
					cloth[y][x] = 1;
				}
				angle = (angle + 1) % 4;
			}
			
			while(p > 1){
				for(int i=0;i<2;i++){
					cloth[y][x] = 1;
					for(int j=0;j<p;j++){
						x += dx[angle];
						y += dy[angle];
						cloth[y][x] = 1;
					}
					angle = (angle + 1) % 4;						
				}
				p -= 2;
			}
			
			if(n % 2 == 0){//偶数
				x += dx[angle];
				y += dy[angle];
				cloth[y][x] = 1;
			}
			
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(cloth[i][j]){
						printf("#");
					}else{
						printf(" ");
					}
				}
				std::cout << std::endl;
			}
		}
	}
}

Measured memory_bytes: 1200
n = int(input())
H = [int(i) for i in input().split()]
dp = [0] * n

dp[1] = abs(H[0] - H[1])
for i in range(2, n):
    dp[i] = min(abs(H[i] - H[i - 1]) + dp[i - 1], abs(H[i] - H[i - 2]) + dp[i - 2])
    
print(dp[-1])

Measured memory_bytes: 13928
$wall = $<.each_line.map(&:chomp)
def wall?(i, j, di, dj)
	i = i * 2 + di
	j += dj / 2
	return false if i < 0 or 8 < i or j < 0
	return $wall[i][j] == '1'
end

label = {
	[0, 1] => 'R',
	[1, 0] => 'D',
	[0, -1] => 'L',
	[-1, 0] => 'U',
}

i, j = v = [0, 1]
print 'R'

until i.zero? and j.zero?
	case
	when wall?(i, j, -v[1], v[0])
		v = [-v[1], v[0]]
	when wall?(i, j, *v)
	when wall?(i, j, v[1], -v[0])
		v = [v[1], -v[0]]
	else
		v = [-v[0], -v[1]]
	end
	i += v[0]
	j += v[1]
	print label[v]
end

puts

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

def euclid(a, b):
    if a>b:
        tmp = a
        a = b
        b = tmp
    while a>0:
        c = b%a
        b = a
        a = c
    return b

def sub_gcd(X):
    Y = []
    P, Q = len(X)//2, len(X)%2
    for p in range(P):
        y = euclid(X[2*p], X[2*p+1])
        Y.append(y)
    if Q!=0:
        Y.append(X[-1])
    return Y

def gcd(X):
    Y = sub_gcd(X)
    while len(Y)>1:
        Y = sub_gcd(Y)
    return Y[0]

print(gcd(A))

Measured memory_bytes: 62704
#include<stdio.h>
#include<string.h>
int main(){
    char moji[1001] = {}, str[8] = {}, tmpstr[1001] = {}, x[1001] = {};
    int a, b, n, tmp, r, i, tmp2;
    scanf("%s", moji);
    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        scanf("%s %d %d", str, &a, &b);
        if( strcmp( str, "print" ) == 0 ){
            for( tmp = a; tmp <= b; tmp++ ){
                printf("%c", moji[tmp]);
                }
            printf("\n");
            }else if( strcmp( str, "reverse" ) == 0 ){
              strcpy( tmpstr, moji );
                for( tmp = a; tmp <= b; tmp++ ){
                    moji[ tmp ] = tmpstr[ b - ( tmp - a ) ];
                }


/*              for( tmp = a, tmp2 = b; tmp < tmp2; tmp++, tmp2-- ){
                  tmpstr = moji[ tmp ];
                  moji[ tmp ] = moji[tmp2];
                  moji[ tmp2 ] = tmpstr;
              }  */
        }else{
            scanf("%s", x);
            for( tmp = a; tmp <= b; tmp++ ){
                moji[tmp] = x[ tmp - a ];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
map<int, ll>dp[N];
int n;
ll a[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%lld", &a[i]);
	dp[1][1] = a[1]; dp[1][0] = 0;
	dp[2][0] = 0; dp[2][1] = max(a[1], a[2]);
	for (int i = 3; i <= n; i++) {
		int L = n / 2 - (int)ceil(0.5*(n - i + 1)), R = (int)ceil(0.5*i);
		for (int j = L; j <= R; j++) {
			if (!dp[i - 1].count(j) && !dp[i - 2].count(j - 1))continue;
			else if (dp[i - 1].count(j) && !dp[i - 2].count(j - 1))dp[i][j] = dp[i - 1][j];
			else if (dp[i - 2].count(j - 1) && !dp[i - 1].count(j))dp[i][j] = dp[i - 2][j - 1] + a[i];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 2][j - 1] + a[i]);
		}
	}
	printf("%lld\n", dp[n][n / 2]);
	return 0;
}

Measured memory_bytes: 46032
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let X = readInt()

(X / 500)*1000 + ((X%500)/5)*5
|> printfn "%d"

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

long long mod = 1e9 + 7;


int main()
{
	int n;
	cin >> n;
	long long a[n], b[n], c[n];
	long long ansA[n], ansB[n], ansC[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	ansA[0] = a[0];
	ansB[0] = b[0];
	ansC[0] = c[0];
	for (int i = 1; i < n; i++) {
		ansA[i] = a[i] + max(ansB[i-1], ansC[i-1]);
		ansB[i] = b[i] + max(ansA[i-1], ansC[i-1]);
		ansC[i] = c[i] + max(ansA[i-1], ansB[i-1]);
	}
	cout << max(ansA[n-1], max(ansB[n-1], ansC[n-1]));
}






Measured memory_bytes: 4992
/*input
2
1 1
*/

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int t; cin >> t; while(t--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() {
	godspeed;
	int n;
	cin >> n;
	int64 a[n];
	rep(i, n) cin >> a[i];
	sort(a, a+n);
	int64 sum = a[n-1];
	int k = n-2;
	for (int i = n-2; i >= 0; i--) {
		if (k == 0) break;
		sum += a[i];
		k--;
		if (k == 0) break;
		sum += a[i];
		k--;
		if (k == 0) break;
	}
	cout << sum << endl;
}


/*
3 5 1 4 2 6 --
1st + 2nd + 2nd + 3rd + 3rd
*/

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n,m;
  cin >> n >> m;
  vector<int64_t> a(m);
  vector<int64_t> b(m);
  vector<int64_t> c(m);
  rep(i,m){
    cin >> a.at(i) >> b.at(i);
    rep(j,b.at(i)){
      int64_t hoge;
      cin >> hoge;
      c.at(i) += 1 << (hoge-1);
    }
    //cout <<c.at(i) << endl;
  }
  int64_t honu  = 1;
  rep(i,n){
    honu *= 2;
  }
  vector<vector<int64_t>> DP(m+1,vector<int64_t>(honu));
  rep(i,honu){
    rep(j,m+1){
      if(j==0 && i == 0){
        DP.at(j).at(i) = 0;
      }else{
        DP.at(j).at(i) = 1234567890;
      }
    }
  }
  int64_t INVALID = 1234567890;
  rep(i,m){
    rep(j,honu){
      if(DP.at(i).at(j) != INVALID){
        DP.at(i+1).at(j | c.at(i))
           = min(DP.at(i+1).at(j | c.at(i)),DP.at(i).at(j)+a.at(i));
      }
      DP.at(i+1).at(j)
        = min(DP.at(i).at(j),DP.at(i+1).at(j));
    }
  }
  if(DP.at(m).at(honu-1) != INVALID){
    cout << DP.at(m).at(honu-1) << endl;
  }else{
    cout << -1 << endl;
  }
         
      
      
  

      
    
    
    
    
}

Measured memory_bytes: 32384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NQ = Console.ReadLine().Split(' ');
            int N = int.Parse(NQ[0]);
            int Q = int.Parse(NQ[1]);
            int[] pa = new int[1+N];
            int[] xs = new int[1+N];
            for (var i = 2; i <= N; i++)
            {
                string[] ab = Console.ReadLine().Split(' ');
                int a = int.Parse(ab[0]);
                int b = int.Parse(ab[1]);
                pa[b] = a;
            }
            for (var i = 1; i <= Q; i++)
            {
                string[] px = Console.ReadLine().Split(' ');
                int p = int.Parse(px[0]);
                int x = int.Parse(px[1]);
                xs[p] += x;
            }
            for (var i = 2; i <= N; i++)
            {
                xs[i] += xs[pa[i]];
            }
            string ans = string.Join(" ", xs);
            Console.WriteLine(ans.Substring(2));
        }
    }
}


Measured memory_bytes: 36080
n,m = map(int,input().split())
ken = [[] for i in range(n)]
jun = [0] * m
p = [0] * m
for i in range(m):
    p[i],y = map(int,input().split())
    ken[p[i]-1].append((y,i))
    
for i in range(n):
    if ken[i] == []:
        continue
    else:
        ken[i].sort()
        for j in range(len(ken[i])):
            jun[ken[i][j][1]] = j+1
            
for i in range(m):
    jun[i] += p[i] * 1000000
    ss = str(jun[i])
    s = "0"*(12-len(ss)) + ss
    print(s)

Measured memory_bytes: 64288
s=input()
n1=int(s[:2])
n2=int(s[2:])

if (n1==0 or n1>=13) and (n2>=1 and n2<=12):
    print("YYMM")
elif (n1>=1 and n1<=12) and (n2==0 or n2>=13):
    print("MMYY")
elif (n1>=1 and n1<=12) and (n2>=1 and n2<=12):
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 3060
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=N-K+1
long=10**9
for i in range(a):
  l=A[i+K-1]-A[i]+min(abs(A[i+K-1]),abs(A[i]))
  long=min(long,l)
print(long)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

using namespace std;

int main()
{
    IOS;
    int n,m,k,x;
    cin>>n>>m;
    vector<int> v[m];
    for(int i=0;i<m;i++)
    {
        cin>>k;
        for(int j=0;j<k;j++)
        {
            cin>>x;
            v[i].pb(x);
        }
    }
    int p[n];
    for(int i=0;i<m;i++) cin>>p[i];
    int ans=0;
    for(int i=0;i<(1<<n);i++)
    {
        int j=i;
        int cnt=0;
        vector<int> u(n,0);
        int k=0;
        while(j)
        {
            u[k++]=j%2;
            j>>=1;
        }
        // for(k=0;k<n;k++) cout<<u[k]<<" ";
        // cout<<endl;
        for(int j=0;j<m;j++)
        {
            int sum=0;       
            for(auto k:v[j]) if(u[k-1]) sum++;
            //cout<<sum<<endl;
            if(sum%2==p[j]) cnt++;
        }
        if(cnt==m) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
if 1 not in a:
  print(-1)
else:
  i = 1
  j = 0
  s = 0
  while j != N:
    if a[j] == i:
      sum = j-i+1
      i += 1
      s = j
    j += 1
  if s != N-1:
    sum += N-s-1
  print(sum)

Measured memory_bytes: 26140
#include<stdio.h>
int main(void)
{
	char str[100];
	int i;
	
	scanf("%s",str);
	
	i=0;
	while(str[i]!='\0')
	{
		i++;
	}
	i--;
	while(i>=0)
	{
		putchar(str[i]);
		i--;
	}
	putchar('\n');
	return 0;
}

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

int main() {
    int N, M, c; cin >> N >> M;
    vector<int> ans(N);
    rep(i, M * 2) {
        cin >> c;
        ans.at(c - 1)++;
    }
    rep(i, N) {
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 256
import math

a,b,h,m = map(int, input().split())

xh = a*math.cos((60*h+m)/360*math.pi)
yh = a*math.sin((60*h+m)/360*math.pi)

xm = b*math.cos(m/30*math.pi)
ym = b*math.sin(m/30*math.pi)

print( ((xh-xm)**2+(yh-ym)**2)**0.5 )

Measured memory_bytes: 9412
n = int(input())

a = list(map(int, input().split()))
count = 0
for i in range(n):
    if (a[i]%2) or (a[i]%3==0) or (a[i]%5==0):
        count += 1

if count == n:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    v A(N),B(N);
    rep(i,0,N)cin>>A[i]>>B[i];
    sort(all(A));
    sort(all(B));
    if(A.size()%2 == 0){
        cout<<B[N/2]+B[N/2-1]-A[N/2]-A[N/2-1]+1;
    }
    else{
        cout<<B[N/2]-A[N/2]+1;
    }
    return 0;
}

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

int main(){
   int n;
   cin >> n;
   vector<int> A(n);
   for(int i = 0; i < n; i++){
       cin >> A[i];
   }
   for (int i = 0; i < n - 1; i++){
       cout << A[n - 1 - i] << " ";
   }
   cout << A[0] << endl;
   return 0;
}


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

int main()
{
  char op;
  int a, b;

  while (cin >> a >> op >> b, op != '?'){
    if (op == '+') cout << a + b;
    if (op == '-') cout << a - b;
    if (op == '*') cout << a * b;
    if (op == '/') cout << a / b;
    cout << endl;
  }
}

Measured memory_bytes: 1160