akhauriyash/Code-Regression huggingface dataset:
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int N=305;
int P;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
int f[N][N],ch[N][N],sf[N][N],n,m;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&m,&P);
	fp(i,0,n){
		ch[i][0]=1;
		fp(j,1,i)ch[i][j]=inc(ch[i-1][j],ch[i-1][j-1]);
	}
	fp(i,0,m)f[1][i]=1,sf[1][i]=m-i+1;
	fp(i,2,n+1)fp(j,0,m-1){
		fp(k,1,i-1)upd(f[i][j],1ll*sf[k][j+1]*f[i-k][j]%P*ch[i-2][k-1]%P);
		fd(l,m,0)sf[i][l]=inc(sf[i][l+1],f[i][l]);
	}
	printf("%d\n",f[n+1][0]);
	return 0;
}

Measured memory_bytes: 1280
#基準曜日の取得
S = input()
 
# 入力された内容をもとに次の日曜日までの日数を表示
if S == "SAT":
  print(1)
elif S == "FRI":
  print(2)
elif S == "THU":
  print(3)
elif S == "WED":
  print(4)
elif S == "TUE":
  print(5)
elif S == "MON":
  print(6)
elif S == "SUN":
  print(7)
else:
  print("入力内容が間違っています。")

Measured memory_bytes: 9108
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    string S; cin >> S;
    
    int ans = 700;
    for (char c : S) {
        if (c == 'o') ans += 100;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N,W = map(int,input().split())
l = [list(map(int,input().split())) for i in range(N)]
w,v = [list(i) for i in zip(*l)]
INF = 10**9+7
dp = [[INF] * (100001) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(100001):
        if j-v[i] >= 0:
            dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i])
        else:
            dp[i+1][j] = dp[i][j]
ans = 100000
while dp[N][ans] > W:
    ans -= 1
print(ans)

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    string s1 = s.substr(0,(n - 1) / 2), s2 = s.substr((n + 2) / 2, n);
    string s3 = s1, s4 = s2; 
    reverse(s3.begin(), s3.end());
    reverse(s4.begin(), s4.end());
    if(s1 == s3 && s2 == s4 && s1 == s2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define LL long long
using namespace std;

LL N,a[100010],A,B;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> A >> B;

    int i; LL res=0;
    for (i=1; i<=N; i++){
        cin >> a[i];
        if (i!=1)
            res+=min(B,A*(a[i]-a[i-1]));

    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
	
	public class Main {
	
		public static void main(String[] args) {
			execute16_4();
		}
		
		private static void execute16_4() {
			try 
			(Scanner sc = new Scanner(System.in)) {
				int s = sc.nextInt();
				System.out.println(s+s*s+s*s*s);
			}
		}
    }

Measured memory_bytes: 27032
sx,sy,tx,ty = map(int,input().split())
diff_x=tx-sx
diff_y=ty-sy
ans = ''
for i in range(diff_y):
    ans += 'U'
for i in range(diff_x):
    ans += 'R'
for i in range(diff_y):
    ans += 'D'
for i in range(diff_x):
    ans += 'L'
ans += 'L'
for i in range(diff_y+1):
    ans += 'U'
for i in range(diff_x+1):
    ans += 'R'
ans += 'DR'
for i in range(diff_y+1):
    ans += 'D'
for i in range(diff_x+1):
    ans += 'L'
ans += 'U'

print(ans)

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair

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

const int maxn = 105;

int ans[maxn][maxn];
vector<int> c;

int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int h, w, n;
    cin >> h >> w;
    cin >> n;
    for (int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        for (int j=0;j<x;j++)
        {
            c.push_back(i+1);
        }
    }

    int counter = 0;
    for (int i=1;i<=h;i++)
    {
        if (i&1)
        {
            for (int j=1;j<=w;j++)
            {
                ans[i][j] = c[counter];
                counter++;
            }
        }
        else
        {
            for (int j=w;j>=1;j--)
            {
                ans[i][j] = c[counter];
                counter++;
            }
        }
    }

    for (int i=1;i<=h;i++)
    {
        for (int j=1;j<=w;j++)
        {
            if (j > 1) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 512
"use strict";

function main(input) {
  const args = input.trim().split("\n");
  const n = to_num(args[0].split(" ")[0]);
  const m = to_num(args[0].split(" ")[1]);
  let R = [];
  let L = [];
  args.map((line, index) => {
    if (index === 0) return;
    L.push(to_num(line.split(" ")[0]));
    R.push(to_num(line.split(" ")[1]));
  });

  let maxL = -1000;
  let minR = 1000000;
  for (let i = 0; i < m; i++) {
    maxL = Math.max(maxL, L[i]);
    minR = Math.min(minR, R[i]);
  }
  console.log(Math.max(0, minR - maxL + 1));
}

const to_num = (str) => {
  return parseInt(str, 10);
};
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 53584
#include <iostream>
#include <vector>
#include <set>

using namespace std;

#define M (int)1e6

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

int main() {
    int n;  cin >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int g = a[0];
    for (int i = 1; i < n; i++)
        g = gcd(g, a[i]);
    if (g != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    int *fac = new int[M+1];
    for (int i = 1; i <= M; i++)
        fac[i] = i;
    for (long long i = 2; i <= M; i++) {
        if (fac[i] != i)
            continue;
        for (long long j = i*i; j <= M; j += i) {
            fac[j] = i;
        }
    }

    vector<set<int> > vec(n);
    set<int> s;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        int x = a[i];
        while (x > 1) {
            vec[i].insert(fac[x]);
            x /= fac[x];
        }
        for (auto ite = vec[i].begin(); ite != vec[i].end(); ite++) {
            if (s.find(*ite) != s.end())
                flag = false;
            s.insert(*ite);
        }
    }
    if (flag)
        cout << "pairwise coprime" << endl;
    else 
        cout << "setwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 195176
c = []
for i in range(3):
    c.append(list(map(int,input().split())))
flg = False
for a1 in range(101):
    for b1 in range(101):
        if c[0][0] != a1 + b1:
            continue
        for a2 in range(101):
            if c[1][0] != a2 + b1:
                continue
            for b2 in range(101):
                if c[0][1] != a1 + b2:
                    continue
                if c[1][1] != a2 + b2:
                    continue
                for a3 in range(101):
                    if c[2][0] != a3 + b1:
                        continue
                    if c[2][1] != a3 + b2:
                        continue
                    for b3 in range(101):
                        if c[0][2] != a1 +b3:
                            continue
                        if c[1][2] != a2 + b3:
                            continue
                        if c[2][2] != a3 + b3:
                            continue
                        flg = True

if flg == True:
    print("Yes")
else:
    print("No")

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

using namespace std;

const int MAXN = 5010;

int mod;

inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }

int f[MAXN][MAXN];
int g[MAXN][MAXN];
int S[MAXN * 2];

int main() {
	int n; mod; cin >> n >> mod;
	int N = (n + 1) / 2;

	f[0][0] = 1;
	for(int i = 1; i <= N; i++)
		for(int j = 0; j <= n; j++)
			for(int k = j; k <= n; k += i)
				Add(f[i][k], f[i - 1][j]);

	g[0][0] = 1;
	for(int i = N - 1; i >= 1; i--) {
		for(int j = 0; j <= n; j++) {
			if(i * j >= n) break;
			for(int k = i * j; i + k <= n; k++)
				if(i + k <= n)
					Add(g[j + 1][k + i], g[j][k]);
		}
	}

	for(int i = 0; i <= n; i++)
		for(int j = 1; j <= n; j++)
			Add(g[i][j], g[i][j - 1]);
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= n; j++)
			Add(g[i][j], g[i - 1][j]);

	int n1 = N, n2 = N - 1;
	int res = 0;
	if(!(n & 1)) {
		for(int x = 1; x <= n; x++)
			for(int i = 0; i < x; i++)
				res = (res + 1LL * f[n1][i] * g[n - x][x - i - 1]) % mod;
	} else {
		for(int x = 1; x <= n; x++)
			for(int i = 0; i < x; i++)
				res = (res + 1LL * f[n1 - 1][i] * g[n - x][x - i - 1]) % mod;
	}
/*
	for(int i = 0; i <= n; i++) printf("%d\n", S[i]);

	for(int i = 1; i <= n; i++) Add(S[i], S[i - 1]);

	int res = 0;
	for(int i = 0; i < n; i++) Add(res, S[i]);
*/
	printf("%d\n", res);
	return 0;
}


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

main(){
  int i, mi, t, rem, maxrem;
  vector<int> a(5);
  maxrem = 0;
  mi = 0;
  for(i=0;i<5;i++){
    cin >> a[i];
    rem = (1000-a[i]) % 10;
    if(maxrem < rem){
      maxrem = rem;
      mi = i;
    }
  }
  t=0;
  for(i=0;i<5;i++){
    if(i==mi){
      t += a[i];
    } else {
      t += ceil( ((double)a[i]) / 10 ) * 10;
    }
  }
  cout << t << endl;
}

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

int main(){
    int D,N;
    cin>>D>>N;
    if(N!=100){
        if(D==0)cout<<N<<endl;
        else if(D==1)cout<<N*100<<endl;
        else cout<<N*10000<<endl;
    }else{
        if(D==0)cout<<101<<endl;
        else if(D==1)cout<<10100<<endl;
        else cout<<1010000<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
*/
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int const mod = 1e9+7;
int power(int x, int y, int mod = 2e18){ int ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
int gcd(int a , int b){if(a==0)return b;return gcd(b%a,a);}
int n;
int a[100001];
int b[100001];
int c[100001];
int dp[100001][4];
int solve(int i,int k=0)
{
	if(i==n)
		return 0;
	if(dp[i][k]!=-1)
		return dp[i][k];
	int ans = 0 ;
	if(k!=1)
	{
		ans = max(ans,a[i]+solve(i+1,1));
	}
	if(k!=2)
	{
		ans = max(ans,b[i]+solve(i+1,2));
	}
	if(k!=3)
	{
		ans = max(ans,c[i]+solve(i+1,3));
	}
	dp[i][k]=ans;
	return dp[i][k];

}
signed main() {
	IOS;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	cout<<solve(0);
	
return 0;
}

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

/*
以下(8~35行目)は二項係数を求める処理
https://drken1215.hatenablog.com/entry/2018/06/08/210000 より
*/
const int MAX = 2000003;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  // 前処理
    COMinit();
  
  int r_min;
  int c_min;
  int r_max;
  int c_max;
  cin >> r_min >> c_min >> r_max >> c_max;
  
  long long answer=2000000014;
  r_max++;
  c_max++;
  answer += COM(r_max+c_max,c_max);
  answer += COM(r_min+c_min,c_min);
  answer -= COM(r_max+c_min,c_min);
  answer -= COM(r_min+c_max,c_max);
  
  answer %= 1000000007;
  
  cout << answer << endl;
}

Measured memory_bytes: 47104
n=int(input())
p=list(map(int,input().split()))
p=p[::-1]
a=list(range(1,n*n+1,n+1))
b=list(range(n*n+1,0,-n-1))
for i in range(n):
  x=p[i]-1
  if x==0:
    b[x]-=i
  else:
    a[x]-=i
print(*a)
print(*b)

Measured memory_bytes: 6344
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rep1(i,n) for (int i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
int main(){
  ll a; cin >> a;
  cout << (a%1000==0 ? 0 : 1000-(a%1000));
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,x,t;
  cin >> n >> x >> t;
  ll sum=0,ans=0;
  while(sum<n) {
    sum+=x;
    ans+=t;
  } 
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
ll n, k,  a[105];
bool dp[100005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> k;
	for (ll i = 0; i< n; i++)cin >> a[i];
	//~ dp[i] is the winner if there are i stones remaining
	for (ll i= 0; i<= k; i++){
		for (ll j = 0; j < n; j++){
			if (i >= a[j] && !dp[i-a[j]])dp[i] = 1;
		}
	}
	if (dp[k])cout << "First";
	else cout << "Second";
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

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

	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k&1) cout << b-a << endl;
	else cout << a-b << endl;

	return 0;
}

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

using namespace std;

const int maxn=1e5+5;

int n,a[maxn],l[maxn];

int lis()
{
    l[0]=a[0];
    int length=1;
    for(int i=1;i<n;i++){
        if(l[length-1]<a[i]){
            l[length++]=a[i];
        }else{
            *lower_bound(l,l+length,a[i])=a[i];
        }
    }
    return length;
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<lis()<<endl;
    return 0;
}



Measured memory_bytes: 3764
import java.util.Scanner;

public class Main{
	static public void  main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] p = new int[5];
		for(int i = 0; i < 5; i++){
			p[i] = scan.nextInt();
		}
		int k = scan.nextInt();
		String ret = "Yay!";
		for(int i = 0; i < 4; i++){
			for(int j = i+1; j < 5; j++){
				if(p[j] - p[i] > k) ret=":(";
			}
}
		System.out.println(ret);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, K;
  cin >> N >>K ;
  long long A=0;
  for(int i=K;i<N+2;i++){
  	A=A+(N-i+1)*i+1;
  }
  cout<< A%(10*10*10*10*10*10*10*10*10+7) << endl;
 return 0; 
}

Measured memory_bytes: 3632
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1')ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(ll i=1;i<=(ll)sqrt(n);i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.rbegin(),ret.rend());
	return(ret);
}
int main(){
	ll n,k;
	cin>>n>>k;
	V<ll> a(n);
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	V<ll> tmp=divisor(sum);
	for(ll v:tmp){
		V<ll> d(n),sum(n+1,0);
		for(int i=0;i<n;i++){
			d[i]=a[i]%v;
		}
		sort(all(d),greater<ll>());
		for(int i=0;i<n;i++){
			sum[i+1]=sum[i]+d[i];
		}
		ll res=0;
		ll times=inf;
		for(int i=0;i<=n;i++){
			if(res%v==(sum[n]-sum[i])%v){
			chmin(times,max(res,(sum[n]-sum[i])));
			}
			res+=(v-d[i])%v;
		}
		if(times<=k){
			cout<<v<<"\n";
			return 0;
		}
	}
}

Measured memory_bytes: 3568
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
bool used[100001];
int mass[100001];
int n,m,x,y,ans;
int main()
{
	cin>>n>>m;
	fill(mass,mass+n,1);
	used[0]=1;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		x--; y--;
		if(used[x]&&!used[y]){
			used[y]=1;
		}
		mass[x]--;
		mass[y]++;
		if(!mass[x]) used[x]=0;
	}
	for(int i=0;i<n;i++) if(used[i]) ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<stdio.h>

long long t[44];

void fib(int a)
{
	t[0] = t[1] = 1;
	for(int i = 2; i <= a; i++)
		t[i] = t[i-1] + t[i-2];
}
int main()
{
	int a;
	scanf("%d", &a);
	fib(a);
	printf("%ld\n", t[a]);
}



Measured memory_bytes: 2104
#include <cstdio>

int main() {
    int n = 0;

    while (scanf("%d", &n) != EOF) {
        int t = 1;
        bool firstIn = true;

        for (int i = 0; i < 10; ++i) {
            if ((n & t) == t) {
                if (!firstIn) {
                    printf(" ");
                }
                printf("%d", t);
                firstIn = false;
            }

            t *= 2;
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<int> v(3); 
	for (int i=0; i<3; i++)
		cin>>v[i];
	cout<<(v[0]+v[1]+v[2]<22?"win":"bust")<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
def resolve():
    N = int(input())
    TA = [list(map(int, input().split())) for i in range(N)]
    t, a = TA[0]
    for i in range(1, len(TA)):
        t_next, a_next = TA[i]
        div = max((t//t_next)+(t%t_next!=0), (a//a_next)+(a%a_next!=0))
        t = t_next*div
        a = a_next*div
    print(t+a)


if '__main__' == __name__:
    resolve()



Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  
  if(a+b>a*b && a+b>a-b){
    cout<<a+b<<endl;
  }else if(a*b>a+b && a*b>a-b){
    cout<<a*b<<endl;
  }else{
    cout<<a-b<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,x;
    cin>>k>>x;
    int m = x-k+1;
    if(k==1)
    {
        cout<<x<<endl;
    }
    else
    {

        for(int i=1;i<=2*k-1;i++)
        {
            cout<<m<<" ";
             m++;

        }

    }
    return 0;




}


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

int main(){
    int n,m,s[200001],g[200001],i,ans=0,x,y;
    for(i=0;i<200001;i++){
        s[i] = 0;
        g[i] = 0;
    }
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d %d",&x,&y);
        if(x==1){
            s[y] ++;
        }
        if(y==n){
            g[x] ++;
        }
    }
    for(i=1;i<n;i++){
        if(s[i]&g[i]){
            ans = 1;
            break;
        }
    }
    if(ans == 1){
        printf("POSSIBLE\n");
    } else {
        printf("IMPOSSIBLE\n");
    }
}

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

  int main() {
    int N,K;
    cin >> N >> K;
    int count=0;
    vector<int> h(N);

    for(int i=0; i<N; i++)
      cin >> h.at(i);

    for(int i=0; i<N; i++){
      if(h.at(i)>=K)
        count++;
    }

    cout << count << endl;
  }

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve(){
    
}

int main()
{
    IO;
    double r;
    cin>>r;
    cout<<PI*2*r<<endl;
    return 0;

    int t;
    cin>>t;
    while(t){
        solve();
        t--;
    }
}   

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int k,x;
  cin >> k >> x;
  k--;

  for(int i=x-k; i<=x+k; i++) {
    cout << i << (i==x+k ? "\n" : " ");
  }
}

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

void solve()
{
    int n, k; cin >> n >> k;
    long long ans = k;
    n--;
    int mul = k-1;

    while(n--){
        ans *= mul;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3676
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	ret = pow(10, n, mod) - (pow(9,n, mod)*2)+pow(8, n, mod)
	ret %= mod
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62108
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

vector<long long int>by(401, 1);
vector<long long int>rev(401, 1);

void Search(vector<vector<int>>&edge, vector<vector<long long int>>&dp, int node) {
	vector<long long int>box(N + 1);
	box[0] = 1;
	for (auto i : edge[node]) {
		Search(edge, dp, i);
		vector<long long int>nbox(N + 1);
		for (int j = 0; j <= N; j++) {
			if (box[j] == 0)continue;
			for (int k = 0; k <= N; k++) {
				if (dp[i][k] == 0)continue;
				for (int l = 0; l <= min(j, k); l++) {
					long long int add = by[j] * rev[l] % MOD*rev[j - l] % MOD*by[j + k - l] % MOD*rev[j] % MOD*rev[k - l] % MOD;
					nbox[j + k - l] += add*dp[i][k]%MOD*box[j]%MOD;
					nbox[j + k - l] %= MOD;
				}
			}
		}
		box = nbox;
	}
	for (int i = 1; i <= N; i++)dp[node][i] = box[i - 1];
	return;
}

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

	cin >> N;
	vector<vector<int>>edge(N);
	vector<int>in(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		in[R]++;
	}
	for (int i = 2; i <= 400; i++) {
		by[i] = by[i - 1] * i%MOD;
		rev[i] = power(by[i], MOD - 2, MOD);
	}
	vector<vector<long long int>>dp(N, vector<long long int>(N + 1));
	int root = -1;
	for (int i = 0; i < N; i++) {
		if (in[i] == 0)root = i;
	}
	Search(edge, dp, root);
	cout << accumulate(dp[root].begin(), dp[root].end(), 0LL) % MOD << endl;
}


Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t> bool ckmin(t& a, const t& b) { return a > b ? a = b, true : false; }
template <class t> bool ckmax(t& a, const t& b) { return a < b ? a = b, true : false; }
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T> struct IsC {
  template <class C>
  static char test(typename C::const_iterator*);
  template <class C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <> struct IsC<string> { static const bool value = false; };
template <class C> typename enable_if<IsC<C>::value, ostream&>::type operator<<( ostream& o, const C& c) { o << '{'; for (auto it = c.begin(); it != c.end();) o << *it << (++it != c.end() ? ", " : "}"); return o; }
template <class a, class b> ostream& operator<<(ostream& o, const pair<a, b>& p) { return o << '(' << p.fi << ", " << p.se << ')'; }


void solve() {
    int s, w;
    cin >> s >> w;
    if(w >= s)
        cout << "unsafe\n";
    else
        cout << "safe\n";
    
}

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

    solve();
}



Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;

		if (N % 2 == 0) {
			ans = N / 2;
		} else {
			ans = (N + 1) / 2;
		}
		System.out.println(ans);
	}
}

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

int main()
{
  string S, T;
  cin >> S >> T;

  int ans = T.size();

  for (int i = 0; i <= S.size() - T.size(); i++)
  {
    int tmp = 0;
    for (int j = 0; j < T.size(); j++)
    {
      if (S.at(i + j) != T.at(j))
      {
        tmp++;
      }
    }
    ans = min(tmp, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3608
#include<stdio.h>

int main()
{	
	int S, h, m, s;
	scanf("%d",&S);
	
	h = S/3600;	
	m = (S - h * 3600)/60;
	s = (S - h * 3600 - m*60); 
	printf("%d:%d:%d\n",h,m,s);
	return 0;
} 


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (k % 2 == 0) {
		ans += (a - b);
	}
	else {
		ans += (b - a);
	}
	if (abs(ans) > 1e18) puts("Uufair");
	else dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;
int main(int argc, char *argv[])
{
  int N;
  string S;
  bool arphabet_before[30];
  bool arphabet_after[30];
  cin >> N;
  cin >> S;
  int result = 0;
  for (int i = 0; i < N; i++) {
    int counter = 0;
    for (int j = 0; j < 30; j++) {
      arphabet_before[j] = false;
      arphabet_after[j] = false;
    }
    
    for (int j = 0; j < i; j++) {
      arphabet_before[S[j]-97] = true;
    }
    for (int j = i; j < (int)S.length(); j++) {
      arphabet_after[S[j]-97] = true;
    }

    for (int j = 0; j < 30; j++) {
      if (arphabet_before[j] == true && arphabet_after[j] == true) {
	counter++;
      }
    }
    if (counter > result) {
      result = counter;
    }
  }
  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int sudoku[10][10];

bool ok(int a,int b){
	int i,j;
	for(i=0;i<9;i++){
		if(i!=a&&sudoku[a][b]==sudoku[i][b])return false;
	}
	for(i=0;i<9;i++){
		if(i!=b&&sudoku[a][b]==sudoku[a][i])return false;
	}
	for(i=a/3*3;i<a/3*3+3;i++){
		for(j=b/3*3;j<b/3*3+3;j++){
			if(i!=a&&j!=b&&sudoku[a][b]==sudoku[i][j])return false;
		}
	}
	return true;
}

int main() {
	int n=in();
	int i;
	for(i=0;i<n;i++){
		if(i>0)cout<<endl;
		int a,b;
		for(a=0;a<9;a++){
			for(b=0;b<9;b++){
				cin>>sudoku[a][b];
			}
		}
		for(a=0;a<9;a++){
			for(b=0;b<9;b++){
				if(ok(a,b)){
					cout<<" "<<sudoku[a][b];
				}else{
					cout<<"*"<<sudoku[a][b];
				}
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import math
a,b,c= map(int,input().split(" "))
k=int(input())
while(k>0 and b<=a):
    b*=2
    k-=1
while(k>0 and c<=b):
    c*=2
    k-=1
if a<b and b<c:
    print("Yes")
else:
    print("No")

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

#define Bye return 0
#define ll long long

using namespace std;

const int M = 1e5+1;

vector<int> marked(M, false);
vector<int> wrong_answers(M, 0);

void solve(){
    int n, m; cin>>n>>m;
    
    int AC = 0, WA = 0;
    for (int i=0; i<m; i++){
        int pos; string ans; cin>>pos>>ans;
        if(marked[pos]) continue;
        if(ans == "AC"){
            marked[pos] = true;
            AC++;
            WA += wrong_answers[pos];
        } else
            wrong_answers[pos]++;
    }
    cout<<AC<<" "<<WA<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3868
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n,m,l;
		long cal;
		int i,j,k;
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		m=scan.nextInt();
		l=scan.nextInt();
		long[][] yousoA =new long[n][m];
		long[][] yousoB =new long[m][l];
		long[][] yousoC =new long[n][l];
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++) {
			cal=scan.nextInt();
			yousoA[i][j]=cal;
			}
		}
		for(i=0;i<m;i++)
		{
			for(j=0;j<l;j++) {
				cal=scan.nextInt();
				yousoB[i][j]=cal;
				}
		}
		for(i=0;i<n;i++)
		{
			cal=0;
			for(j=0;j<l;j++) {
				for(k=0;k<m;k++) {
				cal=cal+yousoA[i][k]*yousoB[k][j];
				}
				yousoC[i][j]=cal;
				cal=0;
				if(j==l-1)
					break;
				System.out.print(yousoC[i][j]+" ");
			}
			System.out.println(yousoC[i][j]);
			
		}
		
	}
}

Measured memory_bytes: 53684
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String s=sc.next();
			int count=0;
			if(s.charAt(0)=='A') count++;
			int c=0;
			for(int i=2; i<=s.length()-2; i++) {
				if(s.charAt(i)=='C') {
					c++;
				}
			}
			if(c==1) count++;
			if(count>=2) {
				boolean tf=true;
				for(int i=0; i<s.length(); i++) {
					if(s.charAt(i)=='A' || s.charAt(i)=='C') {
						continue;
					}
					if(Character.isUpperCase(s.charAt(i))) {
						tf=false;
						break;
					}
				}
				if(tf) count++;
			}
			System.out.println((count==3)?"AC":"WA");

		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int K, A, B; cin >> K >> A >> B;
  
  if(A >= B-2 || A >= K) cout << K+1 << endl;
  else {
    int a = A;
    K -= A-1;
    a -= A;
    K--;
    a += B;
    K--;
    cout << a+(K/2)*(B-A)+(K%2) << endl;
  }

}

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

int a[1234];

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a+i);
	}
	long long ans = 2e15;
	for (int i = -100; i <= 100; ++i) {
		long long cur = 0;
		for (int j = 0; j < n; ++j) {
			cur += (i-a[j])*(i-a[j]);
		}
		ans = min(ans, cur);
	}
	printf("%lld", ans);
}

int main() {
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c;
    a=read(), b=read(), c=read();
    int tt=a+b+c;
    int qwq=max(max(a,b),c);
    int ty=qwq;
    int res=1;
    int K=read();
    for(ri int i=1;i<=K;i++) res*=2ll;
    qwq*=res;
    printf("%lld\n",tt+qwq-ty);
    return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }
    else{
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let k: usize = sc.get();
    let s: String = sc.get();

    if s.len() <= k {
        println!("{}", &s);
    } else {
        println!("{}...", &s[..k]);
    }
}


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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  cin >> N;
  vi A(N);
  REP(0, N, i) {
    cin >> A[i];
  }

  sort(all(A), greater<i64>());

  priority_queue<i64> Q;
  Q.push(A[0]);
  i64 ans = 0;
  REP(1, N, i) {
    ans += Q.top();
    Q.pop();
    Q.push(A[i]);
    Q.push(A[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6928
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0

inplutlist=inpl()
anslist = heapq.nsmallest(2,inplutlist)
ans = sum(anslist)
print(ans)

Measured memory_bytes: 21608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    vector<vector<int>> G(N);
    rep(i, N - 1){
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }
    G[X].push_back(Y);
    G[Y].push_back(X);
    //グラフの作成完了
    vector<int> ans(N, 0);
    rep(i, N){//各頂点を始点にしてBFS
        vector<int> dist(N, -1);
        queue<int> que;
        dist[i] = 0;
        que.push(i);
        while(!que.empty()){
            int v = que.front(); que.pop();
            for(int nv : G[v]){
                if(dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        for(int j : dist){
            ans[j]++;
        }
    }
    rep(i, N - 1) cout << ans[i + 1] / 2 << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		long[] AB = GetLongs(2);
		WriteLine(lcm(AB[0], AB[1]));
	}
	
	private long lcm(long x, long y) => (x / gcd(x,y)) * y;
	private long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13396
# N:標準入力
N = int(input())

# 結果の出力のための変数定義
result = 0

# Nまでの条件以外の繰り返しの合計
for i in range(1, N + 1):
    if i % 15 == 0:
        result += 0
    elif i % 3 == 0:
        result += 0
    elif i % 5 == 0:
        result += 0
    else:
        result += i
print(result)

Measured memory_bytes: 9172
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#include<bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define read(a) long long int a; cin>>a;
#define readstr(s) string s; cin>>s;
#define readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define v(pi) vector<ll>pi
#define vp(pi) vector<pair<ll,ll>>pi
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#include <cmath>
#include <map>
#include <string>
#define mi(lol) map<ll,ll>lol
#define fsort(vec) sort(vec.begin(),vec.end())
#define rsort(vec) sort(vec.begin(),vec.end(),compare)
#define inf ll inf=INT_MAX
//sorting according to the second element vector 

bool compare(pair<ll,ll> p,pair<ll,ll> q){
	return p.second < q.second;	
}

//   example:-
//   sort(vec.begin(),vec.end(),compare);


int main() {
	fast;
	readstr(s);
	loop(j,0,s.length()){
		if(s[j]=='7') {cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(1000000)

S=input()
s=[]
for i in S:
    s+=[i]
ans=0
que=[]
que+=[s[0]]
def cube(i):
    global ans
    if i==len(s):
        print(ans)
    else:
        que.append(s[i])
        flag=True
        while flag:
            if len(que)==0 or len(que)==1:
                flag=False
            elif que[-1]==que[-2]:
                flag=False
            elif que[-1]!=que[-2]:
                del que[-1]
                del que[-1]
                ans+=2
        cube(i+1)
cube(1)


Measured memory_bytes: 92048
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
# row = [int(input().rstrip()) for _ in range(n)]

def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())

    cities = [[int(x) for x in input().rstrip().split(" ")] for _ in range(n)]
    import math

    import itertools

    length_list = []
    p = itertools.permutations(list(range(n)), n)
    for v in p:
        length = 0
        for city_i in range(n - 1):
            city1 = cities[v[city_i]]
            city2 = cities[v[city_i + 1]]
            length += math.sqrt((city1[0] - city2[0]) ** 2 + (city1[1] - city2[1]) ** 2)

        length_list.append(length)

    print(sum(length_list) / len(length_list))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 75544
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))

using namespace std;

/*
s
t
 */

char s[3001], t[3001];
int len[3001][3001];
int from[3001][3001];
int ls,lt;

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

  ls = strlen(s);
  lt = strlen(t);

  REP(i,ls){
    REP(j,lt){
      if(s[i]==t[j]){
        len[i+1][j+1] = len[i][j]+1;
        from[i+1][j+1] = 0;
      } else if(len[i+1][j] > len[i][j+1]){
        len[i+1][j+1] = len[i+1][j];
        from[i+1][j+1] = 1;
      } else {
        len[i+1][j+1] = len[i][j+1];
        from[i+1][j+1] = 2;
      }
    }
  }

  int l = len[ls][lt];
  char ans[l+1];
  ans[l] = '\0';

  int i = ls;
  int j = lt;
  for(int k = l-1; k >= 0; ){
    switch(from[i][j]){
    case 0:
      i--;
      j--;
      ans[k] = s[i];
      k--;
      break;
    case 1:
      j--;
      break;
    case 2:
      i--;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70656