akhauriyash/Code-Regression huggingface dataset:
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(ALL(a));
    cout << a[0] + a[1] << endl;
    return 0;
}

Measured memory_bytes: 888
N = str(input())
 
if(N[-1]=="3"):
    print("bon")
    
if(N[-1]=="0" or N[-1]=="1" or N[-1]=="6" or N[-1]=="8"):
    print("pon")
    
if(N[-1]=="2" or N[-1]=="4" or N[-1]=="5" or N[-1]=="7" or N[-1]=="9"):
    print("hon")


Measured memory_bytes: 9148
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vvi s(D, vi(26));
    rep(i, D) rep(j, 26) {
        cin >> s[i][j];
    }

    vi t(D);
    vi last(26);
    rep(d, D) {
        int ma = INT_MIN, nn = 23;
        rep(i, 26) {
            int ggh = 0;
            ggh += s[d][i];
            rep(j, 26) {
                if(i == j) continue;
                ggh -= c[j]*(d+1-last[j]);
            }
            if(chmax(ma, ggh)) {
                nn = i;
            }
        }
        last[nn] = d+1;
        t[d] = nn;
    }
    last.assign(26, 0);
    vector<set<int> > se(26);
    rep(i, 26) {
        se[i].insert(D);
    }
    ll gh = 0;
    rep(d, D) {
        se[t[d]].insert(d);
        gh += s[d][t[d]];
        last[t[d]] = d+1;
        rep(j, 26) {
            gh -= c[j]*(d+1-last[j]);
        }
    }

    vvi bits(26, vi(D+1));
    auto add = [&](int al, int d, int x) {
        while(d <= D) {
            bits[al][d] += x;
            d += d&-d;
        }
    };
    auto sum = [&](int al, int d) {
        if(d == 0) return 0;
        int res = 0;
        while(d) {
            res += bits[al][d];
            d &= d-1;
        }
        return res;
    };


    rep(i, D) {
        rep(j, 26) {
            add(j, i+1, 1);
        }
    }

    rep(i, D) {
        int now = sum(t[i], i+1);
        add(t[i], i+1, -now);
    }

    int X = 100000;
    while(X--) {
        int nowd = X%D;
        int nowal = X%26;
        if(t[nowd] == nowal) continue;
        ll nowgh = gh;
        nowgh += s[nowd][nowal]-s[nowd][t[nowd]];
        auto itr = se[nowal].lower_bound(nowd);
        nowgh += (*itr - nowd)*sum(nowal, nowd+1) * c[nowd];
        itr = se[t[nowd]].upper_bound(nowd);
        nowgh -= (*itr-nowd)*(sum(t[nowd], nowd)+1) * c[t[nowd]];
        if(nowgh > gh) {
            add(t[nowd], nowd+1, sum(t[nowd], nowd)+1);
            add(nowal, nowd+1, -sum(nowal, nowd+1));
            se[t[nowd]].erase(nowd);
            se[nowal].insert(nowd);
            t[nowd] = nowal;
            gh = nowgh;
        }
    }

    rep(i, D) {
        cout << t[i]+1 << endl;
    }
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    cin >> s;
    string ans = "";
    REP(i, size(s)) ans += 'x';
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int s,w; cin>>s>>w;
    if(w>=s) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define debug(x) cout << #x << " : " << (x) << " --------------" << endl;
using namespace std;
struct Point {
    int l;
    int h;
};
bool operator < (const Point& lhs, const Point& rhs) {
    return tie(lhs.l, lhs.h) < tie(rhs.l, rhs.h);
}
int main(void){
    int n, m, a;
    while (cin >> n >> m >> a && n && m && a) {
        int H = 0;
        map<Point, int> intersection;
        REP(i, m) {
            int h, p, q;
            cin >> h >> p >> q;
            intersection[{p, h}] = q;
            intersection[{q, h}] = p;
            H = max(H, h);
        }
        int l = a;
        while (H > 0) {
            if (intersection.find({l, H}) != intersection.end()) {
                l = intersection[{l, H}];
            }
            --H;
        }
        cout << l << endl;
    }
    return EXIT_SUCCESS;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m,r;
	
	cin >>n >>m >>r;
	VI z(r);
	rep(i,r){ cin >>z[i]; z[i]--;}
	
	vector<VI> a(n, VI(n, mod));
	rep(i,n) a[i][i] =0;
	rep(i,m){
		int f,t,c;
		cin >>f >>t >>c;
		a[f-1][t-1] = a[t-1][f-1] = c;
	}
	rep(k,n) rep(i,n) rep(j,n) a[i][j] =min(a[i][j], a[i][k] + a[k][j]);

	ll INF = 1LL<<50, ans =INF;

	vector<vector<ll>> dp(1<<r, vector<ll>(r, INF));
	rep(i,r) dp[1<<i][i] = 0;
	
	rep(i, 1<<r) rep(j, r) rep(k, r){

		dp[i | 1<<k][k] = min(dp[i | 1<<k][k], dp[i][j] + a[z[j]][z[k]]);
	
	}
	
	rep(i,r) ans = min(ans, dp[(1<<r)-1][i]);
	cout << ans <<"\n";
	return 0;
}


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

const int INF = 1001001001;

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> dp(h+1, INF);
    dp[0] = 0;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        rep(j, h) {
            int nj = min(j+a, h);
            dp[nj] = min(dp[nj], dp[j]+b);
            // printf("dp[%d] = %d\n", nj, dp[nj]);
        }
    }
    cout << dp[h] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);

        while(true){

            int H = scan.nextInt();
            int M = scan.nextInt();
            int i,j;

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

            for(j=0;j<H;j++){
                for(i=0;i<M;i++){
                    if((i+j)%2==0){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }

            System.out.println();
            
        }
    }
}


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

int main() {
    int h,n; cin >> h >> n;
    ll total = 0;
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        total += a;
    }
    if(total < h){
        cout << "No" << endl;
    } else{
        cout << "Yes" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long K, long long S) {
  ll ans = 0;

  REP(x, K + 1) REP(y, K + 1) {
    int z = S - (x + y);
    if (z < 0 || z > K)
      continue;
    ans++;
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long K;
  long long S;
  cin >> K;
  cin >> S;
  solve(K, S);
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
long long INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int vp[2*300*300+1],vl[300*300+1],answer[100000];
int h,w,d,q,d2;

int inline dist(int i2){
    return abs(vp[i2]-vp[i2-d2]) + abs(vp[i2+1]-vp[i2-d2+1]);
}

int main(){
    scanf("%d %d %d",&h,&w,&d);
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            int a;
            scanf("%d",&a);
            vp[2*a] = i;
            vp[2*a+1] = j;
        }
    }

    scanf("%d",&q);
    d2 = 2*d;
    FOR(i,1,d+1) vl[i] = 0;
    FOR(i,d+1,h*w+1) vl[i] = vl[i-d] + dist(2*i);

    REP(i,q){
        int l,r;
        scanf("%d %d",&l,&r);
        answer[i] = vl[r] - vl[l];
    }
    REP(i,q) printf("%d\n",answer[i]);
    return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
	int [] dx = {0,1,0,-1};
	int [] dy = {1,0,-1,0};
	
	private void doit(){
		
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			String s = sc.next();
			int pos = 0;
			
			while(true){
				if(s.length() == pos){
					System.out.println("YES");
					break;
				}
				if(s.startsWith("dream", pos)){
					if(s.startsWith("dreamer", pos)){
						if(s.startsWith("dreamera", pos)){
							pos += 5;
						}
						else{
							pos += 7;
						}
					}
					else{
						pos += 5;
					}
				}
				else if(s.startsWith("erase", pos)){
					if(s.startsWith("eraser",pos)){
						pos += 6;
					}
					else{
						pos += 5;
					}
				}
				else{
					System.out.println("NO");
					break;
				}
			}
			
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 13964
/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

#include<bits/stdc++.h>
using namespace std;
#define ll long long int



ll N,X,T;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
  cin>>N>>X>>T;

  if(N%X == 0){
    cout<<(N/X)*T<<'\n';
  }

  else
    cout<<(N/X + 1)*T<<'\n';


}



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

  return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
	int x,y,i=0,j;
	int X[3000],Y[3000];
	do{
		i++;
	scanf("%d %d",&x,&y);
	if(x<=y){
		X[i-1]=x;
		Y[i-1]=y;
	}else if(x>y){
		X[i-1]=y;
		Y[i-1]=x;
	}
	}while(x!=0||y!=0);
	for(j=0;j<i-1;j++){
		printf("%d %d\n",X[j],Y[j]);
	}
	return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2e18;
const ll Log = 30;

ll a, b, c, d;
map<ll, ll> mp, mp2;

ll Solve(ll x);

ll Solve2(ll x){
	if(x == 0) return 0;
	if(x == 1) return d;
	if(mp2.count(x)) return mp2[x];
	ll res = (Inf/d + 2 < x ? Inf : x*d);
	if(x % 2 == 0) res = min(res, Solve(x/2) + a);
	if(x % 3 == 0) res = min(res, Solve(x/3) + b);
	if(x % 5 == 0) res = min(res, Solve(x/5) + c);
	mp2[x] = res;
	return res;
}
ll Solve(ll x){
	//cerr << x << '\n';
	if(x == 0) return 0;
	if(x == 1) return d;
	if(mp.count(x)) return mp[x];
	ll res = (Inf/d + 2 < x ? Inf : x*d);
	if(res < 0){
		debug(d); debug(x);
		assert(false);
	}
	for(int i = 1; i <= min(x, 4ll); i++){
		res = min(res, Solve2(x - i) + i*d);
	}
	res = min(res,  Solve2(x + 1) + d);
	if((x + 2)%5 == 0) res = min(res, Solve((x + 2) / 5) + d + d + c);
	if(x % 2 == 0) res = min(res, Solve(x/2) + a);
	if(x % 3 == 0) res = min(res, Solve(x/3) + b);
	if(x % 5 == 0) res = min(res, Solve(x/5) + c);
	mp[x] = res;
	return res;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll T;
	cin >> T;
	ll n;
	while(T--){
		mp.clear();
		mp2.clear();
		cin >> n >> a >> b >> c >> d;
		cout << Solve(n) << '\n';
		//debug(Solve2(10));
	}
	return 0;
}



Measured memory_bytes: 9052
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut monster: Vec<u64> = (0..n+1).map(|_| read()).collect();
    let power: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut ans : u64 = 0;

    for (i, &p) in power.iter().enumerate() {
        if p <= monster[i] {
            ans += p;
        } else if p > monster[i] {
            ans += monster[i];
            let rp = p - monster[i];
            if rp <= monster[i+1] {
                ans += rp;
                monster[i+1] -= rp;
            } else if rp > monster[i+1] {
                ans += monster[i+1];
                monster[i+1] = 0;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
e = Hash.new(){|h,k| h[k] = Hash.new}
(n-1).times do
  a,b,c = gets.chomp.split.map(&:to_i)
  e[a][b] = c
  e[b][a] = c
end

q,k = gets.chomp.split.map(&:to_i)
lens = Array.new(n+1)
queue = [[k, 0]]
visited = Set.new([k])
lens[k] = 0
until queue.empty?
  node, len = queue.pop
  e[node].each do |nnode, nlen|
    next if visited.include? nnode
    visited.add nnode
    lens[nnode] = len + nlen
    queue.push [nnode, len + nlen]
  end
end

q.times do
  x,y = gets.chomp.split.map(&:to_i)
  puts lens[x] + lens[y]
end

Measured memory_bytes: 58248
#include <bits/stdc++.h>
using namespace std;
int n,a[200002];
int vis[200002];
long long k;
int f(int i, int cnt)
{
  	if(cnt==k)return i;
	if(vis[i]!=-1)
	{
		k-=vis[i];
		k%=(1LL*cnt-vis[i]);
		int ans = i;
		for(int j=0;j<k;j++)ans=a[ans];
		return ans;
	}
	vis[i] = cnt;
	return f(a[i],cnt+1);
}
int main()
{
	memset(vis,-1,sizeof(vis));
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	cout<<f(1,0);
}

Measured memory_bytes: 5212
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        s: String, t: String,
        mut a: usize, mut b: usize,
        u: String
    };

    if u == s {
        a -= 1;
    } else {
        b -= 1;
    }
    println!("{} {}", a, b);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int N; cin >> N;
    int p[N];
    REP(i, N) cin >> p[i];

    int maxp = 0;
    int maxpindex = 0;
    REP(i, N) {
        if (maxp < p[i]) {
            maxp = max(maxp, p[i]);
            maxpindex = i;
        }
    }
    int ans = 0;
    REP(i, N) {
        if (i == maxpindex) {
            ans += p[i] / 2;
        } else {
            ans += p[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define min(q,w) ((q)>(w)?(w):(q))
#define max(q,w) ((q)<(w)?(w):(q))
using namespace std;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int a[N];
bool z[N];
int B[2*N][2],A[N],B0;
void link(int q,int w)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q;
}
int main()
{
	int q,w,e;
	read(n);
	char ch=' ';
	for(;ch!='R'&&ch!='B';ch=getchar());
	fo(i,1,n)
	{
		if(ch=='R')++q;
		ch=getchar();
	}
	if(2*q>n)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(str, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a = IR(2)
    n %= 500
    if a >= n:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    _ = II()
    a = LI()
    a.sort(reverse=True)
    op = 0
    ans = 0
    for ai in a:
        ans += -ai * op or ai
        op ^= 1
    print(ans)
    return

#C
def C():
    c = LIR(3)
    for x in range(c[0][0] + 1):
        b = (c[0][0] - x, c[0][1] - x, c[0][2] - x)
        if (c[1][0] - b[0]) == (c[1][1] - b[1]) == (c[1][2] - b[2]):
            if (c[2][0] - b[0]) == (c[2][1] - b[1]) == (c[2][2] - b[2]):
                print("Yes")
                return
    print("No")
    return
#D
def D():
    move = [[0, 1], [0, -1], [-1, 0], [1, 0]]
    h, w = LI()
    s = SR(h)
    q = deque([(0, 0, 1)])
    ans = h * w
    for y in range(h):
        for x in range(w):
            if s[y][x] == "#":
                ans -= 1
    check = [[True] * w for _ in range(h)]
    while q:
        x, y, tern = q.pop()
        for mx, my in move:
            mx += x
            my += y
            if 0 <= mx < w and 0 <= my < h:
                if s[my][mx] == "." and check[my][mx]:
                    check[my][mx] = False
                    if my == h - 1 and mx == w - 1:
                        print(ans - tern - 1)
                        return
                    q.appendleft((mx, my, tern + 1))
    print(-1)


    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 42224
def changing_a_character(N: int, K: int, S: str)->str:
    return ''.join(c.lower() if i == K-1 else c for i, c in enumerate(S))


if __name__ == "__main__":
    N, K = map(int, input().split())
    S = input()

    ans = changing_a_character(N, K, S)
    print(ans)


Measured memory_bytes: 3316
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int a;	cin >> a;
	int ans = a + (a*a) + (a*a*a);
	cout << ans << endl;
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	return 0;
}


Measured memory_bytes: 3608
#include <iostream> 

using namespace std;

int main(int argc, char *argv[]) {
	int A, B;
	cin >> A >> B;

	if (A == 1) A = 14;
	if (B == 1) B = 14;
	if (A < B) printf("Bob\n");
	else if (A > B) printf("Alice\n");
	else printf("Draw\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int res = 0;
    rep(i, a+1)rep(j, b+1)rep(k, c+1){
        if(500*(i)+100*(j)+50*(k) == x)res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

//main
int main(){
  string S; cin >> S;
  int count;
  int maximum=0;
  rep(i,S.size()){
    count=0;
    for(int j=i; j<S.size(); j++){
      if(S[j]=='A'||S[j]=='T'||S[j]=='C'||S[j]=='G') count += 1;
      else break;
    }
    maximum = max(maximum,count);
  }
  cout << maximum << endl;  
}




Measured memory_bytes: 384
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n, k = intin()
    print(n - k + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3672
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>     
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define rev(i,n) for(ll i=n-1;i>=0;--i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define all(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x,y)* mod_pow(kai(y,y), mod - 2, mod) % mod;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};
//cout << fixed << setprecision(10) << num << endl;

signed main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	loop(i, k + 1, n + 1) {
		ans += (n / i) * (i - k);
		if (n % i >= k)ans += (n % i) - k + 1;
		if (k == 0)ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int r = 0;
	int g = 0;
	int b = 0;
	int n = 0;
	int c = 0;

	scanf("%d", &r);
	scanf("%d", &g);
	scanf("%d", &b);
	scanf("%d", &n);

	for (int i = 0; i <= n / r; i++)
	{
		for (int j = 0; j <= (n - i * r) / g; j++)
		{
			if((n-i*r-j*g)%b==0)
				{c++;  }	
			
		}
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
const int MOD = 1e9+7;
//struct area
struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//function area

//main area
int main(){
    int n, m;
    cin >> n >> m;
    UnionFind tree(n);
    rep(i,m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        tree.unite(x, y);
    }
    vector<int> count(n, 0);
    rep(i,n){
        int k = tree.root(i);
        count[k]++;
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans, count[i]);
    }
    cout << ans << endl;
}
/*



*/

Measured memory_bytes: 11016
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

ll calc_num_of_combination(ll n, ll r){
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

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

  map<string, int> mp;
  int n;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    sort(ALL(s));
    mp[s]++;
  }

  ll ans = 0;
  for (auto& p : mp) {
    if (p.second <= 1) continue;
    ans += calc_num_of_combination(p.second, 2);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11264
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = a < 0 ? -1 : 1, y = 0, a < 0 ? -a : a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///

int n;
set<int> g[2000];
int a[2000];

int used[2000];
int finished[2000];

vector<int> mrg(vector<vector<int>> vals) {
  int m = vals.size();
  priority_queue<pair<int, int>> pq;
  for(int i = 0; i < m; i++) {
    reverse(begin(vals[i]), end(vals[i]));
    if(vals[i].size()) pq.emplace(vals[i].back(), i);
  }

  vector<int> res;
  while(pq.size()) {
    int x, i;
    tie(x, i) = pq.top();
    pq.pop();
    res.emplace_back(x);
    vals[i].pop_back();
    if(vals[i].size()) pq.emplace(vals[i].back(), i);
  }
  return res;
}

vector<int> dfs(int i) {
  used[i] = 1;
  vector<vector<int>> vals;
  for(int j : g[i]) if(!used[j]) {
    vector<int> v = dfs(j);
    vals.push_back(v);
  }
  auto p = mrg(vals);
  p.insert(p.begin(), a[i]);
  return p;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for(int i = 0; i < n; i++) for(int j = 0; j < i; j++) {
    int x = gcd(a[i], a[j]);
    if(x != 1) {
      g[i].emplace(j);
      g[j].emplace(i);
    }
  }
  vector<vector<int>> vals;
  for(int i = 0; i < n; i++) if(!used[i]) {
    vector<int> v = dfs(i);
    vals.push_back(v);
  }
  auto ans = mrg(vals);
  for(int i = 0; i < n; i++) cout << ans[i] << " \n"[i == n - 1];
  cout << flush;
  return 0;
}


Measured memory_bytes: 119552
#include "bits/stdc++.h"
using namespace std;
static const int MAX = 100000;

int points[MAX];

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;

    for (int i = 0; i < Q; ++i) {
        int A; cin >> A;
        points[A - 1]++;
    }

    for (int i = 0; i < N; ++i) {
        if (Q - points[i] >= K) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;

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

  printf("%f", pow(l/3.0, 3));
  
  

  return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  p = list(map(int, input().split()))
  for i in range(1000):
    if not(X-i in p):
      ans = X-i
      break
    elif not(X+i in p):
      ans = X+i
      break
  print(ans)

Measured memory_bytes: 9120
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

bool comp(int a, int b) {
  return __builtin_popcount(a) < __builtin_popcount(b);
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> c(m);
  vector<int> a(m);
  const int N = (1 << n), INF = 1e12;
  vector<int> dp(N, INF);
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    int b;
    cin >> b;
    c[i].resize(b);
    for (int j = 0; j < b; j++) {
      cin >> c[i][j];
      c[i][j]--;
    }
    for (int mask = 0; mask < (1 << b); mask++) {
      int adad = 0;
      for (int j = 0; j < b; j++) {
        if (mask & (1 << j)) {
          adad |= (1 << c[i][j]);
        }
      }
      dp[adad] = min(dp[adad], a[i]);
    }
  }
  vector<int> order;
  for (int i = 0; i < N; i++) {
    order.push_back(i);
  }
  sort(order.begin(), order.end(), comp);
  for (auto &state : order) {
    vector<int> v;
    for (int i = 0; i < 13; i++) {
      if (state & (1 << i)) v.push_back(i);
    }
    for (int mask = 0; mask < (1 << sz(v)); mask++) {
      int adad = 0;
      for (int j = 0; j < sz(v); j++) {
        if (mask & (1 << j)) {
          adad |= (1 << v[j]);
        }
      }
      dp[state] = min(dp[state], dp[adad] + dp[state ^ adad]);
    }
  }
  if (dp[N - 1] == INF) {
    cout << "-1\n"; 
  } else {
    cout << dp[N - 1] << "\n";
  }
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int par[100010],r[100010]={};
int root(int a);
void unite(int a,int b);

int main(void){
  int n,m,i,x,y,z;
  set<int> s;
  cin >> n >> m;
  for (i=1;i<=n;i++) par[i]=i;
  for (i=0;i<m;i++){
    cin >> x >> y >> z;
    unite(x,y);
  }
  for (i=1;i<=n;i++) s.insert(root(i));
  cout << s.size() << endl;
  return 0;
}

int root(int a){
  if (par[a]==a) return a;
  return par[a]=root(par[a]);
}

void unite(int a,int b){
  a=root(a);
  b=root(b);
  if (a==b) return;
  if (r[a]<r[b]){
    par[a]=b;
    r[b]++;
  }else{
    par[b]=a;
    r[a]++;
  }
  return;
}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int d = a / b;
		int r = a % b;
		double f = (double)a / (double)b;
      /*  BigDecimal BD = new BigDecimal(f); */
        
        System.out.printf("%d %d %.5f", d, r, f);
		

	}
}

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

void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

bool sortKhela(const pair< int, int > &a,
               const pair< int, int > & b)
{
    return (a.first < b.first);
}

int main()
{
    c_p_c();
    char ch;
    cin >> ch;
    if (ch >= 'A' && ch <= 'Z')
        cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}

Measured memory_bytes: 3540
N = int(input())
B = [int(i) for i in input().split()] + [0]

A = []
for i in range(N):
  if B[i] != B[i+1]:
    A.append(B[i])

T = []
for i in range(len(A)-1):
  if A[i] < A[i+1]:
    T.append(1)
  else:
    T.append(-1)
T.append(0)
T2 = [(A[0], T[0])]
for i in range(len(A)-1):
  if T[i] != T[i+1]:
    T2.append((A[i+1], T[i+1]))

money = 1000
kabu = 0
for m, s in T2:
  if kabu > 0 and s == -1:
    money += m * kabu
    kabu = 0
  if s == 1:
    buy = money // m
    kabu += buy
    money -= buy * m
if kabu > 0:
  money += A[-1] * kabu
print(money)



Measured memory_bytes: 61888
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <string>
#define pi 3.1415926535897932384626
#include <cmath>
#define test(t) while(t--)

#define ll  long long int

#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define pb push_back
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);
#define double long double


using namespace std;
ll form(ll n){
return (n*(n+1))/2;
}
ll exponent(ll base, ll power){
   ll res = 1;
  ll m = 1000000007;
   while(power){
    if(power&1)
        res = (res*base)%m;
    base= (base*base)%m;
    power=power>>1;
   }
return res;}
void solve()
{ ll a,b;
  in a>>b;
 out  a*b<<en;
}



int main(){ fast()
             //freopen("input.txt","r",stdin);
             //freopen("output.txt","w",stdout);
             ll t=1;
           //cin>>t;
            test(t){
            solve();
            }
return 0;}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio> 　　　　 //定义输入／输出函数
#include <stack>　　　　　 //STL 堆栈容器
#include <map>　　　　　　 //STL 映射容器
#include <vector>　　　　　//STL 动态数组容器
#include <string>　　　　　//字符串类
#include <iterator>        //STL迭代器
#include <cstdlib> 　　　　//定义杂项函数及内存分配函数
#include <cstring> 　　　　//字符串处理ed
#include<algorithm>
#include<queue>
#include<cmath>
#include<ctime>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define FOR(ITER,BEGIN,END)  for(int  ITER=BEGIN;ITER<END;ITER++)
#define PER(ITER,TIMES) FOR(ITER,0,TIMES)
#define TIME(TIME_NUMBER) PER(_PETER_MRSCO_ITER_,TIME_NUMBER)	
#define  ll  long long
#define close_stdin  ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
//const int maxn = 200005;
//const long long mod = 1000000007;
//long long a[maxn];
//long long sum1[maxn]; //正
//long long sum[maxn]; //负
//int n, k;
//void solve() {
//	cin >> n >> k;
//	int cnt1 = 0, cnt = 0;
//	long long ans = 0;
//	for (int i = 1;i <= n;i++) {
//		cin >> a[i];
//		if (a[i] > 0) { cnt1++; }
//		else if(a[i]<0) { cnt++; }
//	}
//	if (cnt1 + cnt < k) { cout << "0\n"; return; }
//	sort(a + 1, a + 1 + n);
//	sum1[0] = 1;sum[0] = 1;
//	for (int i = 1;i <= cnt1;i++) {
//		sum1[i] = (sum1[i - 1] * a[n - i + 1]) % mod;
//		sum[i] = (sum[i - 1] * (-a[i]))%mod;
//	}
//	for(int i=0;i<=min(k,cnt))
//
//}


//const int maxn = 1000005;
//int a[maxn];
//int n;
//vector<int>up, down;
//void solve() {
//	cin >> n;
//	for (int i = 1;i <= n;i++) {
//		cin >> a[i];
//	}
//	a[0] = -1000000001;
//	a[n + 1] = 1000000001;
//	int i = 0;
//	int flag = 0;
//	while (i <= n) {
//		if (!flag) {
//			while (a[i] <= a[i + 1]&&i<=n) { i++; }
//			up.push_back(i);
//			flag = 1;
//		}
//		else if(flag==1){
//			while (a[i] >= a[i + 1]) { i++; }
//			down.push_back(i);
//			flag = 2;
//		}
//		else if (flag == 2) {
//			while (a[i] <= a[i + 1]&&i<=n) { i++; }
//			flag = 3;
//		}
//		else if (flag == 3) { flag = 4; break; }
//	}
//	if (flag == 1) { cout << "1 1\n"; }
//	else if(flag==3){
//		int x = up[0];
//		while (a[x] == a[up[0]]) { x--; } {up[0] = x + 1;}
//		x = down[0];
//		while (a[x] == a[down[0]]) { x++; } {down[0] = x - 1;}
//		cout << up[0] << " " << down[0] << "\n";
//	}
//	else if (flag == 4) { cout << "impossible\n"; }
	/*for (int i = 1;i <=n;i++) {

		if (a[i] >= a[i - 1] && a[i] > a[i+1] ) { up.push_back(i); }
		else if (a[i] < a[i - 1] && a[i] <= a[i + 1]) { down.push_back(i); }
	}
	int szup = up.size(), szdown = down.size();
	if (szup > 1 && szdown > 1) { cout << "impossible\n"; }
	else if (!szup && !szdown) { cout << "1 1\n"; }
	else {
		int x = up[0];
		while (a[x] == a[up[0]]) { x--; } {up[0] = x + 1;}
		x = down[0];
		while (a[x] == a[down[0]]) { x++; } {down[0] = x - 1;}
		cout << up[0] << " " << down[0] << "\n"; 
	}*/
//}
const int maxn = 200005;
int a[maxn];
int n;
long long ans = 0;
void solve1() {
	cin >> n;
	for (int i = 1;i <= n;i++) { cin >> a[i]; }
	sort(a + 1, a + 1 + n);
	ans += a[n];
	int cnt = n - 2;
	int i = n - 1;
	for (int i = n - 1;i >=1;i--) {
		if (cnt) { cnt--; ans += a[i]; }
		if (cnt) { cnt--; ans += a[i]; }
		else { cout << ans << "\n";return; }
	}
}
int main() {
	close_stdin;
	solve1();
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int a[31] = {0};
	a[1] = 1; a[2] = 2; a[3] = 4;
	FOR(i,4,31){
		a[i] = a[i-1] + a[i-2] + a[i-3];
	}
	int n;
	while(cin >> n, n){
		cout << ((a[n]%3650==0) ? a[n]/3650 : a[n]/3650 + 1) << endl;
	}
}

Measured memory_bytes: 1156
#include<iostream>
#include<cmath>
using namespace std;
void solve() {
	int r, t; cin >> r >> t;
	bool a = r % 100 == 0, b = t % 30 == 0;
	if (a&&b)cout << t / 30 * 5 + r / 100 << endl;
	else if (a && !b)cout << floor((double)t / 30) * 5 + r / 100 << ' ' << ceil((double)t / 30) * 5 + r / 100 << endl;
	else if (!a&&b)cout << t / 30 * 5 + floor((double)r / 100) << ' ' << t / 30 * 5 + ceil((double)r / 100) << endl;
	else cout << floor((double)t / 30) * 5 + floor((double)r / 100) << ' ' << floor((double)t / 30) * 5 + ceil((double)r / 100) << ' ' << ceil((double)t / 30) * 5 + floor((double)r / 100) << ' ' << ceil((double)t / 30) * 5 + ceil((double)r / 100) << '\n';
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3276
while True:
	n, q = map(int, raw_input().split())
	if n == q == 0: break
	counts = [0] * 101
	maxd = 0
	for i in xrange(n):
		data = map(int, raw_input().split()[1:])
		for d in data:
			counts[d] += 1
			maxd = max(maxd, counts[d])
	if q <= maxd:
		print counts.index(maxd)
	else:
		print 0

Measured memory_bytes: 4228
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    string s(b, '0'+a);
    string t(a, '0'+b);
    cout << min(s, t) << endl;
    return 0;
}


Measured memory_bytes: 256
def solve(a, b, c, d):
    f = True
    while a > 0 and c > 0:
        if f:
            c -= b
            f = False
        else:
            a -= d
            f = True
    if a > 0:
        return 'Yes'
    else:
        return 'No'


a, b, c, d = map(int, input().split())
print(solve(a, b, c, d))


Measured memory_bytes: 9112