akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    sc.nextLine
    val ABC = Array.fill(3)(sc.nextLine)

    var n = 0
    for (i <- 0 until N) {
      if (ABC(0)(i) != ABC(1)(i)) {
        n += 1
      }
      if (ABC(0)(i) != ABC(2)(i) && ABC(1)(i) != ABC(2)(i)) {
        n += 1
      }
    }
    n.toString
  }
}


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

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

index = l.index(m)  

l.pop(index)

for i in range(n):
  if i == index:
  	print(max(l))
  else:
    print(m)

Measured memory_bytes: 12512
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline long long read()
{
	long long kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
LL n,p;
LL su[1000111],co=0;
bool vis[1000111];
void init()
{
	for(LL i=2;i<=1e6+10;++i)
	{
		if(!vis[i])
		{
			su[++co]=i;
		}
		for(int j=1;j<=co&&su[j]*i<1e6+10;++j)
		{
			vis[su[j]*i]=1;
			if(i%su[j]==0)break;
		}
	}
	return;
}
int main()
{
	init();
	n=read();p=read();
	if(n==1)printf("%lld\n",p);
	else
	{
		LL asd=1;
		for(int i=1;i<=co&&su[i]<=p/su[i];++i)
		{
			LL now=0;
			while(p%su[i]==0)
			{
				p/=su[i];
				now++;
			}
			asd=asd*pow(su[i],(now/n));
		}
		printf("%lld\n",asd);
	}
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#define PI 6*asin(0.5)
using namespace std;

int main(){
  int i,j,n;
  double x,y,na,ka;
  while(1){
    cin >> n;
    if(n == -1) break;

    x = 1.0;
    y = 0.0;
    ka = 0.0;
    na = 0.0;
    for(i=1;i<n;i++){
      na = sqrt(pow(na,2) + 1.0);
      ka += PI - (PI/2 + acos(1.0/na));

      x = x + cos(ka);
      y = y + sin(ka);
    }

    printf("%.2f\n%.2f\n",x,y);

  }
  return 0;
 }

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

int main(){
	bool first = true;
	double input, high = 0, low = 0;

	while ( cin >> input ){
		if ( first ){
			high = low = input;
			first = false;
		}else{
			if ( input > high ){
				high = input;
			}else if ( input < low ){
				low = input;
			}
		}
	}

	input = high - low;
	cout << input << endl;

	return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);

  int n, k;
  cin >> n >> k;

  long double ans = 0;
  vector<long double> a(n);
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a[i] = (x+1);
    if (i) a[i] += a[i-1];
    if (i >= k) ans = max(ans, a[i] - a[i-k]);
  }
  ans = max(ans, a[k-1]);
  cout << ans / 2 << '\n';
}

Measured memory_bytes: 3328
import heapq

N = int(input())
a = list(map(int, input().split()))

f = a[:N]
heapq.heapify(f)
red = [0] * (N + 1)
red[0] = sum(f)

l = [-i for i in a[2*N:]]
heapq.heapify(l)
blue = [0] * (N + 1)
blue[N] = -sum(l)

for i in range(N):
    num1 = a[N + i]
    pop1=heapq.heappushpop(f, num1)
    red[i+1] = red[i] + num1 - pop1

    num2 = a[2*N - i - 1]
    pop2=heapq.heappushpop(l, -num2)
    blue[N-i-1] = blue[N-i] + num2 + pop2

ans = red[0] - blue[0]

for k in range(N+1):
    ans = max(ans, red[k] - blue[k])

print(ans)


Measured memory_bytes: 117412
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int INF=1e5+5;
int n,num[INF],q;
long long sum;
signed main()
{
        scanf("%lld",&n);
        for (int i=1; i<=n; i++) {
                int x=0;
                scanf("%lld",&x);
                sum+=x;
                num[x]++;
        }
        scanf("%lld",&q);
        while (q--) {
                int x=0,y=0;
                scanf("%lld %lld",&x,&y);
                num[y]+=num[x];
                sum+=(y-x)*num[x];
                num[x]=0;
                cout<<sum<<"\n";
        }
        return 0;
}


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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  string s,t;
  int n;
  cin >> n >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main (){
    int n,k;
    cin >> n >> k;
    int x=1;
    for(int i=0; i<n; i++){
        if( x + k < x * 2 ) x += k;
        else  x *= 2;
    }
    cout << x << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << 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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll a[n],b[n],c[n];
  rep(i,0,n)cin>>a[i]>>b[i]>>c[i];

  ll dp[n][3];
  rep(i,0,n)CLR(dp[i],0);
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  rep(i,1,n){
    rep(j,0,3){
      dp[i][j]+=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
      if(j==0)dp[i][j]+=a[i];
      else if(j==1)dp[i][j]+=b[i];
      else dp[i][j]+=c[i];
    }
  }

  out(max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));

  return 0;
}


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

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

    vector<int> C(N - 1);
    vector<int> S(N - 1);
    vector<int> F(N - 1);

    for (int i = 0; i < N - 1; i++)
    {
        cin >> C.at(i) >> S.at(i) >> F.at(i);
    }

    for (int i = 0; i < N - 1; i++)
    {
        int t = 0;
        for (int j = i; j < N - 1; j++)
        {
            if (t <= S.at(j))
                t = S.at(j) + C.at(j);
            else if (t % F.at(j) == 0)
            {
                t = t + C.at(j);
            }
            else
            {
                t = t + F.at(j) - (t % F.at(j)) + C.at(j);
            }
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
 int n = 0, k = 0,val=0,val1;
 cin >> n >> k;
 val = k;
 val1 = val - 1;
 for (int i = 0; i < n-1; i++)
 {
  val = val*val1;
 }
 cout << val;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s,e;
    cin >> s >> e;
    rep(i,e.size()){
        cout << s[i];
        cout << e[i];
    }
    if(s.size()>e.size())cout << s[s.size()-1];
    cout << endl;
}
   

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


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

    string tmp;

  rep(i,N){
    cin >> tmp;
    if (tmp == "Y"){
      cout << "Four";
      return 0;
    }
  }
  cout << "Three";
}


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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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 (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353


ll dp[100010][2];
vi L(100010);

ll rec(int n, bool f) { //Lより既に小さくなっているかどうかをfで記憶
    if (n == -1) return 1;

    ll &res = dp[n][f];
    if (~res) return res;
    res = 0;

    //x = 0, y = 0;
    res += rec(n - 1, f | L[n]);

    //x=0,y=1 or x = 1, y=0
    if (f | L[n]) {
        res += 2 * rec(n - 1, f);
    }

    res %= MOD;
    return res;
}

int main() {
    memset(dp, -1, sizeof(dp));
    string s; cin >> s;
    int N = s.size();
    rep(i, N) {
        L[i] = s[N - i - 1] - '0';
    }

    cout << rec(N, 0) << endl;

}


Measured memory_bytes: 7120
def main():
    n = int(input())
    a = tuple(int(x) for x in input().split())

    memo = tuple([None] * n for _ in range(n))
    for i in range(n):
        memo[i][i] = a[i]

    for l in range(n - 2, -1, -1):
        for r in range(l + 1, n):
            memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1])

    print(memo[0][n - 1])


if __name__ == '__main__':
    main()

# [l,r]を
# l:=配列aの右端から左にシフト
# r:=lと一致する位置からn-1まで右にシフト
# と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい
# 漸化式で使う値は、
# lがより右にいるときの計算結果（前のループで計算済み）と
# rがより左にいるときの計算結果（一番左でもl==rなので計算済み）
# なので、参照する値がNoneになることはなく、Noneのチェックは不要になる

# 関数名は関係あるのか？


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

int main(void){
	int n, minv=0, ans=-2e9;
	cin >> n;
	vector<int> r(n);
	for(int i=0; i<n; i++){
		cin >> r[i];
        if(i!=minv && r[i]-r[minv] > ans) ans=r[i]-r[minv];
		if(r[i] < r[minv]) minv=i;
		if(i!=minv && r[i]-r[minv] > ans) ans=r[i]-r[minv];
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>

int main(void)
{
	int i,j,n,count=0;
	scanf("%d", &n);
	int a[n];
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	
	for(i=0; i<n; i++){
		int check=0;
		if(a[i] < 2){
			check++;
		}
		else if(a[i] == 2){
			count++;
		}
		
		if(a[i] % 2 ==0){
			check++;
		}
		
		for(j=3; j <= sqrt(a[i]); j+=2){
			if(a[i] % j ==0){
				check++;
				break;
			}
		}
		if(check == 0){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>

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

int main() {
	int N; cin >> N;
	char S[101]; cin >> S;

	int x = 0;
	int X = 0;
	rep(i, 0, 101) {
		if (S[i] == '\0')break;
		if (S[i] == 'I')x++;
		if (S[i] == 'D')x--;
		if (X < x) X = x;
	}
	cout << X << endl;

	return 0;
}

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

using namespace std;

int main() {

  int n, boi;
  //string popo, team, huff= "Hufflepuff:\n", rave = "Ravenclaw:\n", slyt = "Slytherin:\n", gryf = "Gryffindor:\n";
  cin >> n;
  boi = n;
  cin >> n;
  boi += n;
  cin >> n;
  boi += n;
  if(boi > 21){
    cout << "bust";
  }else{
    cout << "win";
  }
  return 0;
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n,m,l,a[45],b[45],c[45],dp[45][410][410],ans =100000009;
  cin >> n >> m >> l;
  
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  
  for(int i = 0; i <= n; ++i){ 
    for(int j = 0; j <= 400; ++j){ 
      for(int k = 0; k <= 400; ++k){  
        dp[i][j][k]=100000009; 
      }  
    }  
  }
  
  
  dp[0][0][0] =0;
  
  
  for(int i=0;i<n;i++){
    for(int j=0;j<=400;j++){
      for(int k=0;k<=400;k++){
        if(dp[i][j][k] == 100000009){
          continue;
        }
        dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
      }
    }
  }
  
  for(int j=1;j<=400;j++){
    for(int k=1;k<=400;k++){
      
      if(k*m ==j*l){
        ans = min(dp[n][j][k],ans);
      }
    }
  }
  
  if(ans == 100000009){
    ans = -1;
  }
  
  cout << ans << endl;
}
  


Measured memory_bytes: 28928
#include<iostream>
#include<algorithm>
using namespace std;
struct ss
{
    int num;
    int gs;
}a[10001];
bool cmp(ss c,ss b)
{
    return c.gs>b.gs;
}
int main()
{
    int maze[100][100];
    int h,w,n,i,j;
    while(cin>>h>>w>>n){
    for(i=0;i<n;i++)
    {
        cin>>a[i].gs;
        a[i].num=i+1;
    }
    sort(a,a+n,cmp);
    int t=0,y=0;
    for(i=0;i<h;i++)
    {
        if(i%2==0){
        for(j=0;j<w;j++)
        {
            y++;
            if(y>a[t].gs)t=t+1,y=1;
            maze[i][j]=a[t].num;
        }}
        else
        {
            for(j=w-1;j>=0;j--)
           {
            y++;
            if(y>a[t].gs)t=t+1,y=1;
            maze[i][j]=a[t].num;
           }
        }
    }
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cout<<maze[i][j]<<" ";
        }
        cout<<endl;
    }
    }
    return 0;
}

Measured memory_bytes: 384
N = int(input())
S = []

for i in range(N):
    s, p = input().split()
    S.append((s, int(p), i + 1))

S.sort(key = lambda x: x[1], reverse = True)
S.sort(key = lambda x: x[0])

for i in range(N):
    print(S[i][2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int dp[1<<15][15],d[15][15],a,b,c,n,p,INF=1<<30;
int rec(int s,int v){
	if(dp[s][v]!=-1)return dp[s][v];
	if(s==(1<<n)-1&&v==0)return 0;
	int res=INF;
	for(int i=0;i<n;i++)if(!(s>>i&1)&&d[v][i]!=-1)res=min(res,rec(s|(1<<i),i)+d[v][i]);
	return dp[s][v]=res;
}
int main(){
	memset(dp,-1,sizeof(dp));
	memset(d,-1,sizeof(d));
	cin>>n>>p;
	for(int u=0;u<p;u++)cin>>a>>b>>c,d[a][b]=c;
	cout<<(INF==(a=rec(0,0))?-1:a)<<endl;
}

Measured memory_bytes: 5000
#!/usr/bin/env python3
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

init = [str(i) for i in range(10) if i not in D and i != 0]
use = [str(i) for i in range(10) if i not in D]
q = deque(init)
ans = []
while q:
    num = q.pop()
    if int(num) >= N:
        ans.append(num)
        continue
    for u in use:
        q.append(num + u)

print(min(list(map(int, ans))))

Measured memory_bytes: 9460
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N, A;
  cin >> N >> A;
  if(N % 500 <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } 
int main(){
  int a,b;
  cin >> a >> b;
  if(1 <= a && a <= 9){
    if(1 <= b && b <= 9){
      cout << a*b<<endl;
    }
    else{
      cout << -1 <<endl;
    }
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;

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

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  bool ans = std::any_of(va.begin(), va.end(), [](ll a) { return a % 2 == 1; });
  if (ans) {
    cout << "first" << '\n';
  } else {
    cout << "second" << '\n';
  }
}

Measured memory_bytes: 3984
#include<cstdio>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

 
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c&&a!=c){
		cout<<"Yes"<<endl;
	}
	else if(c==b&&b!=a&&c!=a){
		cout<<"Yes"<<endl;
	}
	else if(a==c&&a!=b&&c!=b){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;

void solve(){
    ll n;
    cin >> n;
    if(n == 1){
        cout << "0\n";
        return;
    }
    const ll M = 1e9 + 7;
    ll t10 = 1, t9 = 1, t8 = 1;
    for(int i = 0; i < n; ++i){
        t10 = (t10 * 10) % M;
        t9 = (t9 * 9) % M;
        t8 = (t8 * 8) % M;
    }
    ll ans = (t10 + t8 - t9 - t9 + M + M) % M;
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__);
#else
#define debug(...)
#endif
typedef double db;
typedef long long L;
typedef long double lf;
typedef unsigned int uint;
typedef unsigned long long uL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f,mo=998244353;
template<typename T>inline void admo(int&a,const T&b){a=(a+b>=mo?a+b-mo:a+b);}
template<typename T>inline void sumo(int&a,const T&b){a=(a-b<0?a-b+mo:a-b);}
template<typename T,typename S>inline bool upmx(T&a,const S&b){return a<b?a=b,1:0;}
template<typename T,typename S>inline bool upmn(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T>inline T gcd(T a,T b){while(b)a%=b,swap(a,b);return a;}
inline int Pow(int a,int b,int p=mo){int r=1;for(;b;b>>=1,a=1ll*a*a%p)if(b&1)r=1ll*r*a%p;return r;}
inline int rd(){
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=2e5+11,M=31;
int a[N],n,b[M],c[M];
int main(){
#ifdef flukehn
	freopen("g.in","r",stdin);
#endif
	n=rd();
	L ans=0;
	rep(i,1,n){
		a[i]=rd();
		int l=0;
		For(j,0,M)if(a[i]>>j&1){
			upmx(l,b[j]);
			c[j]=b[j];
			b[j]=i;
		}else{
			upmx(l,c[j]);
		}
		ans+=i-l;
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)

int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
int dxx[]={1,1,0,-1,-1,-1,0,1};
int dyy[]={0,-1,-1,-1,0,1,1,1};
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
const int INF= 1 <<30 ;
#define fin <<'\n'
int main(){
  cin.tie(0), ios::sync_with_stdio(false);

  int n,t,a,h,ans;
  double ner = INF;
  cin >>n>>t>>a;
  FOR(i,n){
    cin >>h;
    double c =abs((t- h*0.006)-a);
    if(c<ner){
      ner=c;
      ans=i+1;
    }
  }
    cout <<ans fin;
 

  return 0;
}


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

int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> vec(n, vector<int>(0));
  for (int i = 0; i < q; i++) {
    int a, t, x;
    cin >> a >> t;
    if (a == 0) {
      cin >> x;
      vec.at(t).push_back(x);
    }
    else if (a == 1) {
      if (vec.at(t).size() > 0) cout << vec.at(t).at(0) << endl;
    } else {
      if (vec.at(t).size() > 0) vec.at(t).erase(vec.at(t).begin());
    }
  }
}


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

int main(){
  int64_t n, k;
  cin >> n >> k;
  int64_t q;
  q = n / k;
  if((n-k*q) < abs(n-k*(q+1))){
    n = n-k*q;
  }
  else{
    n = abs(n-k*(q+1)); 
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    stack < char > st;
    int i , n;
    string s;
    cin >> s;
    n = s.size();
    for(i=0;i<n;i++)
    {
        if(st.empty())
        {
            st.push(s[i]);
        }
        else{
            if(s[i] == 'T')
            {
                if(st.top() == 'S')
                    st.pop();
                else st.push(s[i]);
            }
            else st.push(s[i]);
        }
    }
    cout << st.size() ;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

#define y1 y1_dsf

int x1, y1, x2, y2, x3, y3;

inline ld getd(int x1, int y1, int x2, int y2)
{
//     cout << (ld)(x1 - x2) * (x1 - x2) << ' ' <<  (ld)(y1 - y2) << ' ' <<  (y1 - y2) << endl;
    return sqrt((ld)(x1 - x2) * (x1 - x2) + (ld)(y1 - y2) * (y1 - y2));
}

int main()
{
    scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
    ld a = getd(x1, y1, x2, y2);
    ld b = getd(x2, y2, x3, y3);
    ld c = getd(x3, y3, x1, y1);
//     cout << a << ' ' << b << ' ' << c << endl;
    if (a < b) swap(a, b);
    if (a < c) swap(a, c);
    ld al = acos((a * a + c * c - b * b) / (2 * a * c));
    ld be = acos((a * a + b * b - c * c) / (2 * a * b));
//     cout << a << ' ' << b << ' ' << c << endl;
//     cout << al << ' ' << be << endl;
    ld x = a / (2 + 1 / tan(al / 2) + 1 / tan(be / 2));
    cout.precision(20);
    cout << x << endl;
    return 0;
}

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

using namespace std;

class CDice{
private:
	vector<int> surface;
public:
	CDice(){};
	CDice(vector<int> vc){SetSurface(vc);};
	~CDice(){};
	void SetSurface(vector<int> vc){surface = vc;};
	void TurnN();
	void TurnE();
	void TurnW();
	void TurnS();
	int GetTop(){return surface[0];};
};

void CDice::TurnN()
{
	vector<int> tmp = surface;
	tmp[0] = surface[1];
	tmp[1] = surface[5];
	tmp[2] = surface[2];
	tmp[3] = surface[3];
	tmp[4] = surface[0];
	tmp[5] = surface[4];
	surface = tmp;
}

void CDice::TurnE()
{
	vector<int> tmp = surface;
	tmp[0] = surface[3];
	tmp[1] = surface[1];
	tmp[2] = surface[0];
	tmp[3] = surface[5];
	tmp[4] = surface[4];
	tmp[5] = surface[2];
	surface = tmp;
}

void CDice::TurnW()
{
	vector<int> tmp = surface;
	tmp[0] = surface[2];
	tmp[1] = surface[1];
	tmp[2] = surface[5];
	tmp[3] = surface[0];
	tmp[4] = surface[4];
	tmp[5] = surface[3];
	surface = tmp;
}

void CDice::TurnS()
{
	vector<int> tmp = surface;
	tmp[0] = surface[4];
	tmp[1] = surface[0];
	tmp[2] = surface[2];
	tmp[3] = surface[3];
	tmp[4] = surface[5];
	tmp[5] = surface[1];
	surface = tmp;
}

int main()
{
	vector<int> in(6);
	for (int i = 0; i < 6; i++)
		cin >> in[i];

	CDice dice(in);
	string order;
	cin >> order;

	for (int i = 0; i < order.length(); i++){
		char c = order[i];
		switch(c){
			case 'N': dice.TurnN(); break;
			case 'E': dice.TurnE(); break;
			case 'W': dice.TurnW(); break;
			case 'S': dice.TurnS(); break;
		}
	}

	cout << dice.GetTop() << endl;

	return 0;
}



Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<ctime>
using namespace std;

int n,a,b;
vector<vector<int>>path(100001);
long long dp[100001][2]={};

long long mod(const long long& a){
	return a%1000000007;
}
int dfs(int num,int bw){//w0,b1
	if(dp[num][bw]!=0)
		return dp[num][bw];
	dp[num][0]=dp[num][1]=1;
	if(!path[num].size())
		return (long long)1;
	for(int i=0;i<path[num].size();i++)
	{
		for(int j=0;j<path[path[num][i]].size();j++){
			if(path[path[num][i]][j]==num){
				path[path[num][i]].erase(path[path[num][i]].begin()+j);
				break;
			}
		}
		dp[num][0]=mod(dp[num][0]*=mod(dfs(path[num][i],0)+dfs(path[num][i],1)));
		dp[num][1]=mod(dp[num][1]*=dfs(path[num][i],0));
	}
	return dp[num][bw];
}



int main(){
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		cin>>a>>b;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	cout<<mod(dfs(1,0)+dfs(1,1))<<endl;
	
}

Measured memory_bytes: 14208
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    boolean[] one=new boolean[n];
    boolean[] enu=new boolean[n];
    for(int i=0;i<m;i++){
      int from=sc.nextInt()-1;
      int to=sc.nextInt()-1;
      if(from==0){
        one[to]=true;
      }else if(to==n-1){
        enu[from]=true;
      }
    }
    for(int i=0;i<n;i++){
      if(one[i]&&enu[i]){
        System.out.println("POSSIBLE");
        return;
      }
    }
    System.out.println("IMPOSSIBLE");
  }
}

Measured memory_bytes: 93720
N = gets.to_i

digit = N.to_s.length

count = 0

digit.times.each do |num|
  num += 1
  if num.odd?
    num_start = 10 ** (num - 1)
    num_end = 10 ** num - 1
    num_end = N < num_end ? N : num_end
    
    count += num_end - num_start + 1
  end
end

puts count

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

int main() {

    int h, w;

    for ( ;; ) {

        std::cin >> h >> w;

        if ( h == 0 && w == 0 ) break;

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

            for ( int j = 0; j < w; j++ ) {
                ( i + j ) % 2 == 0
                    ? std::cout << "#"
                    : std::cout << "." ;
            }
            std::cout << std::endl;
        }

        std::cout << std::endl;
    }


    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define endl '\n'
#define ll unsigned long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    ll years = 0;
    ll tmp = 100;
    cin>>x;
    while(1)
    {
        if(x <= tmp)
        {
            cout<<years<<endl;
            break;
        }
        else
        {
            tmp+=(tmp/100);
            years++;
        }
    }
    return 0;
}
/**
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
ll main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)solve();
    return 0;
}
*/


Measured memory_bytes: 3652
N = int(input())
H = list(map(int, input().split()))
cnt = 0
while any(H):
  st = False
  for i, v in enumerate(H):
#    print(H, cnt)
#    print(v)
    if v > 0:
      st = True
      H[i] -= 1
#      print(H)
    else:
      if st == True:
        cnt += 1
        st = False
        break
  if st == True:
    cnt += 1
    st = False
print(cnt)
    
      

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

int n;
int ans;
int a[105],b[105],c[105];

int main()
{
	cin >> n;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n;i++) cin >> b[i];
	for(int i=1;i<n;i++) cin >> c[i];
	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(a[i]==a[i-1]+1) ans+=c[a[i-1]];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.ThreadLocalRandom;
public class Main 
{
	
	static long gcd(long a, long b) 
	{
		if (b == 0)
		{	
			return a;
		}
		
		else
		{
			 return gcd(b, a % b);
		}
	}
	public static void main(String[] args) throws Exception
	{

		
		   PrintWriter out = new PrintWriter(System.out);
		   Scanner in = new Scanner(System.in);
		 // long n , k , q;
		  
	int x = in.nextInt();
	int y = in.nextInt();
	int xx = in.nextInt();
	int yy= in.nextInt();
	if( x  > xx  ) for(int i = 0; i < Math.abs(xx  - x);i++)out.print("L");
	else for(int i = 0; i < Math.abs(xx  - x);i++)out.print("R");
	if( y  > yy  ) for(int i = 0; i < Math.abs(yy  - y);i++)out.print("D");
	else for(int i = 0; i < Math.abs(yy  - y);i++)out.print("U");
	if( x  < xx  ) for(int i = 0; i < Math.abs(xx  - x);i++)out.print("L");
	else for(int i = 0; i < Math.abs(xx  - x);i++)out.print("R");
	if( y  < yy  ) for(int i = 0; i < Math.abs(yy  - y);i++)out.print("D");
	else for(int i = 0; i < Math.abs(yy  - y);i++)out.print("U");
	if( x  < xx  ) out.print("L");
	else out.print("R");
	if( y  > yy  ) for(int i = 0; i < Math.abs(yy  - y) + 1;i++)out.print("D");
	else for(int i = 0; i < Math.abs(yy  - y ) + 1;i++)out.print("U");
	if( x  > xx  ) for(int i = 0; i < Math.abs(xx  - x ) + 1;i++)out.print("L");
	else for(int i = 0; i < Math.abs(xx  - x ) + 1;i++)out.print("R");
	if( y  > yy  ) out.print("U");
	else out.print("D");
	
	if( x  < xx  ) out.print("R");
	else out.print("L");
	if( y  > yy  ) for(int i = 0; i < Math.abs(yy  - y) + 1;i++)out.print("U");
	else for(int i = 0; i < Math.abs(yy  - y ) + 1;i++)out.print("D");
	if( x  > xx  ) for(int i = 0; i < Math.abs(xx  - x ) + 1;i++)out.print("R");
	else for(int i = 0; i < Math.abs(xx  - x ) + 1;i++)out.print("L");
	if( y  > yy  ) out.print("D");
	else out.print("U");
	   out.close();
	}
}

Measured memory_bytes: 10192
n=int(input())
R =[int(input()) for i in range(n)]
r=R[0]
maxV=-float('inf')
for i in range(n-1):
	if R[i]<r:
		r=R[i]
	if maxV<R[i+1]-r:
		maxV=R[i+1]-r
print(maxV)






Measured memory_bytes: 13616
#include <iostream>
#include <cmath>

using namespace std;

void solve(){
    int x;
    int h, m, s;
    cin >> x;
    h = x/3600;
    m = (x-h*3600)/60;
    s = x-(h*3600)-(m*60);
    cout << h << ":" << m << ":" << s << endl;
}

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

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxx = 100000;


int main() {
    ll a;
    cin >> a;
    cout << a * (a - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;


int main()
{
	double x,a,b;
	while(cin>>x>>a>>b)
	{
		int aa=fabs(x-a);
		int bb=fabs(x-b);
		if(aa>bb)cout<<"B"<<endl;
		else cout<<"A"<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n, m, k, x, y, _2k;
char col[] = "RGBY";
char mp[505][505];

int main() {
	scanf("%d%d%d", &n, &m, &k), _2k = k * 2;
	for(register int i = 1; i <= n; ++i)
		for(register int j = 1; j <= m; ++j) {
			x = n + i + j, y = m + i - j;
			mp[i][j] = col[2 * ((x / k) & 1) + ((y / k) & 1)];
		}
	for(register int i = 1; i <= n; ++i) {
		for(register int j = 1; j <= m; ++j)
			putchar(mp[i][j]);
		putchar('\n');
	}
	return 0;
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 51
#define MAXN 1000000000
using namespace std;
inline int read()
{
	int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),m=read(),a[INF],b[INF],c[INF],d[INF];
    for(int i=1;i<=n;i++)
    {
    	a[i]=read();
		b[i]=read();
	}
    for(int i=1;i<=m;i++)
    {
        c[i]=read();
        d[i]=read();
    }
    for(int i=1;i<=n;i++)
    {
        int minn=MAXN,k;
        for(int j=1;j<=m;j++)
            if(abs(a[i]-c[j])+abs(b[i]-d[j])<minn)
			{
                minn=abs(a[i]-c[j])+abs(b[i]-d[j]);
                k=j;
            }
        write(k);
    	putchar('\n');   
    }
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd =1e5+10;
int a[maxd];
long long gcd(long long x,long long y)
{
    if(!y) return x;
    return gcd(y,x%y);
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    long long a,b,c,d;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    long long g = gcd(c,d);
    long long ac = (a-1)/c , ad = (a-1)/d;
    long long ak = ac+ad - (a-1)/(c*d/g);
    long long bc = b/c, bd = b/d;
    long long bk = bc+bd - ((b) / (c*d/g));
    //printf("%lld %lld\n",ak,bk); 
    printf("%lld\n",b-a+1 - (bk-ak));
    return 0;
}  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

long long M;

int main() {
  cin >> M;
  long long sum = 0;
  long long count = 0;
  long long num = 0;
  rep(i, M) {
    long long d, c;
    cin >> d >> c;
    sum = (sum + d * c);
    // count += sum / 9;
    // sum %= 9;
    num += c;
  }
  long long ans = (sum - 1) / 9;
  ans += num - 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
	int a,b,t,i,ans=0;
	scanf("%d %d %d",&a,&b,&t);
	double time=t+0.5;
	
	for(i=1;i<=time;i++){
		if(i%a==0){
			ans += b;
		}
	}
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


int dp[110][4][2];

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

	string S;
	int N, K;
	cin >> S >> K;
	N = S.size();

	dp[0][0][0] = 1;

	REP(i, N) {
		REP(j, 4) {
			REP(k, 2) {

				int nd = S[i] - '0';
				REP(d, 10) {
					int ni = i + 1, nj = j, nk = k;

					if (d != 0)nj++;
					if (nj > K)continue;
					if (k == 0) {
						if (d > nd)continue;
						if (d < nd)nk = 1;
					}

					dp[ni][nj][nk] += dp[i][j][k];
				}

			}
		}
	}
	
	cout << dp[N][K][0] + dp[N][K][1] << endl;



	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;

  int a, b;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
LL mod = 1e9 + 7;
LL f[200005];
LL qpow(LL x, LL n)
{
    LL res = 1, p = x;
    while(n)
    {
        if(n & 1)
            res = res*p%mod;
        p = p*p%mod;
        n >>= 1;
    }
    return res;
}

LL C(LL x, LL y)
{
    LL a = f[x], b = f[y]*f[x-y]%mod;
    return a*qpow(b, mod - 2)%mod;
}
int main()
{
    f[0] = 1;
    for(int i = 1; i < 2e5+5; i++)
        f[i] = f[i-1]*i%mod;
    LL h, w, a, b;
    while(~scanf("%lld%lld%lld%lld", &h, &w, &a, &b))
    {
        LL ans = 0;
        for(LL i = b + 1; i <= w; i++)
        {
            ans = (ans + C(i + h - a - 2, h - a - 1)*C(w + a - i - 1, w - i)%mod)%mod;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 1792
from collections import deque

WHITE = 0
GRAY = 1
BLACK = 2

n = int(input())

M = [[0] * n for i in range(n)]

d = [-1] * (n)
color = [WHITE] * (n)


time = 0

def dfs_visit(u):
    global time
    time += 1
    color[u] = GRAY
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    time += 1

def bfs(s):
    queue = deque([])
    queue.append(s)
    d[s] = 0
    while len(queue) > 0:
        u = queue.popleft()
        for v in range(n):
            if M[u][v] == 0:
                continue
            if d[v] != -1:
                continue
            d[v] = d[u] + 1
            queue.append(v)

    for i in range(n):
        print("%d %d" % (i+1, d[i]))


if __name__ == "__main__":
    for i in range(n):
        arr = list(map(int, input().split()))
        for v in (arr[2:]):
            M[arr[0]-1][v-1] = 1

    bfs(0)



Measured memory_bytes: 6084
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const int MAX_N = 300000;
bool is_prime[MAX_N + 1];
vector<int> primes;

// O(n log log n) time
void sieve(int n = MAX_N + 1) {
    fill(is_prime + 2, is_prime + n, true);
    for (int i = 2; i < n; i++) {
        if (!is_prime[i] || (i % 7 != 1 && i % 7 != 6)) continue;
        primes.push_back(i);
        for (long long j = 2 * i; j < n; j += i) {
            is_prime[j] = false;
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    sieve();
    int n;
    while (cin >> n, n != 1) {
        vector<int> ans;
        for (int p : primes) {
            if (n % p == 0) ans.push_back(p);
        }
        cout << n << ":";
        for (int v : ans) cout << " " << v;
        cout << endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+100;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll t,n,m,a[maxn];
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    ll res=0;
    for(int i=0;i<t;i++){
        cin>>a[i];
    } 
    sort(a,a+t,greater<int>());
    res=a[0];
    for(int i=1;i<=t/2-1;i++) res+=a[i]*2;
    if(t&1) res+=a[t/2];
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    string a ; cin >> a;
    if (a == "ABC") cout << "ARC" << endl;
    else if (a == "ARC") cout << "ABC" << endl;
    return 0;
}


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

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

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeMaximum(Node x){
 while(x->right!=NIL)x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

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

  if(z->left==NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL){
    x=y->left;
  }
  else x=y->right;

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

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

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

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

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

Node find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

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

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

  return 0;
}



Measured memory_bytes: 20484
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::vector<int> ac(n+1,0); // all
	std::vector<int> bc(n+1,0); // plus only
	rep(i,n) ac[i+1] = ac[i] + a[i];
	rep(i,n) bc[i+1] = bc[i] + std::max(0ll,a[i]);
	debug(ac,bc);
	int max = 0;
	for(int l=0;l+k<=n;l++) {
		int r = l+k;
		int sum = bc[n]-bc[r] + bc[l]; // white
		max = std::max(max, sum);
		sum += ac[r] - ac[l]; // black
		max = std::max(max, sum);
	}
	print(max);

	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	cout << "Christmas" << ' ';
	for (int i = 0; i < 25 - n; i++)
		cout << "Eve" << ' ';
}

Measured memory_bytes: 256
from collections import deque

s, t = input(), input()
n, m = len(s), len(t)

# dp[i][j] = s[:i], t[:j]の共通部分列の長さ
dp = [[0] * (m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

ans = deque()
i, j = n, m
while i and j:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans.appendleft(s[i])

print("".join(ans))


Measured memory_bytes: 113244
//                 SILENT KILLER
#include<bits/stdc++.h>
//typedef long long ll;
using namespace std;
int main() {

	int n;
	cin>>n;
 map<string,int>m;
	while(n--)
	{
		string s;
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;


}



Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,p[50]={},cnt=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> p[i];
  }
  for(int i=0; i<n; i++) {
    if(p[i]==i+1) {
      cnt++;
    }
  }
  if(cnt>=n-2) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

l=[]
for i in range(n):
  a,b=map(str, input().split())
  b=100-int(b)
  if b<10:
    b=str('0')+str(b)
  elif b==100:
    b="999"
  else:
    b=str(b)
  a=a+b
  l.append(a)

l2=sorted(l)

for i in range(n):
  print(l.index(l2[i])+1)

Measured memory_bytes: 9092
// ABC137E.cpp

#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using ll = long long;
#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
using namespace std;

vector<int> to[2510];
vector<int> rto[2510];
bool gFrom1[2510];
bool gToN[2510];
bool ok[2510];

const int INF = 1001001001;

void dfs(int v) { // v:startから到達できる頂点をtrueにする
    if (gFrom1[v]) return;
    gFrom1[v] = true;
    for (int u : to[v]) {
        dfs(u);
    }
}

void rdfs(int v) { // v;goalに到達できる頂点をtrueにする
    if (gToN[v]) return;
    gToN[v] = true;
    for (int u : rto[v]) {
        rdfs(u);
    }
}

int main()
{
    int n, m,p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0); // startから到達できる頂点
    rdfs(n - 1); // goalに到達できる頂点
    rep(i, n) {
        ok[i] = gFrom1[i] & gToN[i];
    }
    // bellman-ford
    vector<int> d(n, INF);
    d[0] = 0;
    bool upd = true;
    int step = 0;
    while (upd) {
        upd = false;
        rep(i, m) {
            int a, b, c;
            tie(a, b, c) = edges[i];
            if (!ok[a]) continue;
            if (!ok[b]) continue;
            int nD = d[a] + c;
            if (nD < d[b]) {
                upd = true;
                d[b] = nD;
            }
        }
        step++;
        if (step > n) {
            cout << "-1" << endl;
            return 0;
        }
    }
    int ans = -d[n - 1];
    ans = max(ans, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  pair<int, pair<int, int>>
#define pll   pair<ll, ll>

#define F  first
#define S  second
#define PB push_back
#define MP make_pair

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename T>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

// add templates here

template<class T>
void println(const vector<T> &data) {
    cout << to_string<vector<T>, T>(data) <<endl;
}

template<class T>
void println(const T &data) {
    cout << to_string((T)data) << endl;
}

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);
    
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int A, B;
    cin >> A >> B;
    
    if(abs(A-B) & 1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    
    int ans = abs(A+B)/2;
    
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int i;
  string s,w[3]={"Sunny","Cloudy","Rainy"};
  cin >> s;
  for (i=0;i<3;i++) if (s==w[i]) break;
  cout << w[(i+1)%3] << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     int n,k;
     cin>>n>>k;
     int A[n];
     for(int i=0;i<n;++i)
     {
     	cin>>A[i];
	 }
	 sort(A,A+n);
	 int ans=0;
	 for(int i=0;i<k;++i)
	 {
	 	ans+=A[i];
	 }
	 cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640