akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    int x,ans=0;
    cin>>x;
    struct point{double x, y;};
    point p;
    p.x=0;
    p.y=0;
    do{
        ans++;
        p.x+=cos(ans*M_PI*x/180+1/2);
        p.y+=sin(ans*M_PI*x/180+1/2);
        //cerr<<p.x<<" "<<p.y<<endl;
    }while(abs(p.x)>0.001||abs(p.y)>0.001);
    cout<<ans<<endl;
}

Measured memory_bytes: 3944
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    if(N % 2) {
        N *= 2;
    }
    output(N);
    
    return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N, vector<int> (0));
  for(int i = 0; i < M; i++){
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  
  vector<vector<int>> dist(N, vector<int>(2,-1));
  queue<int> que;
  
  dist[0][0] = 0;
  que.push(0);
  
  while(!que.empty()){
    int v = que.front();
    que.pop();
    
    for(auto nv : G[v]){
      if(dist[nv][0] != -1)
        continue;
      dist[nv][0] = dist[v][0] + 1;
      dist[nv][1] = v+1;
      que.push(nv);
    }
  }
  
  cout << "Yes" << endl;
  
  for(int v = 1; v < N; v++)
    cout << dist[v][1] << endl;
  
  return 0;
  
}

Measured memory_bytes: 21324
A = [[0]*3 for i in range(3)]
a = [[0]*3 for i in range(3)]

for i in range (3):
    X,Y,Z = map(int,input().split())
    a[i][0] = X
    a[i][1] = Y
    a[i][2] = Z

N = int(input())
b = [0]*N

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

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i] == a[j][k]:
                A[j][k] = 1

if sum(A[0]) ==3 or sum(A[1]) ==3 or sum(A[2]) ==3 or A[0][0]+A[1][0]+A[2][0] ==3 or A[0][1]+A[1][1]+A[2][1] ==3 or A[0][2]+A[1][2]+A[2][2] ==3 or A[0][0]+A[1][1]+A[2][2] ==3 or A[0][2]+A[1][1]+A[2][0] ==3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
//https://blog.csdn.net/hesorchen
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define lowbit(a) (a & (-a))
#define INF 0x3f3f3f3f
#define MAX 1010
#define mod 1000000007
#define PI 3.1415926
map<string, int> mp;
int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        string a;
        cin >> a;
        mp[a]++;
    }
    int maxx = 0;
    for (auto it = mp.begin(); it != mp.end(); it++)
        maxx = max(maxx, it->second);
    // cout << maxx << endl;
    for (auto it = mp.begin(); it != mp.end(); it++)
        if (maxx == it->second)
            cout << it->first << endl;

    return 0;
}

Measured memory_bytes: 25344
def rec(s):
    ans = int(1e8)
    c_list = []
    st = []
    n = len(s)
    l = 0
    r = len(s)-1
    if s[0]!='[':
        return 1+int(s)//2
    for i in range(n):
        _s = s[i]
        if _s=='[':
            if len(st)==0:
                l = i+1
            st.append(_s)
        elif _s==']':
            st = st[:-1]
            if len(st)==0:
                r = i
                c_list.append(rec(s[l:r]))
    c_list.sort()
    return sum( c_list[:1+len(c_list)//2] )

N = int(input())
for _ in range(N):
    s = input()
    print(rec(s))

Measured memory_bytes: 7720
N=int(input())
C=[c for c in input()]
R,W=0,0
for c in C:
  if c=='R': R+=1
  else: W+=1
ans,l,r = 0,0,N-1
while l<r:
  if C[l] == 'W' and C[r] == 'R':
    l,r = l+1,r-1
    ans += 1
  elif C[l] == 'R': l+=1
  elif C[r] == 'W': r-=1
ans = min(ans,min(R,W))
print(ans)

Measured memory_bytes: 11024
#ABC 087 B問題
L = [int(input()) for i in range(4)]
X=L[3]
counter=0
for a in range(L[0]+1):
    for b in range(L[1]+1):
        for c in range(L[2]+1):
            if 500*a+100*b+50*c==X:
                counter+=1
print(counter)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define MOD 1000000007

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

int main(void) {
  int i,j;
  vector<bool> prime(1005,true);
  loop(i,2,1005)
    if(prime[i])
      for(j=2;i*j<=1000;j++)
        prime[i*j]=false;
  prime[0]=prime[1]=false;

  vi num(1000,0);//素因数                         
  int n;
  cin>>n;
  for(i=2;i<=n;i++){
    for(j=2;j<=i;j++)//iを素因数分解              
      if(prime[j]){
        int number=i;
        while(number%j==0){
          num[j]++;
          number/=j;
        }
      }
  }
  ll ans=1;
  rep(i,n+1)
    ans=(ans*(num[i]+1))%MOD;
  cout<<ans%MOD<<endl;
}


Measured memory_bytes: 256
s = input()
t = input()
lenS = len(s)
lenT = len(t)
dp = []
for i in range(lenS+1):
    dp.append([0]*(lenT+1))
for i in range(1,lenS+1):
    for j in range(1,lenT+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=""
i=lenS
j=lenT
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans+=s[i-1]
        i-=1
        j-=1
print(ans[::-1])

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

ll inf=9223372036854775806,ans=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long long a,f;
    char b,c,d,e;
    scanf("%lld %c%c%c%c",&a,&b,&c,&d,&e);
    f = (b-'0')*100+(d-'0')*10+e-'0';
    printf("%lld",a*f/100);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  

int N;
vi tv,tw;
int q;
vp qq;
int border;
v(vl) dp;

int depth(int k) {
  if(k==0) return 1;
  return depth((k+1)/2-1)+1;
}

int main() {
  cin >> N;
  tv.resize(N);
  tw.resize(N);
  rep(i,N) {
    cin >> tv[i] >> tw[i];
  }
  int L=0;
  cin >> q;
  qq.resize(q);
  rep(qi,q) {
    cin >> qq[qi].first >> qq[qi].second;
    chmax(L,qq[qi].second+1);
  }
  const int X=10;
  border = min(1<<(X+1)-1,N);
  dp.assign(border,vl(L,0));
  rep(i,L) {
    if(i-tw[0]<0) continue;
    dp[0][i]=tv[0];
  }
  srep(i,1,border) {
    int p=(i+1)/2-1;
    dp[i]=dp[p];
    drep(j,L) {
      if(j-tw[i]<0) continue;
      chmax(dp[i][j],dp[i][j-tw[i]]+tv[i]);
    }
  }
  
  rep(qi,q) {
    int k=depth(qq[qi].first-1);
    if(k<=X) {
      cout << dp[qq[qi].first-1][qq[qi].second] << endl;
      continue;
    }
    ll ans = 0;
    rep(b,1<<(k-X)) {
      ll sw=0,sv=0;
      int now=qq[qi].first-1;
      rep(i,k-X) {
        if((b>>i)&1) {
          sw+=tw[now];
          sv+=tv[now];
        }
        now=(now+1)/2-1;
      }
      if(sw>qq[qi].second) continue;
      int rem=qq[qi].second-sw;
      chmax(ans,sv+dp[now][rem]);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 809708
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main() {
	int n , m;
	cin >> n >> m;
	vector<int>broken(n + 1);
	rep(i, m){
		int a; cin >> a;
		broken[a] = 1;
	}
	const int mod = 1000000007;
	vector<int>dp(n + 2);
	dp[n] = 1;
	for(int i = n - 1; i >= 0; i--){
		if(broken[i] ){
			dp[i] = 0;
			continue;
	}
		dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
	}

	cout << dp[0] << endl;
  return 0;
}


Measured memory_bytes: 1024
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
def isok(x,y):##適宜変更
    if x+y<=k:
        return True
    else:
        return False

def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1,Trueならlen(ls)-1
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2
    return ok ##一番右のTrueのindex  Trueの個数はok+1こ


n,m,k = ma()
A  = list(ma())
B = list(ma())
la = [0]*(n+1)
lb = [0]*(m+1)
for i in range(n):
    la[i+1] = la[i] + A[i]
for i in range(m):
    lb[i+1] = lb[i] + B[i]

ans = 0
for i in range(n+1):
    if la[i] >k:break
    idx = bisect(lb,la[i])
    ans = max(ans,idx+i)
print(ans)


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

int main(){
  int a,pay;
  string ans;
  cin >> pay >>a;

  int num = pay/500;
  int amari = pay - (num * 500);

  if(a >= amari){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    cout << n << ":";
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            cout << " " << i;
            n /= i;
        }
    }
    if (n != 1) {
        cout << " " << n;
    }
    cout << endl;
}



Measured memory_bytes: 3100
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>

using namespace std;

typedef long long int lli;

int main() {
	int n;
	double xy[3][3],x,y;
	double a, b, c, d, e, f, radius;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 2; k++) {
				cin >> xy[j][k];
			}
		}
		a = -2 * (xy[0][0]-xy[1][0]);
		b = -2 * (xy[0][1] - xy[1][1]);
		c = -1 * (pow(xy[0][0], 2) + pow(xy[0][1], 2)) + pow(xy[1][0], 2) + pow(xy[1][1], 2);
		d = -2 * (xy[0][0] - xy[2][0]);
		e = -2 * (xy[0][1] - xy[2][1]);
		f = -1 * (pow(xy[0][0], 2) + pow(xy[0][1], 2)) + pow(xy[2][0], 2) + pow(xy[2][1], 2);
		y = (a*f - c*d) / (a*e - b*d);
		x = (c*e - b*f) / (a*e - b*d);
		if (x == 0) x = 0;
		if (y == 0) y = 0;
		radius =sqrt(pow((x-xy[0][0]),2)+pow((y-xy[0][1]),2));

		cout << fixed << setprecision(3) << x << " " << y << " "<< radius <<endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <math.h>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	ll x; cin >> x;
	ll a = (x / 11) * 2;
	ll b = x % 11;
	if (b != 0) {
		if (b > 6 && b < 11) a += 2;
		if (b <= 6) a++;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <utility>

#define MAX_N 100

void select_sort(int*,int);
void bubble_sort(int*,int);

int A[MAX_N];
int count = 0;
int n;
int d[MAX_N];
char c[MAX_N];


struct card
{
    char c;
    int d;
    int initial_index;
} card[MAX_N];

struct card_s
{
    char c;
    int d;
    int initial_index;
} card_s[MAX_N];


int main(){

    scanf("%d\n",&n);
    for(int i = 0; i < (n-1); i++){
        scanf("%c%d ",&card[i].c,&card[i].d);
        card_s[i].c = card[i].c;
        card_s[i].d = card[i].d;
        card[i].initial_index = i;
        card_s[i].initial_index = i;
    }
    scanf("%c%d",&card[n-1].c,&card[n-1].d);
    card[n-1].initial_index = n-1;
    card_s[n-1].initial_index = n-1;
    card_s[n-1].c = card[n-1].c;
    card_s[n-1].d = card[n-1].d;
    
//    for(int i = 0; i < n; i++){
//        printf("c %c d %d initial_index %d\n",card[i].c,card[i].d,card[i].initial_index);
//    }
    for(int times = 0; times < 2; times++){
        if(times == 0){bubble_sort(d,n);}
        else{
            for(int i = 0; i < n; i++){
                card[i].c = card_s[i].c;
                card[i].d = card_s[i].d;
                card[i].initial_index = card_s[i].initial_index;
            }
            select_sort(d,n);
        }
        for(int i = 0; i < n; i++){
            if(i<(n-1))printf("%c%d ",card[i].c,card[i].d);
            if(i == (n-1)) printf("%c%d\n",card[i].c,card[i].d);
        }
        bool stable = true;
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                if(card[i].d == card[j].d){
                    if(card[i].initial_index > card[j].initial_index){
                        stable = false;
                    }
                }
            }
        }
        if(stable){printf("Stable\n");}
        else{printf("Not stable\n");}
    }
}

void bubble_sort(int* a,int n){
    for(int i = 0; i < n; i++){
        for(int j = (n - 1); j > i; j--){
            if(card[j].d < card[j-1].d){
//                if(d[j] == d[j-1] && c[j] == c[j-1]) count++;
                std::swap(card[j],card[j-1]);
            }
        }
    }

}


void select_sort(int* a,int n){
    for(int i = 0; i < (n-1); i++){
        int a_min = MAX_N;
        int a_min_idx = MAX_N + 1;

        for(int j = i+1; j <n; j++){
            if(card[j].d < a_min){
                a_min = card[j].d;
                a_min_idx = j;
            }
        }
        if(card[i].d > card[a_min_idx].d){
            std::swap(card[i],card[a_min_idx]);
        }
    }
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll N, M;
  cin >> N >> M;
  COUT(0.5 * N * (N - 1) + 0.5 * M * (M - 1));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;







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

  
    
    int n;
    cin>>n;

    map<int,int>m;
    for(int i=2;i<=n;i++)
    {
       int k=i;
       for(int j=2;k&&j*j<=i;j++)
       {
          int cnt=0;
          while(k%j==0)
          {
             k/=j; cnt++;
          }
          m[j]+=cnt;

       }
       if(k>1)
       m[k]+=1;
    }
int ans=1;
    for(auto i : m)
   {
      ans=ans*(i.second+1)%mod;
   }
cout<<ans<<"\n";

  

   
}

 

 
 
 
 
 

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 2e5 + 1e3;

vector<int> V[N];

priority_queue<pair<int, int>> P;

int L[N], R[N]; bool book[N];

int main() {

	File();

	int n = read(), m = read();

	For (i, 1, n)
		L[i] = read(), R[i] = read(), V[L[i]].push_back(i);

	For (i, 1, m) for (int id : V[i]) {
		if (int(P.size()) < i) P.emplace(-R[id], id), book[id] = true;
		else {
			if (-P.top().first < R[id]) {
				book[P.top().second] = false, P.pop();
				P.emplace(-R[id], id), book[id] = true;
			}
		}
	}

	For (i, 1, m) V[i].clear();
	For (i, 1, n) if (!book[i]) V[R[i]].push_back(i);

	int pre = P.size(), ans = pre, rest = 0;
	Fordown (i, m, 1) {
		if (i > pre) ++ rest;
		Rep (j, V[i].size())
			if (rest) -- rest, ++ ans;
	}
	printf ("%d\n", n - ans);

	return 0;

}

Measured memory_bytes: 13812
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////
ll modpow(ll a,ll n){
    if (n == 1) return a % mod;
    if (n % 2 == 1) return (a * modpow(a,n-1)) % mod;
    ll t = modpow(a,n/2);
    return (t * t) % mod;
}

int main(){
    ll m,n;
    cin >> m >> n;
    cout << modpow(m,n) << endl;
}   



Measured memory_bytes: 3112
import sys
sys.setrecursionlimit(10**7)
import math
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def TWO(M):
  L=[0]*M
  R=[0]*M
  for i in range(M):
    L[i],R[i] = II()
  return L, R

from itertools import product
S = I()
mark = list(product(['','+'],repeat=len(str(S))-1))
ans = 0
for a in mark:
  form = ''
  for i in range(len(str(S))*2-1):
    if i%2==0:
      form += str(S)[i//2]
    else:
      form += a[i//2]
  ans += eval(form)
print(ans)

Measured memory_bytes: 39664
from collections import deque
while True :
    try : 
        s = deque()
        s.append(float(input()))
        for _ in range(9) :
            if _ % 2 == 0 : s.append(s[_]*2)
            else : s.append(s[_]/3)
        print(sum(s))
    except : 
        break

Measured memory_bytes: 7588
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r; cin >> r;
    ll res = 3 * r * r;
    cout << res;
    cout << endl;
    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Team{
  int team_id=-1;
  int wa_count[11]={};
  int ac_time=9999;
  int penalty_time=9999;
  int result_time=999999;
  int ac_count=-1;
  bool operator==(const Team& another)const{
    return ac_count==another.ac_count&&result_time==another.result_time;
  }
};

bool Comp(const Team& a,const Team& b){
  if(a.ac_count!=b.ac_count){
    return a.ac_count>b.ac_count;
  }else if(a.result_time!=b.result_time){
    return a.result_time<b.result_time;
  }else{
    return a.team_id>b.team_id;
  }
}


void Solve(int m,int t,int p,int r){
  std::vector<Team> team(t+1);

  for(int i=1;i<=t;i++){
    team[i].team_id=i;
    team[i].ac_time=0;
    team[i].penalty_time=0;
    team[i].result_time=0;
    team[i].ac_count=0;
  }
  for(int i=0;i<r;i++){
    int mk,tk,pk,jk;
    cin>>mk>>tk>>pk>>jk;
    Team& tgt=team[tk];
    if(jk==0){
      //AC
      tgt.ac_time+=mk;
      tgt.penalty_time+=tgt.wa_count[pk]*20;
      tgt.ac_count++;
    }else{
      //WA
      tgt.wa_count[pk]++;
    }
  }

  for(int i=1;i<=t;i++){
    team[i].result_time=team[i].penalty_time+team[i].ac_time;
  }

  std::sort(team.begin(),team.end(),Comp);

  for(int i=0;i<t-1;i++){
    if(team[i]==team[i+1]){
      cout<<team[i].team_id<<"=";
    }else{
      cout<<team[i].team_id<<",";
    }
  }
  cout<<team[t-1].team_id<<endl;


}



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


  while(true){
    int m,t,p,r;
    cin>>m>>t>>p>>r;
    if(m==0&&t==0&&p==0&&r==0){
      break;
    }
    Solve(m,t,p,r);

  }




  return 0;
}



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

int N;
int x, y;

int main() {
  scanf("%d", &N);
  int c = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &x, &y);
    if (x == y) {
      c++;
    } else {
      c = 0;
    }
    if (c == 3) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
ll k;
cin>>n>>k;
vector<int> a(n);
rep(i,n){
    cin>>a[i];
    a[i]--;
}
vector<int> visit(n,0);
int idx=0;
int to_loop=0;
int freq_loop=0;
while(true){
    if(visit[idx]==0){
        visit[idx]++;
        to_loop++;
        idx=a[idx];
    }
    else{
        visit[idx]++;
        if(visit[idx]==2){
            freq_loop++;
            idx=a[idx];
        }
        else{
            break;
        }
    }
}
to_loop-=freq_loop;
idx=0;
if(k<to_loop){
    rep(i,k){
        idx=a[idx];
    }
}
else{
    k=to_loop+ (k-to_loop)%freq_loop;
    rep(i,k){
        idx=a[idx];
    }

}
cout<<idx+1<<endl;
return 0;
}

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


int main(){
	string S;
	cin >> S;
	vector<int> A(4);
	for(int i = 0; i < 4; ++i){
		A[i] = S[i] - '0';
	}
	for (int bit = 0; bit < (1<<3); ++bit) {
		int tmp = A[0];
		vector<char> op(3);
		for (int i = 0; i < 3; ++i) {
			if(bit & (1<<i)) {
				tmp += A[i+1];
				op[i] = '+';
			}
			else {
				tmp -= A[i+1];
				op[i] = '-';
			}
		}
		if(tmp == 7){
			cout << A[0] << op[0] << A[1] << op[1] << A[2] << op[2] << A[3] << "=7" << endl;
			return 0;
		}
	}
	return 0;

}














Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
#include <cstring>
#include <unordered_map>
using namespace std;
const int MAXN=405;
typedef long long ll;
struct Node{
	int a,b,c,d;
}a[MAXN];
int n;
unordered_map<ll,int>mp;
inline ll gethsh(Node x)
{
	return (ll)x.a<<30|(ll)x.b<<20|(ll)x.c<<10|(ll)x.d;
}
ll hsh[MAXN];
bool flag=true;
inline void add(ll x,int v)
{
	for(int i=0;i<4;++i,x=(x>>10)|((x&1023)<<30))
		mp[x]+=v;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		Node x;
		scanf("%d%d%d%d",&x.a,&x.b,&x.c,&x.d);
		a[i]=x;
		hsh[i]=gethsh(x);
		add(hsh[i],1);
	}
	ll ans=0;
	for(int i=1;i<=n-5;++i){
		add(hsh[i],-1);
		Node x=a[i];
		for(int j=i+1;j<=n;++j){
			add(hsh[j],-1);
			Node y=a[j];
			for(int p2=0;p2<4;++p2){
				ll now=1;
				ll t[5]={0};
				t[0]=gethsh((Node){x.b,x.a,y.b,y.a});
				t[1]=gethsh((Node){x.c,x.b,y.a,y.d});
				t[2]=gethsh((Node){x.a,x.d,y.c,y.b});
				t[3]=gethsh((Node){x.d,x.c,y.d,y.c});
				for(int k=0;k<4;++k){
					int o=mp.count(t[k])?mp[t[k]]:0;
					now*=o;
					add(t[k],-1);
				}
				for(int k=0;k<4;++k)
					add(t[k],1);
				ans+=now;
				swap(y.a,y.b),swap(y.b,y.c),swap(y.c,y.d);
			}
			add(hsh[j],1);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;

int main() {
  ll N,K,index;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i=0;i<N;i++) {
    cin >> A.at(i);
    if (A.at(i)==1) {
      index = i;
    }
  }

  ll ans;
  if ((N-1)%(K-1)==0) {
    ans = (N-1)/(K-1);
  }
  else {
    ans = (N-1)/(K-1)+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python

def main():
    S = input()
    size = len(S)

    ans = 0
    for bit in range(1 << size-1):
        exp = S[0]
        for i in range(size-1):
            if (bit & (1 << i)):
                exp += '+'
            exp += S[i+1]
        ans += eval(exp)

    print(ans)

if __name__ == '__main__':
    main()

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

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

	int ret=1;
	for (int i=1;i<n;i++)
	{
		int t;
		cin>>t;
		if (t<m) {m=t;ret++;}
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

int n, a, b;
void run(){
    cin >> n;
    int cnt = 0, mx = 0;
    for(int i = 1; i <= n; i++){
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        mx = max(mx, cnt);
    }
    DEBUG(mx >= 3 ? "Yes" : "No");
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios_base::sync_with_stdio(false);

    run(); return 0;
}


Measured memory_bytes: 3612
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N+1):
        if Y == 10000*x+5000*y+1000*(N-x-y) and N-x-y >=0:
            print("{} {} {}".format(x,y,N-x-y))
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int K = scan.nextInt();
        String S = scan.next();
        String T = scan.next();
        solve(N, M, K, S, T);
    }
    public static void solve(int N, int M, int K, String S, String T) {
        int[] x = new int[10000000];
        int[] y = new int[10000000];
        Arrays.fill(x, -1);
        Arrays.fill(y, -1);
        int t = 0;
        for(char c : new StringBuilder(S).reverse().toString().toCharArray()) {
            x[t++] = c == '0' ? 0 : 1;
        }
        t = 0;
        for(char c : new StringBuilder(T).reverse().toString().toCharArray()) {
            y[t++] = c == '0' ? 0 : 1;
        }
        int min = Math.min(N-1, M-1);
        for (int i = min; 0 <= i; i--) {
            if (x[i] != 1 || y[i] != 1) {
                continue;
            }
            int times = 0;
            boolean x_up = false;
            boolean y_up = false;
            int j = i;
            while(times < K) {
                if (x[j] == 1 && y[j] == 1) {
                    x[j] = 0;
                    y[j] = 0;
                    x_up = true;
                    y_up = true;
                    times += 1;
                } else {
                    break;
                }
                while (x_up || y_up) {
                    j++;
                    if (x_up) {
                        if (x[j] == -1) {
                            x[j] = 1;
                        } else {
                            x[j] += 1;
                        }
                        x_up = false;
                    }
                    if (y_up) {
                        if (y[j] == -1) {
                            y[j] = 1;
                        } else {
                            y[j] += 1;
                        }
                        y_up = false;
                    }
                    if (x[j] == 2) {
                        x[j] = 0;
                        x_up = true;
                    }
                    if (y[j] == 2) {
                        y[j] = 0;
                        y_up = true;
                    }
                }
            }
        }

        StringBuffer x_str = new StringBuffer();
        for(int i = 0; i < 10000000; i++) {
            if (x[i] != -1) {
                x_str.append(x[i]);
            } else {
                break;
            }
        }
        StringBuffer y_str = new StringBuffer();
        for(int i = 0; i < 10000000; i++) {
            if (y[i] != -1) {
                y_str.append(y[i]);
            } else {
                break;
            }
        }
        System.out.println(x_str.reverse().toString());
        System.out.println(y_str.reverse().toString());
    }
}


Measured memory_bytes: 161456
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(){
    int N, Y;
    cin >> N >> Y;
    for(int x = 0; x <= N; x++){
        for(int y = 0; y <= N; y++){
            int z = N - x - y;
            if(z >= 0 and 10000 * x + 5000 * y + 1000 * z == Y){
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int A = sc.nextInt();
 
    int N = H/A;
    int n = H%A;
      if(n==0){
	System.out.println(N);
      }else{
    System.out.println(N+1);
      }
      }
}



Measured memory_bytes: 20948
#include <stdio.h>

int main () {

  int a,b;

 scanf("%d%d", &a,&b);

 if ((a>0 && b>0) && (a<10 && b<10)) {
   printf("%d\n",a*b);
 } else {
   printf("-1\n");
 }


 return 0;
}


Measured memory_bytes: 128
function Main(input) {
   	var inputArray = input.split("\n");
	var N=inputArray[0]*1;
	var S=inputArray[1];
	
	var first;
	var second;
	var third;
	
	var j;
	
	var hitotsu;
	var futatsu;
	var mittsu;
	var kazoeru=0;
	
	var Idx;
	
	for(var i=0;i<1000;i++){
		first=parseInt(i/100);
		second=parseInt((i-first*100)/10);
		third=i-first*100-second*10;
		
		hitotsu=0;
		futatsu=0;
		mittsu=0;
		
		
		
		for(j=0;j<N;j++){
			Idx=1;
			if(hitotsu==0){
				if(S.charAt(j)*1==first){
					hitotsu=1;
					Idx=0;
					//console.log("hitotsume");
				}
			}
			if(Idx==1&&hitotsu==1&&futatsu==0){
				if(S.charAt(j)*1==second){
					futatsu=1;
					Idx=0;
					//console.log("futatsume");
				}
			}
			if(Idx==1&&hitotsu*futatsu==1){
				if(S.charAt(j)*1==third){
					kazoeru++;
					break;
				}
			}
		}
	}
		
		
	console.log(kazoeru);
	
}
     
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7872
#include <iostream>
using namespace std;
struct statis{
    int a;
    char b;
};
int main()
{
    struct statis alpahbet[26];
    string alph="abcdefghijklmnopqrstuvwxyz";
    for(int i=0;i<26;i++)
    {
        alpahbet[i].a=0;
        alpahbet[i].b=alph[i];
    }
    char temp,last;
    while(cin.get(temp))
    {
        if(last==temp&&temp=='\n')
            break;
        for(int i=0;i<26;i++)
        {
            if(temp==alpahbet[i].b||temp+32==alpahbet[i].b)
                alpahbet[i].a++;
        }
        last=temp;
    }

    for(int i=0;i<26;i++)
        cout<<alpahbet[i].b<<" : "<<alpahbet[i].a<<endl;
    return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>

using namespace std;

struct edge{
  int src, dst, w;
  edge(int src, int dst, int w):src(src),dst(dst),w(w){}
  bool operator<(const edge &t)const{
    if( w != t.w ) return w > t.w;
    if( src != t.src ) return src < t.src;
    return dst < t.dst;
  }
};
typedef vector<edge> edges;
typedef vector<edges> graph;

const int N = 10010;
const int INF = 800000010;

double mst_prim(const graph &g, int r, bool ran[N]){
  const int n = g.size();
  double ret = 0;
  bool vis[n];
  
  fill(vis,vis+n,false);
  priority_queue<edge> Q;
  Q.push( edge(-1,r,INF-0) );
  ran[r] = true;
  while(!Q.empty()){
    edge e = Q.top(); Q.pop();
    if( vis[e.dst] ) continue;
    //cout << e.w << ' ' << -e.w + 10000 << ' ' << ret << endl;
    ret += sqrt(-e.w+INF);
    vis[e.dst] = true;
    ran[e.dst] = true;
    for(int i = 0; i < (int)g[e.dst].size(); ++i){
      if( !vis[g[e.dst][i].dst] ) Q.push( g[e.dst][i] );
    }
  }
  return ret;
}

#define SQ(a) ((a)*(a))

int main()
{
  int n,m;
  while(EOF!=scanf("%d%d",&n,&m)){
    int x[n],y[n];
    bool ran[N];
    double total = 0;
    graph g(n);

    for(int i = 0; i < n; ++i){
      scanf("%d%d", &x[i], &y[i]);
    }
    fill(ran,ran+n,false);
    
    for(int i = 0; i < m; ++i){
      int p,q;
      scanf("%d%d", &p, &q);
      --p;
      --q;
      int w = SQ(abs(x[p]-x[q])) + SQ(abs(y[p]-y[q]));
      total += sqrt(w);
      g[p].push_back( edge(p,q,INF-w) );
      g[q].push_back( edge(q,p,INF-w) );
    }

    double rem = 0;
    for(int i = 0; i < n; ++i){
      if(!ran[i]){
	double tmp = mst_prim(g,i,ran);
	//cout << tmp << endl;
	rem += tmp;
      }
    }
    printf("%.12lf\n", total-rem);
    
  }
  return 0;
}

Measured memory_bytes: 2476
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    
    sort(A.begin(),A.end(),greater<ll>());
    ll out = A[0];
    for(int i=1;i<(N)/2;i++){
        out += A[i]*2;
    }
    if(N%2==1){
        out += A[N/2];
    }
    cout << out << endl;
    return 0;
}


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

using namespace std;

void Main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N, 0), b(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<int> c(M, 0), d(M, 0);
    for (int i = 0; i < M; ++i) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < N; ++i) {
        int minj = 0;
        int mind = abs(c[0] - a[i]) + abs(d[0] - b[i]);
        for (int j = 1; j < M; ++j) {
            int dist = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if (dist < mind) {
                mind = dist;
                minj = j;
            }
        }
        cout << minj + 1 << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3524
/*
*
*   Bismillah Hir Rahman Nir Raheem
*   Name: Jaied Al Sabid
*
*/

#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf
#define elif else if

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

    int64_t a,b;
    cin>>a>>b;
    if(a>b)
    {
        swap(a,b);
    }
    int x = 1;
    while(true)
    {
        if((b*x)%a == 0)
        {
            cout<<b*x<<endl;
            break;
        }
        else
        {
            x++;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll sum(ll n){
	return (n*(n+1))/2;
}
int main(){
	ll n;
	cin>>n;
	ll ans=sum(n)-sum(n/3)*3-sum(n/5)*5+sum(n/15)*15 ;
	cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int N[maxn];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    scanf("%d", &N[i]);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (N[i] == i + 1)
        {
            swap(N[i], N[i+1]);
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <cstring>
#include <set>
#include <bitset>
#include <map>
#include <chrono>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;
const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);

#define all(c) (c).begin(),(c).end()
#define forn(i, a, b) for(int i = a; i < b; i++)
#define read(x) scanf("%d", &x)
#define readv(x, n) vi x(n); forn(i,0,n) scanf("%d", &x[i])

#define pb push_back
#define mp make_pair


int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "wt", stdout);
//#endif
    int n;
    scanf("%d", &n);
    readv(a,n);
    readv(b,n);
    forn(i,1,n) a[i] += a[i-1];
    for(int i = n-2; i>=0; i--) b[i]+=b[i+1];
    int ans = 0;
    forn(i,0,n) ans = max(ans, a[i]+b[i]);
    cout<<ans;
    
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  string str,sub;
  int len,ans=0;
  bool flag=true;
  cin >> str;
  len = str.size();
  rep(i,len){
    rep(j,len-i){
      sub=str.substr(j,i+1);
      rep(i,sub.size()){
        if(sub[i]!='A'&&sub[i]!='T'&&sub[i]!='G'&&sub[i]!='C'){
          flag = false;
          break;
        }
      }
      if(flag){
        ans=i+1;
      }
      flag = true;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}
    vector<bool> a_eq(n, false);
    rep(i, n){if(i+1 == a[i]) a_eq[i] = true;}

    int ans = 0;
    rep(i, n){
        if(a_eq[i] == true){
            ans++;
            i++;
        } 
    }
    cout << ans << endl;
}



Measured memory_bytes: 892