akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	cout << max(a+b, max(a-b, a*b)) << endl;
 	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=1;
  while(ans<=N){
    ans*=2;
  }
  if(ans>N){
    cout<<ans/2<<endl;
  }
  else{
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
const int N=1e6;
ll a[N+3];
int p[N+3],b[N+3];
int main()
{
    ft
    ll i,j,n,l,r,g=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        g=__gcd(g,a[i]);
    }
    vector<ll>v;
    for(i=3;i*i<N;i+=2)
    {
        for(j=i*i;j<N;j+=2*i)
        {
            p[j]=1;
        }
    }
    v.pb(2);
    for(i=3;i<N;i+=2)
    {
        if(p[i]==0)
        {
            v.pb(i);
        }
    }
    r=0;
    for(i=0;i<n;i++)
    {
        l=a[i];
        for(ll x:v)
        {
            if(x*x>l)
            {
                break;
            }
            if((l%x)==0)
            {
                b[x]++;
                while((l%x)==0)
                {
                    l/=x;
                }
            }
        }
        if(l>1)
        {
            b[l]++;
        }
    }
    for(ll y:v)
    {
        if(b[y]>1)
        {
            r=1;
            break;
        }
    }
    if(r==0)
    {
        cout<<"pairwise coprime\n";
    }
    else if(g==1)
    {
        cout<<"setwise coprime\n";
    }
    else
    {
        cout<<"not coprime\n";
    }
    return 0;
}



Measured memory_bytes: 19624
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#include "string"

int32_t main() {
	boost;
	int n,m;
	cin>>n>>m;
	vector<int>g[n+1];
	for(int i=1,u,v,w;i<=m;i++){
		cin>>u>>v>>w;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int visit[n+1]={0};
	function <void (int) > dfs = [&](int u){
		visit[u] = 1;
		for(int v:g[u]){
			if(visit[v])
				continue;
			dfs(v);
		}
	};

	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(visit[i])
			continue;
		cnt++;
		dfs(i);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 16052
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string S;
  cin>>S;
  if(S.size()!=26){
    set<char> A;
    for(char c:S)
      A.insert(c);
    for(char c='a';c<='z';c++)
      if(!A.count(c)){
        cout<<S<<c<<endl;
        return 0;
      }
  }else{
    int i=24;
    for(;i>=0;i--)
      if(S[i]<S[i+1])
        break;
    if(i==-1){
      puts("-1");
      return 0;
    }
    set<char> A;
    for(int j=0;j<i;j++){
      cout<<S[j];
      A.insert(S[j]);
    }
    for(char c=S[i]+1;c<='z';c++)
      if(!A.count(c)){
        cout<<c<<endl;
        return 0;
      }
  }
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;


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

  int N,K; cin>>N>>K;
  int res = (N + 1) / 2;
  string ans = res >= K ? "YES" : "NO";
  cout << ans << endl;
}


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


int main()
{
    long double a, su;
    int i, k, n;

    while (true) {
        cin >> n;

        if (n == 0) { break; }

        vector<long double> s(n);

        for (k = 0; k < n; ++k) {
            cin >> s.at(k);
        }

        su = 0;

        for (k = 0; k < n; ++k) {
            su += s.at(k);
        }

        su /= n;

        a = 0;

        for (k = 0; k < n; ++k) {
            a += (s.at(k) - su) * (s.at(k) - su) / n;
        }

        a = sqrt(a);

        cout << fixed << setprecision(15) << a << endl;
    }
}


Measured memory_bytes: 3312
n = int(input())
pl = list(map(int, input().split()))
ans = 0
for p1,p2,p3 in zip(pl[:-2],pl[1:-1],pl[2:]):
    if p1 < p2 and p2 < p3 or p1 > p2 and p2 > p3:
        ans += 1

print(ans)

Measured memory_bytes: 61000
from sys import stdin

def main():
    n, k = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    
    def ok(ans):
        cnt = sum(max((i - 1) // ans, 0) for i in a)
        # print(ans, cnt) 
        return cnt <= k
    
    ans = 0
    for i in range(32, -1, -1):
        if not ok(ans + (1 << i)):
            ans += 1 << i
    print(ans + 1)

main()


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

counter = 0
while True:
  hasOdd = 0
  for i in range(N):
    if A[i] % 2 == 1:
      hasOdd += 1

  if hasOdd > 0:
    break

  A = [i / 2 for i in A]
  counter += 1
print(str(counter))

Measured memory_bytes: 9124
def f(i):
    return i

n=int(input())
s,t=[],[]
for i in range(n):
    s_i,t_i=map(f,input().split())
    s.append(s_i)
    t.append(int(t_i))
x=input()

sgn=0
ans=0
for i in range(n):
    if sgn==1: ans+=t[i]
    elif s[i]==x: sgn=1
print(ans)

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DKi {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    vector<vector<int>> G;
    vector<int> res, P;

    void dfs(int v, int p, int cur) {
        res[v] = cur + P[v];

        REP(i,G[v].size()) {
            int to = G[v][i];
            if (to == p) continue;
            dfs(to, v, cur + P[v]);
        }
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, Q;
        cin >> N >> Q;
        G.resize(N), res.resize(N);
        REP(i, N - 1) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        P.resize(N);
        REP(i, Q) {
            int p, x;
            cin >> p >> x;
            p--;
            P[p] += x;
        }

        dfs(0, -1, 0);

        REP(i, N) {
            cout << res[i] << " ";
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DKi solver;
    solver.solve(in, out);
    return 0;
}


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

int main() {
    int N, K; cin >> N >> K;
    vector<int> P(N);
    rep(i, N){
        cin >> P[i];
    }
    sort(P.begin(), P.end());
    int ans = 0;
    rep(i, K){
        ans += P[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll e,f,g,h,i,j,k,l;
    k=min(c,d);
    l=max(c,d);
    i=l%k;
    while(i!=0){
        l=k;
        k=i;
        i=l%k;
    }
    g=c*d/k;
    if(a%c==0||b%c==0){
    e=(b-a)/c+1;
    }else if(a%c>b%c){
        e=(b-a)/c+1;
    }else{
        e=(b-a)/c;
    }
    if(a%d==0||b%d==0){
    f=(b-a)/d+1;
    }else if(a%d>b%d){
        f=(b-a)/d+1;
    }else{
        f=(b-a)/d;
    }
    if(a%g==0||b%g==0){
    h=(b-a)/g+1;
    }else if(a%g>b%g){
        h=(b-a)/g+1;
    }else{
        h=(b-a)/g;
    }
    cout<<b-a+1-e-f+h;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N, K, output = 1;
  scanf("%d %d", &N, &K);

  for(int i = 0; i < N; i++) {
    if(output+K > output*2) {
      output *= 2;
    } else {
      output += K;
    }
  }

  printf("%d\n", output);

  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 17;
int n;
int a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	cin >> n;
	FOR(i, 1, n + 1)
		cin >> a[i];
	
	LL ans = 0;
	FOR(i, 1, n + 2)
		ans += abs(a[i] - a[i - 1]);
	
	FOR(i, 1, n + 1)
	{
		LL tut = ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
		cout << tut << endl;
	}
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,len;
    vector<int>v;
    cin>>n;
    while(n)
    {
        v.push_back(n%10);
        n/=10;
    }
    reverse(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        if(v[i]==1) cout<<9;
        else cout<<1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    if((x>=-40)&&(x<=40))
    {
    if(x>=30)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    }
    return 0;
}

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

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } 
        }
    


Measured memory_bytes: 35856
#include <bits/stdc++.h>
using namespace std;
// long long m=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    long long t,m,n,i=5,j,k,temp,sum=0,flag=0,count=0,mi,x,y;
    cin >> n >> m;
    if(n==m) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int N = 100;
const int INF = 2000000000;

int g[N + 1][N + 1];
int d[N + 1], p[N + 1], color[N + 1];
int n;

void prim()
{
	for (int i = 1; i <= n; i++)
	{
		color[i] = WHITE;
		d[i] = INF;
		p[i] = -1;
	}
	d[1] = 0;

	while (true)
	{
		int min = INF;
		int u = -1;
		for (int i = 1; i <= n; i++)
		{
			if (color[i] != BLACK && d[i] < min)
			{
				min = d[i];
				u = i;
			}
		}
		if (u == -1)
			break;

		color[u] = BLACK;

		for (int i = 1; i <= n; i++)
		{
			if (color[i] != BLACK && g[u][i] != INF && d[i] > g[u][i])
			{
				d[i] = g[u][i];
				color[i] = GRAY;
				p[i] = u;
			}
		}
	}
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (p[i] != -1)
			sum += g[p[i]][i];
	}
	printf("%d\n", sum);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", &g[i][j]);
			if (g[i][j] == -1)
				g[i][j] = INF;
		}
	prim();

	return 0;
}



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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n,m; cin >> n >> m;
    vector<vector<int>> graph(n);
    rep(i,0,m){
        int a,b; cin >> a >> b; a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    queue<int> q;
    int memo[n];
    int used[n] = {};
    used[0] = true;
    q.push(0);
    while(!q.empty()){
        int now = q.front(); q.pop();
        rep(i,0,graph[now].size()){
            int next = graph[now][i];
            if(used[next]) continue;
            memo[next] = now;
            used[next] = true;
            q.push(next);
        }
    }
    cout << "Yes" << endl;
    rep(i,1,n){
        cout << memo[i] +1<< endl;
    }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25296
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)

 int main() {
    string S; cin >> S;
    ll N = S.size();
    ll ans = 0;

    FOR(bit, 0, (1<<(N - 1))) {
        ll sum = 0;
        ll y = 0;
        FOR(i, 0, N - 1) {
            y = y * 10 + atoi(S.substr(i, 1).c_str());
            if (bit & (1<<i)) {
                sum += y;
                y = 0;
            }
            
        }
        y = y * 10 + atoi(S.substr(N - 1).c_str());
        sum += y;

        ans += sum;
    }
    
    printf("%lld\n", ans);
 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    ll n;
    cin >> n;
    cout << (int)sqrt(n) * (int)sqrt(n) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
const int maxn = 1e5+10;
int main(){
    int a,b,w;
    scanf("%d%d%d",&w,&a,&b);
    int mae = a-w,ato = a+w;
    if(b>=mae&&b<=ato){
        printf("0\n");
        return 0;
    }
    int res = min(abs(mae-b),abs(ato-b));
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int n ;
  cin >> n ;
  int ans = 0 ;
  int tmp ;
  vector<pair<int,int>> pa(n) ;
  REP(i,n){
    int a ;
    cin >> a ;
    pa.at(i) = make_pair(i+1,a) ;
  }
  
  FOR(i,1,n+1){
    tmp = pa.at(i-1).SE ;
    if(pa.at(tmp-1).SE == i){
      ans++ ;
    }
  }
    
    
    
  
  cout << ans/2 <<endl ;


  return 0 ;
}



Measured memory_bytes: 1024
n, y = map(int,input().split(' '))

finded = False
for sen in range(n+1):
    for gosen in range(n+1-sen):
        if 1000*sen + 5000*gosen + 10000*(n-sen-gosen) == y:
            print(n-sen-gosen,gosen,sen,sep=' ')
            finded = True
            break
    if finded:
        break

if not finded:
    print('-1 -1 -1')



Measured memory_bytes: 3060
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

void solve()
{
    int k; 
    cin >> k;
    string s; cin >> s;
    string ans;
    


    //cout << "fuck you bitch" << "\n";
    // if (s.size() <= k)
    // {
    //     cout << s << "\n";
    // }
    int z = s.size();
    //cout << z << "\n";
    if (z > k)
    {
        //cout << "fuck you bitch" << "\n";
        loop(i,0,k)
        {
            ans += s[i];
        }
        ans += "...";
        cout << ans << "\n";
    }
    else
    {
        cout << s << "\n";
    }
    
}

int main()
{
    solve();
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    string S;
    cin >> S;
    for (char c : S) {
        if (c == '7') {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x( (x%mod + mod) % mod ) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ( (x += a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ( ( x += mod - a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        ( x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  mint ans = 0;
  vector<mint> q(s+1);
  rep(i,n) {
    q[0] += 1;
    {
      vector<mint> q2(s+1);
      rep(j,s+1) {
        q2[j] += q[j];
        if (j + a[i] <= s) q2[a[i] + j] += q[j];
      }
      q = q2;
    }
    ans += q[s];
  }
  cout << ans << endl;
  return 0;
}

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

int main() {
    string s, t; cin>>s>>t;
    int n = s.size();

    for(int i=0; i<n; i++){
        string x = s;
        rotate(x.begin(), x.begin()+i, x.end());

        if(x == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

int N;
cin >> N;

vector<string>s(N);
REP(i, N) cin >> s.at(i);

int M;
cin >> M;

vector<string>t(M);
REP(i, M) cin >> t.at(i);

int sum = 0;

REP(i, N){
    int tmp = 0;
    REP(j, N) if(s.at(i) == s.at(j)) tmp++;
        REP(k, M) if(s.at(i) == t.at(k)) tmp--;
    sum = max(sum, tmp);
}

print(sum);

}

Measured memory_bytes: 256
import Data.List
import Data.List.Split
import qualified Data.Vector as V
import Data.Maybe
import qualified Data.ByteString.Char8 as B
readInt = fst . fromJust . B.readInt
main = mapM_ (print . solve) . chunksOf 2 . map (map readInt. B.words) . B.lines =<< B.getContents
solve::[[Int]]->Int
solve [[n,k],as] = fst $ dfs 0 0 where
  vas = V.fromList . map (\a->if a==1 then 0 else 1) $ as
  g = V.accum (flip (:)) (V.replicate n []) . flip zip [1..] . map (subtract 1) . tail $ as
  dfs r v
    |v==0 || m==0 = (c+vas V.! v,k-1)
    |otherwise = (c,m-1)
    where 
      cs = map (dfs (r+1)) (g V.! v)
      c = foldl' (+) 0 . map fst $ cs
      m = foldl' (min) (k-1) . map snd $ cs

Measured memory_bytes: 51580
#include<iostream>
using namespace std;
int main(){
  int a,b,c,temp1=0,temp2=0;
  cin>>a>>b>>c;

  temp1=a;
  a=b;
  b=temp1;

  temp2=a;
  a=c;
  c=temp2;
  cout<<a<<" "<<b<<" "<<c;
  return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int a, b, c, x, y; std::cin >> a >> b >> c >> x >> y;
  int ans = 0;
  if (x < y) swap(a, b), swap(x, y);
  if (a + b > 2 * c) ans += 2 * c * y, x -= y, y = 0;
  if (a > 2 * c) ans += 2 * c * x, x = 0, y = max(0, y-x);
  if (b > 2 * c) ans += 2 * c * y, y = 0, x = max(0, x-y);
  ans += a * x, ans += b * y;
  std::cout << ans << "\n";
}


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

#define pii pair<int,int>
#define maxn 51
#define m_p make_pair

int main(){
	int n;
	cin>>n;
	vector<int> x(n);
	vector<int> y(n);
	for (int i=0;i<n;i++) cin>>x[i]>>y[i];
	if (n==1){
		cout<<n<<endl;
		return 0;
	}
	int res=n;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++){
			if (i==j) continue;
			int dx=x[j]-x[i];
			int dy=y[j]-y[i];
			int cnt=0;
			for (int k=0;k<n;k++)
				for (int l=0;l<n;l++)
					if (dx==x[l]-x[k] && dy==y[l]-y[k])
						cnt++;
			res=min(res,n-cnt);
		}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
def f(l,m,n,d):
	s=0;q=[]
	for i in range(l,m,d):s+=a[i];heappush(q,a[i]*d)
	r=[s]
	for i in range(m,n,d):s+=a[i];heappush(q,a[i]*d);s-=heappop(q)*d;r+=[s]
	return r
import sys;from heapq import*;n,*a=list(map(int,sys.stdin.read().split()));print(max(x-y for x,y in zip(f(0,n,2*n,1),reversed(f(3*n-1,2*n-1,n-1,-1)))))

Measured memory_bytes: 127576
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
//using namespace __gnu_pbds;
//template <typename T>
//using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll N = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

bool comp(P<int,string> a,P<int,string> b){
        return (a.F > b.F || (a.F == b.F && a.S < b.S));
}

int main(){
    unordered_map<string,int> m;
    int n;
    cin >> n;
    int mx = 0;
    while(n--){
        string a;
        cin >> a;
        m[a]++;
        mx = max(mx,m[a]);
    }
    V<string> a;
    for(auto i: m)if(i.S == mx)a.pb(i.F);
    sort(all(a));
    for(auto &i: a)cout << i << "\n";
return 0;
}


Measured memory_bytes: 26692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a  = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(c > (a -b)) {
			System.out.println(c - (a - b));
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	
	if(a.size() == b.size())
	{
		for(int i = 0; i < a.size(); i++)
		{
			if(a[i] > b[i])
			{
				cout << "GREATER" << endl;
				break;
			}
			else if(a[i] < b[i])
			{
				cout << "LESS" << endl;
				break;
			}
			
			if(i == a.size() - 1)
			{
				cout << "EQUAL" << endl;
			}
		}
			
	}
	else if(a.size() > b.size())
	{
		cout << "GREATER" << endl;
	}
	else
	{
		cout << "LESS" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

class Program {

    /// <summary>
    /// チェスボードのベースとなる文字列を用意しておく
    /// </summary>
    const string BaseString = "#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.";

    private static int Main() {
        while( true ) {
            var input = Console.ReadLine();
            var values = input.Split( ' ' );

            int H = int.Parse( values[ 0 ] );
            int W = int.Parse( values[ 1 ] );

            if( H == 0 && W == 0 ) { break; }

            for( int i = 0; i < H; ++i ) {
                Console.WriteLine( BaseString.Substring( i % 2, W ) );
            }
            Console.WriteLine();
        }

        return 0;
    }
}

Measured memory_bytes: 5416
#include<cstdio>
#include<iostream>
#include<map>
#include<string>

using namespace std;

typedef map<string,string> MSS;

#define MSSVT MSS::value_type

int main(){
	
	string gc;
	string inp;
	string sea;
	string hen;
	string ans;
	MSS data1,data2;

	data1.insert(MSSVT("101"," "));
	data1.insert(MSSVT("010001","."));
	data1.insert(MSSVT("000011",","));
	data1.insert(MSSVT("10010001","-"));
	data1.insert(MSSVT("000000","'"));
	data1.insert(MSSVT("000001","?"));
	data1.insert(MSSVT("100101","A"));
	data1.insert(MSSVT("10011010","B"));
	data1.insert(MSSVT("0101","C"));
	data1.insert(MSSVT("0001","D"));
	data1.insert(MSSVT("110","E"));
	data1.insert(MSSVT("01001","F"));
	data1.insert(MSSVT("10011011","G"));
	data1.insert(MSSVT("010000","H"));
	data1.insert(MSSVT("0111","I"));
	data1.insert(MSSVT("10011000","J"));
	data1.insert(MSSVT("0110","K"));
	data1.insert(MSSVT("00100","L"));
	data1.insert(MSSVT("10011001","M"));
	data1.insert(MSSVT("10011110","N"));
	data1.insert(MSSVT("00101","O"));
	data1.insert(MSSVT("111","P"));
	data1.insert(MSSVT("10011111","Q"));
	data1.insert(MSSVT("1000","R"));
	data1.insert(MSSVT("00110","S"));
	data1.insert(MSSVT("00111","T"));
	data1.insert(MSSVT("10011100","U"));
	data1.insert(MSSVT("10011101","V"));
	data1.insert(MSSVT("000010","W"));
	data1.insert(MSSVT("10010010","X"));
	data1.insert(MSSVT("10010011","Y"));
	data1.insert(MSSVT("10010000","Z"));
	data2.insert(MSSVT(" ","11010"));
	data2.insert(MSSVT(".","11011"));
	data2.insert(MSSVT(",","11100"));
	data2.insert(MSSVT("-","11101"));
	data2.insert(MSSVT("'","11110"));
	data2.insert(MSSVT("?","11111"));
	data2.insert(MSSVT("A","00000"));
	data2.insert(MSSVT("B","00001"));
	data2.insert(MSSVT("C","00010"));
	data2.insert(MSSVT("D","00011"));
	data2.insert(MSSVT("E","00100"));
	data2.insert(MSSVT("F","00101"));
	data2.insert(MSSVT("G","00110"));
	data2.insert(MSSVT("H","00111"));
	data2.insert(MSSVT("I","01000"));
	data2.insert(MSSVT("J","01001"));
	data2.insert(MSSVT("K","01010"));
	data2.insert(MSSVT("L","01011"));
	data2.insert(MSSVT("M","01100"));
	data2.insert(MSSVT("N","01101"));
	data2.insert(MSSVT("O","01110"));
	data2.insert(MSSVT("P","01111"));
	data2.insert(MSSVT("Q","10000"));
	data2.insert(MSSVT("R","10001"));
	data2.insert(MSSVT("S","10010"));
	data2.insert(MSSVT("T","10011"));
	data2.insert(MSSVT("U","10100"));
	data2.insert(MSSVT("V","10101"));
	data2.insert(MSSVT("W","10110"));
	data2.insert(MSSVT("X","10111"));
	data2.insert(MSSVT("Y","11000"));
	data2.insert(MSSVT("Z","11001"));

	
	while(getline(cin,inp)){
		hen=("");
		for(int i=0;i<inp.size();i++){
			sea=inp[i];
			//cout<<inp[i]<<"||"<<endl;
			hen+=data2[sea];
		}
		ans=("");
		sea=("");
		for(int i=0;i<hen.size();i++){
			sea+=hen[i];
			if(data1.find(sea)!=data1.end()){
				ans+=data1[sea];
				//cout<<data1[sea]<<","<<sea<<endl;
				sea=("");
			}
		}
		if(cin.eof()) break;
		cout<<ans<<endl;
	}

}

Measured memory_bytes: 1220
#include <stdio.h>
int main()
{
	long int N;
	int tanda=0;
	scanf ("%d",&N);
	long int A [N];
	long long int risolt=1;
	long long int limit=1000000000000000000;
	for (int i=0;i<N;i++)
	{
		scanf ("%lld",&A[i]);
		if (A[i]==0)
		{
			puts ("0");
			return 0;
		}
	}
		for (int i=0;i<N;i++)
	{
		if (A[i]>limit)
		{
			puts ("-1");
			return 0;
		}
		limit=limit/A[i];
		risolt=risolt*A[i];
	}
	printf ("%lld\n",risolt);
	return 0;
	
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    ll n,m;
    cin >> n >> m;
    if(n==1&&m==1){
        cout << 1 << endl;
        return 0;
    }
    if(n==1||m==1){
        if(n==1)swap(n,m);
        cout << n-2 << endl;
        return 0;
    }
    // 以下n,m>=2;
    cout << (n-2)*(m-2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>

using namespace std;
int main(){
  size_t N;
  cin >> N;

  size_t ans = N;
  size_t s = sqrt(N);

  for(size_t i = 1; i <= s; ++i){
    size_t j = N / i;
    size_t a = (i * j);
    if(N == a){
      ans = N > ( i + j - 2 ) ? i + j - 2  : N;
    }
  }
cout << ans << endl;
}

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 1000041
using namespace std;

ll mp[mxn];
int main()
{
    FLASH
    ll n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i],mp[a[i]]++;
    ll cnt = n;
    if(mp[1] == 1)
    {
        cout << "1";
        return 0;
    }
    else if(mp[1] >= 2)
    {
        cout << "0";
        return 0;
    }
    for(int i = 0; i < n; i++)
    {
        ll x = a[i];
        if(mp[a[i]] >= 2)
        {
            cnt--;
            continue;
        }
        for(int j = 2; j * j <= x; j++)
        {
            if(x % j == 0)
            {
                if(mp[j] >= 1 || mp[x / j] >= 1)
                {
                    cnt--;
                    break;
                }
            }
        }
    }
    cout << cnt << '\n' ;
    return 0;
}


Measured memory_bytes: 12976
n,w=[int(k) for k in input().split()]
li=[]
 
 
ans=0
for i in range(n):
    li.append([int(k) for k in input().split()])
dp=[[0 for i in range(100001)] for j in range(n+1)]
for i in range(1,100001):
    dp[0][i]=10**10
dp[0][0]=0    
for a in range(1,n+1):
    for b in range(1,100001):
        if(li[a-1][1]<=b):
            x=li[a-1][0]+dp[a-1][b-li[a-1][1]]
            y=dp[a-1][b]
            dp[a][b]=min(x,y)
        else:
            dp[a][b]=dp[a-1][b]
        if dp[a][b]<=w:
          ans=max(ans,b)
 
 
print(ans)    
 


Measured memory_bytes: 171912
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=1005;
int n,m;
int ans[N*200],t[N][N],tt[N],b[N*200],a[N*200];
int D,del,clk,vis[N];
void dfs(int u)
{
	int i;
	if(vis[u]) return;
	if(u==del) return;
	vis[u]=clk;
	for(i=1;i<=tt[u];i++) dfs(b[t[u][i]]);
}
void work(int u)
{
	int i,v;
	del=u;
	memset(vis,0,sizeof(vis));
	for(i=1;i<=tt[u];i++)
	{
		clk=v=b[t[u][i]];
		dfs(v);
	}
	for(i=1;i<=tt[u];i++) 
	{
		v=b[t[u][i]];
		if (v!=vis[v]) ans[t[u][i]]=1;
	}
}
int main()
{
	int u,v,i;
	n=ri(),m=ri();
	for(i=1;i<=m;i++)
	{
		u=ri(),v=ri();
		a[i]=u,b[i]=v;
		t[u][++tt[u]]=i;
	}
	for(u=1;u<=n;u++)
	{
		work(u);
		for(i=1;i<=tt[u]/2;i++) swap(t[u][i],t[u][ tt[u]-i+1 ]);
		work(u);
	}
	for(u=1;u<=n;u++)
	{
		memset(vis,0,sizeof(vis));
		clk=1;
		del=0;
		dfs(u);
		for(i=1;i<=m;i++) if(b[i]==u) ans[i]^=vis[a[i]];
	}
	for(i=1;i<=m;i++) if(ans[i]) puts("diff");else puts("same");
	return 0;
}


Measured memory_bytes: 7552
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            x = (a*500) + (b*100) + (c*50)
            if x == X:
                count += 1
print(count)

Measured memory_bytes: 3064
using namespace std;
#include<string>
#include<cmath>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9 + 1;
#include<iterator>






void solve() {
	ll n, c = 0, q;
	cin >> n;
	ll a[n];
	fr(i, 0, n) cin >> a[i];
	sort(a, a + n);
	c += a[n - 1];
	q = n - 2;
	fr(i, 0, n - 2) {c += (a[q] * 2); i++; q--;}
	if (n % 2 != 0) {
		q++;
		c -= a[q];
	}

	cout << c;
}



int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif

	ll t;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int tmp = 1;
    for(int i=0; i<n; i++){
        tmp = min(2*tmp, tmp+k);
    }

    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 384
a,b,c,x,y=gets.split.map(&:to_i)

key=[a+b,c*2].min

dif=(x-y).abs
ans=0

if x>=y 
    ans+=y*key
    
    ans+=dif*[a,2*c].min
    
else
    ans+=x*key
    
    ans+=dif*[b,2*c].min
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

struct UnionFind {
	vector<int> par, rank;
	
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		REP(i, n) {
		 par[i] = i;
		 rank[i] = 0;
		}
	}
	
	int operator[] (int x) {
		return find(x);
	}
	
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		
		if (rank[x] < rank[y]) swap(x, y);
		
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	
};


using pll = pair<ll, ll>;
using ll3 = tuple<ll, ll, ll>;
int N, D;
vector<int> A;

void dfs(int l, int r, vector<ll3> &edge) {
	if (r - l <= 1) return;
	int m = (l + r) / 2;
	
	pll mn(longINF, -1);
	FOR(i, m, r) chmin(mn, pll(A[i] + (ll)i * D, i));
	FOR(i, l, m) edge.emplace_back(A[i] - (ll)i * D + mn.fi, i, mn.se);
	
	mn = pll(longINF, -1);
	FOR(i, l, m) chmin(mn, pll(A[i] - (ll)i * D, i));
	FOR(i, m, r) edge.emplace_back(A[i] + (ll)i * D + mn.fi, i, mn.se);
	
	dfs(l, m, edge);
	dfs(m, r, edge);
}

int main() {
	cin >> N >> D;
	A.resize(N);
	REP(i, N) scanf("%d", &A[i]);
	
	vector<ll3> edge;
	dfs(0, N, edge);
	sort(ALL(edge));
	
	UnionFind uf(N);
	ll ans = 0;
	for (ll3 &cur : edge) {
		ll cost, x, y;
		tie(cost, x, y) = cur;
		if (uf.same(x, y)) continue;
		uf.unite(x, y);
		ans += cost;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 101344
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = c - (a - b);
		if(ans >= 0)
			System.out.println(ans);
		else
			System.out.println(0);
		
	}

	}

Measured memory_bytes: 22608
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=100005;
vector<int>e[MAXN];
int dp[MAXN];
void dfs(int u)
{
    vector<int>tmp;
    for(int i=0;i<(int)e[u].size();i++)
    {
        int v=e[u][i];
        dfs(v);
        tmp.push_back(dp[v]+1);
    }
    sort(tmp.begin(),tmp.end(),greater<int>());
    for(int i=0;i<(int)tmp.size();i++)
        dp[u]=max(dp[u],tmp[i]+i);
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int a;
        scanf("%d",&a);
        e[a].push_back(i);
    }
    dfs(1);
    int res=0;
    for(int i=1;i<=n;i++)
        res=max(res,dp[i]);
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 17024
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    return *(int*)b-*(int*)a;
}

int main(){
    int n;
    scanf("%d",&n);
    int arr[100];
    for (int i=0; i<n; i++) scanf("%d",&arr[i]);
    qsort(arr,n,4,compare);
    int t = 1,ans = 0;
    for (int i=0; i<n; i++) {
        ans += t*arr[i];
        t *= -1;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 2148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N, K = map(int, input().split())

ans = 0
if K % 2 == 0:
    num = 0
    for i in range(1, N+1):
        if i % K == K // 2:
            num += 1
    ans += num ** 3

num = 0
for i in range(1, N+1):
    if i % K == 0:
        num += 1
ans += num ** 3

print(ans)




Measured memory_bytes: 7752
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int dp[110][10010]={}; //[v][w]

int main() {
    string s;
    int n,k;
    cin>>n>>k;
    cin>>s;

    s[k-1]-='A'-'a';
    cout<<s<<endl;
    return 0;
}



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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (n * a > b) {
		cout << b << endl;
	}
	else {
		cout << n * a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int t[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;

      
    
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",t[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}



Measured memory_bytes: 2056
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


def lcs(s1, s2):##
	dp = []
	for s2_k in s2:
		bgn_idx = 0
		for i, cur_idx in enumerate(dp):
			chr_idx = s1.find(s2_k, bgn_idx) + 1
			if not chr_idx:
				break
			dp[i] = min(cur_idx, chr_idx)
			bgn_idx = cur_idx
		else:
			chr_idx = s1.find(s2_k, bgn_idx) + 1
			if chr_idx:
				dp.append(chr_idx)
	return len(dp)

q = INT()

for _ in range(q):
	S = input()
	T = input()
	print(lcs(S, T))




Measured memory_bytes: 7112