akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    A.push_back(X);
    sort(A.begin(), A.end());

    ll ans = A[1] - A[0];
    REP(i, N) {
        ans = gcd(ans, A[i + 1] - A[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  bool c = false;
  int ok = 0;
  if(s[0] == 'A'){
    for(int i = 1; s.size() > i; i++){
      if(i > 1 && s.size()-1 > i){
        if(c && s[i] == 'C'){
          ok = -1;
          break;
        }else if(!c && s[i] == 'C'){
          c=true;
          ok=1;
        }
      }else{
          if(!(s[i] <= 'z' && s[i] >= 'a')){
            ok = -1;
            break;
          }
        }
    }
    if(ok == 1)cout << "AC" << endl;
    else cout << "WA" << endl;
  } else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		long[] X = new long[n];
		long[] sortX = new long[n];
		for (int i = 0; i < n; ++i) {
			X[i] = sc.nextLong();
			sortX[i] = X[i];
		}
		Arrays.sort(sortX);
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; ++i) {
			if (X[i] > sortX[n / 2 - 1]) {
				pw.println(sortX[n / 2 - 1]);
			} else if (X[i] <= sortX[n / 2 - 1]) {
				pw.println(sortX[n / 2]);
			}
		}
		pw.close();
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			return (int) nextLong();
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

cnt = 0
for i in range(0, A+1):
    for j in range(0, B+1):
        for k in range(0, C+1):
            if 500 * i + 100 * j + 50 * k == X:
                cnt += 1
print(cnt)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {

		boolean f=true;
		while(true){
			int pay=sc.nextInt();
			if(pay==0)return;

			if(!f)ln();
			f=false;

			int m10=sc.nextInt(),m50=sc.nextInt(),m100=sc.nextInt(),m500=sc.nextInt();

			int min=Integer.MAX_VALUE;
			int p500=0,p100=0,p50=0,p10=0;

			for(int u10=0;u10<=m10;u10++)for(int u50=0;u50<=m50;u50++)
				for(int u100=0;u100<=m100;u100++)for(int u500=0;u500<=m500;u500++){
					int res=u10*10+u50*50+u100*100+u500*500;
					if(pay<=res){
						res-=pay;
						int t500=res/500;
						res%=500;
						int t100=res/100;
						res%=100;
						int t50=res/50;
						res%=50;
						int t10=res/10;

						int mc=t500+t100+t50+t10+(m10-u10)+(m50-u50)+(m100-u100)+(m500-u500);
						if(min>mc){
							p500=u500;
							p100=u100;
							p50=u50;
							p10=u10;
							min=mc;
						}
					}
			}
			if(p10>0)ln("10 "+p10);
			if(p50>0)ln("50 "+p50);
			if(p100>0)ln("100 "+p100);
			if(p500>0)ln("500 "+p500);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 34756
#include <bits/stdc++.h>
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    vector<int> D(N + 1, 0);
    for (int i = 1; i < N + 1; i++)
    {
        D[i] = D[i - 1] + L[i - 1];
    }
    int ans = 0;
    for (int i = 0; i < N + 1; i++)
    {
        if (X >= D[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll X;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X;

	map<ll, ll> v;
	rep(x, -1000, 1001) v[1LL * x * x * x * x * x] = x;

	fore(bp, v) {
		ll B5 = bp.first;
		ll B = bp.second;

		if (v.count(X + B5)) {
			ll A = v[X + B5];
			printf("%lld %lld\n", A, B);
			return;
		}
	}
}







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

pub 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")
}

use std::collections::HashMap;

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut map: HashMap<char, char> = HashMap::new();

    for i in 0..s.len() {
        if !map.contains_key(&s[i]) {
            map.insert(s[i], t[i]);
        } else {
            let current = map.get(&s[i]).unwrap();
            if *current != t[i] {
                // println!("{} {}", current, t[i]);
                println!("No");
                return;
            }
        }
    }
    let mut map: HashMap<char, char> = HashMap::new();
    let tmp = t;
    let t = s;
    let s = tmp;

    for i in 0..s.len() {
        if !map.contains_key(&s[i]) {
            map.insert(s[i], t[i]);
        } else {
            let current = map.get(&s[i]).unwrap();
            if *current != t[i] {
                // println!("{} {}", current, t[i]);
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 6396
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += B[i]
    if (i != N - 1) and (A[i + 1] == A[i] + 1):
        ans += C[A[i] -  1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>

#define ALL(a)  (a).begin(),(a).end()

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    double a, b, x;
    double ans = 0;

    vector<int> l;

    cin >> a >> b >> x;

    if (x > ((a * a) * b) / 2.0) {
        x = ((a * a) * b) - x;
        ans = atan2(x, ((a * a) * a) / 2.0);
    } else {
        ans = atan2(((a * b) * b) / 2.0, x);
    }

    cout << std::setprecision(9) << ans * 180 / 3.1415926 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int s;
    s=0;
    for(int i =1;i<=N;i++){
        for(int j =1;j<=N;j++){
            for(int k =1;k<=N;k++){
                s+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(9, 0);
    rep(i, n){
        int m;
        cin >> m;
        if(m >= 3200) ++a[8];
        else ++a[m/400];
    }

    int min = 0, max = 0;
    rep(i, 8){
        if(a[i]){
            ++min;
            ++max;
        }
    }
    if(min == 0){
        cout << 1 << " " << a[8] << endl;
        return 0;
    }

    max += a[8];
    cout << min << ' ' << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld err=0.000000001;
#define    N       2000005
#define   ESP     1e-9
#define    pii      pair<int,int>
#define    vi       vector<int>
#define    vl       vector<ll>
#define    pb       push_back
#define    pp       pop_back
int ar[1000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,c;
    cin>>n>>m>>c;
    for(int i=0;i<m;i++){
        cin>>ar[i];
    }
    ll cnt=0;
    for(int i=0;i<n;i++){
            ll sum=c;
        for(int j=0;j<m;j++){
            int input;
            cin>>input;
            sum+=input*ar[j];
        }
        if(sum>0) cnt+=1;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> s(M);
    for(int i=0;i<M;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int a;
            cin>>a;
            s[i]|=(1<<--a);
        }
    }
    vector<int> P(M);
    for(auto &p:P)cin>>p;
    int ans=0;
    for(int b=0;b<(1<<N);b++){
        int ok=1;
        for(int i=0;i<M;i++){
            int bb=b&s[i];
            int cnt=0;
            while(bb){
                cnt+=(1&bb);
                bb>>=1;
            }
            cnt=(cnt&1);
            if(cnt!=P[i]) ok=0;
        }
        ans+=ok;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#define N 501

static const int INFTY = (1<<21);
static const int A = 0;
static const int B = 1;
static const int C = 2;

int n, M[N][N];
int a[N], d[N], f[N], tt;

void dfs_visit(int u);
void dfs();

int main(){
  int u,k,v; 
  int i,j;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  
  dfs();

  return 0;
}

void dfs_visit(int u){
  int v;
  a[u]=B;
  tt++;
  d[u]=tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(a[v]==A){
      dfs_visit(v);
    }
  }
  a[u] = C;
  f[u] = ++tt;
}

void dfs(){
  int i,u;
  for(i=0;i<n;i++)a[i]=A;
  tt=0;
  for(u=0;u<n;u++){
    if(a[u]==A)dfs_visit(u);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}



Measured memory_bytes: 2144
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

l = p[:x] + q[:y] + r
l.sort(reverse=True)

print(sum(l[:x+y]))

Measured memory_bytes: 23328
# -*- coding: utf-8 -*-
import sys
N,Y=map(int, input().split())

num_ten_thouthand = int(Y / 10000)

# num_five_thouthand = int((N % 10000) / 5000)

for i_ten_thouthand in range(0,num_ten_thouthand+1):
    for i_five_thouthand in range(0,N - i_ten_thouthand +1):
        i_thouthand = N  - i_ten_thouthand - i_five_thouthand
        if i_thouthand * 1000 + i_five_thouthand * 5000 + i_ten_thouthand * 10000 == Y:
            print("{} {} {}".format(i_ten_thouthand,i_five_thouthand,i_thouthand))
            sys.exit()

print("-1 -1 -1")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("B.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,k;
    cin >> a >> b >> k;
    if (a+k-1 >= b-k+1){//output all
        rep(i,a,b+1) cout<<i<<endl;
    }
    else{
        rep(i,a,a+k) cout<<i<<endl;
        rep(i,b-k+1,b+1) cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    int n;cin >> n;
    int e[26];
    for(int i = 0;i < 26;i++) e[i] = 0;
    for(int i = 0;i < n;i++){
        char z; cin >> z;
        e[z - 'a']++;
    }
    ll result = 1;
    ll big = 1e9 + 7;
    for(int i = 0;i <  26;i++){
        result = result * (e[i] + 1) % big;
    }
    result -= 1;
    result %= big;

    cout << result << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b,c=0,i=1;
    scanf("%d",&a);
    while(1)
    {
        for(b=a; b>=1; b--)
        {
            if(a%b==0)
            {
                c++;
            }
            if(c>2)
            {
                break;
            }
        }
        if(c==2)
        {
            break;
        }
        a=a+1;
        c=0;
        i++;
    }
    if(c==2)
    {
        printf("%d",a);
    }

}

Measured memory_bytes: 1728
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int x=sc.nextInt();
	    int n=sc.nextInt();
	    if(n==0) {
	    	 System.out.println(x);
	    	 System.exit(0);
	    }
	    int[] p=new int[n];
	    
	    for(int i=0;i<n;i++) {
	    	p[i]=sc.nextInt();
	    }
	    Arrays.sort(p);
	    int ans=0;
	    int dist=1000;
	    int ind=0;
	    for(int i=p[0]-1;i<=p[n-1]+1;i++) {
	    	if(p[ind]==i) {
	    		if(ind<n-1)ind++;
	    		continue;
	    	}
	    	//System.out.println("i "+i);
	    	//System.out.println("dist "+dist);
	    		int tmp=Math.abs(i-x);
	    		if(tmp>=dist) {
	    			break;
	    	    }else {
	    		    dist=tmp;
	    		    ans=i;
	    	    }
	    	
	    }
	    
	    System.out.println(ans);
	}
}


Measured memory_bytes: 35904
N, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]

visited_count = [0]*N

cnt = 1
next_visit = A[0] - 1
for _ in range(K):
    cnt += 1
    if not visited_count[next_visit]:
        visited_count[next_visit] = cnt
        next_visit = A[next_visit] - 1
    else:
        c2 = cnt - visited_count[next_visit]
        c1 = visited_count[next_visit] - 1
        place_count = ((K-c1) % c2) + c1 + 1
        place = visited_count.index(place_count) + 1
        print(place)
        exit(0)

place_count = K + 1
place = visited_count.index(place_count) + 1
print(place)


Measured memory_bytes: 32332
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int a, b;
	cin >> a >> b;

	if (a == 1) a = 14;
	if (b == 1) b = 14;

	if (a > b) cout << "Alice" << endl;
	else if (a < b) cout << "Bob" << endl;
	else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=924844033;
const int N=4005;
int n,k;
bool vis[N][2];
bool ed[N];
int tot;
int d[N][N][2];
int f[N];
int fact[N];
int main()
{
    //freopen("captain.in","r",stdin);
    //freopen("captain.out","w",stdout);
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        for(int j=0;j<=1;j++)
            if(!vis[i][j]){
                int len=0;
                for(int x=i,y=j;x<=n;x+=k,y^=1)
                    vis[x][y]=1,len++;
                tot+=len;
                ed[tot]=1;
            }
    ed[0]=1;
    d[0][0][0]=1;
    for(int i=0;i<2*n;i++)
        for(int j=0;j<=n;j++){
            d[i+1][j][0]=(d[i][j][0]+d[i][j][1])%mod;
            if(!ed[i])
                d[i+1][j+1][1]=d[i][j][0];
        }
    for(int i=0;i<=n;i++)
        f[i]=(d[2*n][i][0]+d[2*n][i][1])%mod;
    fact[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=1ll*fact[i-1]*i%mod;
    int ans=0;
    for(int i=0,j=1;i<=n;i++,j=-j)
        ans=((1ll*ans+1ll*j*fact[n-i]*f[i]%mod)%mod+mod)%mod;
    printf("%d\n",ans);
}

Measured memory_bytes: 124544
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long ans,sum;
int n,a,b,c,x,y,cnt;
struct node{
	int pos,dis;
}num[300001];
bool cmp(node x,node y)
{
	return x.dis>y.dis;
}
int main()
{
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	n=a+b+c;
	for(int i=1;i<=a;i++){
		scanf("%d",&num[i].dis);
		num[i].pos=1;
	}
	for(int i=a+1;i<=a+b;i++){
		scanf("%d",&num[i].dis);
		num[i].pos=2;
	}
	for(int i=a+b+1;i<=a+b+c;i++){
		scanf("%d",&num[i].dis);
		num[i].pos=0;
	}
	sort(num+1,num+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(num[i].pos==1&&x)
			x--,ans+=num[i].dis;
		if(num[i].pos==2&&y)
			y--,ans+=num[i].dis;
		if(num[i].pos==0)
			sum+=num[i].dis,cnt++;
		if(cnt==x+y) break;
	}
	printf("%lld",ans+sum);
	return 0;
}


Measured memory_bytes: 2560
import numpy as np
alpha = list('abcdefghijklmnopqrstuvwxyz')
alpha_num = [num for num in range(26)]

d = {char:num for (char, num) in zip(alpha, range(26))}

S = input()
S_num = np.array([d[char] for char in S])
last = S_num[-1]

flag = True

if len(S) < 26:
  S_num.sort()
  for k in range(len(S_num)):
    if S_num[k] != alpha_num[k]:
      print(S + alpha[k])
      flag = False
      break
  if flag:
    print(S + alpha[len(S)])

else:
  for k in reversed(range(1, 26)):
    if S_num[k] > S_num[k-1]:
      A = S_num[k:]
      A = A[A > S_num[k-1]]
      A.sort()
      print(S[:k-1] + alpha[A[0]])
      flag = False
      break
  if flag:
    print(-1)

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

int main() {
	vector<int>a(3);
	for (int i = 0; i < 3; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	cout << a.at(0)+a.at(1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool flag = true ;
string s ;
int main() {
    int n ;
    cin >> n ;
    cin >> s ;
    if(n%2) {
        cout <<"No" << endl ; return 0 ;
    }
    for(int i = 0 ; i < n / 2; i++) {
        if(s[i] != s[n / 2 + i]) flag =false ;
    } 
    if(flag) cout << "Yes" << endl ;
    else cout << "No" << endl ;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//  16:30-
//A 16:36
//B 16:46
//C 16:51
//D 17:15WA
//D 17:17TLE
int n;
vector<pair<int,int>>mada;
vector<vector<int>>taisen;
map<vector<int>,llint>memo;
llint sai(vector<int>win,int kai){
	if(kai>=mada.size()){return 1;}
	if(memo.count(win)){return memo[win];}
	int A=mada[kai].fir,B=mada[kai].sec;
	auto wina=win,winb=win;
	llint ans=0;
	wina[A]++;
	if(wina[A]<=n/2&&taisen[kai][B]-wina[B]<=n/2){ans+=sai(wina,kai+1);}
	winb[mada[kai].sec]++;
	if(winb[B]<=n/2&&taisen[kai][A]-winb[A]<=n/2){ans+=sai(winb,kai+1);}
	memo[win]=ans;
	return ans;
}
int solve(void){
	int i,j,m;cin>>n;
	memo.clear();taisen.clear();mada.clear();
	if(n==0){return 0;}
	cin>>m;
	vector<int>win(n);
	int yata[9][9]={};
	vector<int>tai(n);
	while(m--){
		int a,b;cin>>a>>b;a--;b--;
		yata[a][b]=1;yata[b][a]=1;win[a]++;
		tai[a]++;tai[b]++;
	}
	
	//cerr<<"ans=";
	for(i=0;i<n;i++){
		if(win[i]>n/2){cout<<0<<endl;return 1;}
		for(j=i+1;j<n;j++){
			if(!yata[i][j]){
				mada.pub(mp(i,j));
				tai[i]++;tai[j]++;
				taisen.pub(tai);
			}
		}
	}
	cout<<sai(win,0)<<endl;
	
	return 1;
}
int main(void){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 4584
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){

    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    x *= 2;
    y *= 2;
    
    int ans = 0;
    while(x > 0 && y > 0){
        ans += min(a+b,2*c);
        x -= 2;
        y -= 2;
    }
    while(x > 0){
        ans += min(a,2*c);
        x -= 2;
    }
    while(y > 0){
        ans += min(b,2*c);
        y -= 2;
    }
    cout << ans << endl;

    


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc095.contest.atcoder.jp/tasks/arc096_a

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

using namespace std;

const int N = 55;

int n, a[N], b[N], can[N][N], e[N][N];
long long ans;
vector <int> v;

void dfs(int v, int x){
      can[x][v] = 1;
      for(int i = 0; i <= v; i ++){
            if(e[v][i] && !can[x][i])
                  dfs(i, x);
      }
}

bool check(int x){
      memset(can, 0, sizeof(can));
      memset(e, 0, sizeof(e));

      for(int i = 1; i <= 50; i ++){
            for(int j = 1; j <= min(i, x); j ++){
                  int r = i % j;
                  e[i][r] = 1;
            }
            for(int j : v){
                  if(j > i) continue;
                  int r = i % j;
                  e[i][r] = 1;
            }
      }

      for(int i = 0; i <= 50; i ++){
            dfs(i, i);
      }

      for(int i = 1; i <= n; i ++){
            if(!can[a[i]][b[i]]) return false;
      }
      return true;
}

int main(){

      for(int i = 1; i <= 50; i ++){
            for(int j = 1; j <= i; j ++){
                  int r = i % j;
                  e[i][r] = 1;
            }
      }

      for(int i = 0; i <= 50; i ++){
            dfs(i, i);
      }

      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 ++){
            if(!can[a[i]][b[i]]){
                  puts("-1");
                  return 0;
            }
      }

      for(int i = 50; i >= 1; i --){
            if(!check(i - 1)){
                  v.push_back(i);
            }
      }

      for(int i : v)
            ans += (1ll << i);

      cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
//#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;


string map[12];
int ans;
int d_row[] = {-1, 0, 0, 1};
int d_col[] = {0, -1, 1, 0};


void dfs(int row, int col)
{
	map[row][col] = 0;
	for (int i=0; i<4; i++)
	{
		int n_row = row + d_row[i];
		int n_col = col + d_col[i];
		if (0<=n_row && n_row<12 && 0<=n_col && n_col<12 && map[n_row][n_col]=='1')
		{
			dfs(n_row, n_col);
		}
	}
}


int main()
{
	while (cin >> map[0])
	{
		ans = 0;
		for (int i=1; i<12; i++) cin >> map[i];
		//for (int i=0; i<12; i++) cout << map[i] << endl;
		for (int i=0; i<12; i++)
		{
			for (int j=0; j<12; j++)
			{
				if (map[i][j] == '1')
				{
					ans++;
					//cout << "ans = " << ans << endl;
					dfs(i, j);
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =2*1e5+5;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

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

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long term_n;
    vector<long long> term_length(200001);
    long long sum_r, sum_l;
    long long nr, nl;

    cin >> term_n;

    for (long i = 0; i < term_n; i++)
    {
        cin >> term_length.at(i);
    }
    

    sum_l = sum_r = 0;
    nr = term_n - 1;
    nl = 0;
    while (nr >= nl)
    {
        if(sum_r <= sum_l) {
            sum_r += term_length.at(nr);
            nr--;
        } else {
            sum_l += term_length.at(nl);
            nl++;
        }
    }

    cout << abs(sum_r - sum_l) << endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC116
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] hs = ReadInts();
            int cnt = 0;
            int remain = n;
            while (remain > 0)
            {
                remain = 0;
                bool removing = false;
                for (int i = 0; i < n; i++)
                {
                    if (hs[i] > 0)
                    {
                        if (!removing)
                        {
                            removing = true;
                            cnt++;
                        }
                        hs[i]--;
                        remain++;
                    }
                    else
                    {
                        removing = false;
                    }
                }
            }
            Console.WriteLine(cnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int cnt[2][105] = { 0 };
int n, ans = 0;

int main() {
	int i, j;
	cin >> n;
	for (i = 0; i < 2; ++i)
		for (j = 1; j <= n; ++j) {
			cin >> cnt[i][j];
			cnt[i][j] += cnt[i][j - 1];
		}
	for (i = 1; i <= n; ++i)
		ans = max(ans, cnt[0][i] + cnt[1][n] - cnt[1][i - 1]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.par = [x for x in range(n)]
        self.rank = [0]*n
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        elif self.rank[y] > self.rank[x]:
            self.par[x] = y
        else:
            self.par[x] = y
            self.rank[y] += 1
    
    def same(self, x, y):
        return (self.find(x) == self.find(y))

n, q = map(int, input().split())
uf = UnionFind(n)
for i in range(q):
    _c, _x, _y = map(int, input().split())
    if _c == 0:
        uf.unite(_x, _y)
    else:
        if uf.same(_x, _y):
            print("1")
        else:
            print("0")


Measured memory_bytes: 6040
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const ll inf = 1000000000000000007LL;
using namespace std;
ll w[10][10], ans[10][10], tmp[10][10], m;
bool solve(ll n) {
	rep(i, 1, 6) rep(j, 1, 6) w[i][j] = - inf;
	rep(i, 1, 6) rep(j, 1, 6) if (i != j && i + j != 7) w[j][i] = i;
	bool flg = true;
	for ( ; n; n /= 2) {
		if (n & 1LL) {
			if (flg) {
				memcpy(ans, w, sizeof(w));
				flg = false;
			} else {
				rep(i, 1, 6) rep(j, 1, 6) tmp[i][j] = - inf;
				rep(i, 1, 6) rep(j, 1, 6) rep(k, 1, 6) 
					tmp[i][j] = max(tmp[i][j], ans[i][k] + w[k][j]);
				memcpy(ans, tmp, sizeof(tmp));
			}
		}
		rep(i, 1, 6) rep(j, 1, 6) tmp[i][j] = - inf;
		rep(i, 1, 6) rep(j, 1, 6) rep(k, 1, 6)
			tmp[i][j] = max(tmp[i][j], w[i][k] + w[k][j]);
		memcpy(w, tmp, sizeof(tmp));
	}
	ll mx = - inf;
	rep(i, 1, 6) rep(j, 1, 6) mx = max(mx, ans[i][j]);
	return (mx >= m);
}
int main() {
	scanf("%lld", &m);
	ll l = 1, r = inf, ans;
	for ( ; l <= r; ) {
		ll mid = (l + r) / 2;
		if (solve(mid)) ans = mid, r = mid - 1;
			else l = mid + 1;
	}
	printf("%lld\n", ans); 
	return 0;
}

Measured memory_bytes: 256
def f(ls):
    if len(ls) == 0:
        return 0
    cnt = 0
    if not 0 in ls:
        min_ = min(ls)
        ls = [l - min_ for l in ls]
        cnt += min_
    divs = []
    s = 0
    for i, l in enumerate(ls):
        if l == 0:
            if i == 0:
                s = 1
            else:
                divs.append(ls[s:i])
                s = i + 1
    if l != 0:
        if s == i:
            divs.append([ls[s]])
        else:
            divs.append(ls[s:i+1])
    cnt_ = sum([f(d) for d in divs])
    return cnt + cnt_

n = int(input())
ls_ = [int(i) for i in input().split()]
print(f(ls_))

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(N);
  for (int i = 0; i < N; ++i) {
    cin >> L[i];
  }
  sort(L.rbegin(), L.rend());
  int ans = 0;
  for (int i = 0; i < K; ++i) {
    ans += L[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

signed main(){
    CIN(x,y);
    COUT(x + y / 2);
}


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

int main(){
  double dp[1<<15][15];
  int prv[1<<15][15];
  int n;
  int num[15],pos[15],w[15],ans[15];

  cin >> n;
  for(int i=0;i<n;i++)cin >> num[i] >> pos[i] >> w[i];

  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      dp[i][j] = 1e+10;
      prv[i][j] = -1;
    }
  }
  for(int i=0;i<n;i++){
    dp[(1<<i)][i] = (double)pos[i]*70/20000;
    prv[(1<<i)][i] = i;
  }

  for(int i=0;i<(1<<n);i++){
    int weight = 0;
    for(int j=0;j<n;j++){
      if( i &(1<<j) )weight += w[j];
    }
    for(int j=0;j<n;j++){
      if( i &(1<<j) ){
	int tmp = i-(1<<j);
	for(int k=0;k<n;k++){
	  if(tmp &(1<<k)){
	    double dis = abs(pos[k] - pos[j]);
	    double d = dp[tmp][k]+dis*(70+20*(weight-w[j]))/20000;
	    if(dp[i][j]>d){
	      dp[i][j] = d;
	      prv[i][j] = k;
	    }
	  }
	}
      }
    }
  }

  int a = 0;
  for(int i=1;i<n;i++){
    if(dp[(1<<n)-1][i] < dp[(1<<n)-1][a])a = i;
  }
 
  int c = n-1;
  int p = (1<<n) - 1;  
  while(p){
    ans[c] = a;
    a = prv[p][a];
    p -= (1<<ans[c]);
    c--;
  }

  for(int i=0;i<n-1;i++)cout << num[ans[i]] << " ";
  cout << num[ans[n-1]] << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

using pdi = pair<ld, int>;

int main(){
    int N; ll T;
    cin >> N >> T;
    T++;
    ll a[N], b[N];
    vector<pdi> v;
    vector<pli> u;
    rep(i, N){
        cin >> a[i] >> b[i];
        ld x = a[i], y = b[i]+1;
        if(a[i] == 0) u.pb(pli(b[i], i));
        else v.pb(pdi(x/y, i));
    }
    sort(all(v), greater<pdi>());
    sort(all(u));
    vector<int> p, q;
    for(auto &e: v) p.pb(e.second);
    for(auto &e: u) q.pb(e.second);
    int n = sz(p), m = sz(q);
    ll dp1[n+1][50], dp2[m+1];
    fill(dp1[0], dp1[n+1], INF);
    dp1[0][0] = 1;
    rep(i, n){
        rep(j, 50){
            if(dp1[i][j] > T) continue;
            chmin(dp1[i+1][j], dp1[i][j]);
            int k = p[i];
            ll l = dp1[i][j]*(a[k]+1)+b[k]+1;
            if(l <= T && j+1 < 50) chmin(dp1[i+1][j+1], l);
        }
    }
    dp2[0] = 0;
    rep(i, m) dp2[i+1] = dp2[i]+b[q[i]]+1;
    int ans = 0;
    rep(i, 50){
        if(dp1[n][i] > T) continue;
        int j = upper_bound(dp2, dp2+m+1, T-dp1[n][i]) - dp2;
        chmax(ans, i+j-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 90088
#include<stdio.h>

int main()
{
	int a,b,c,d;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		d = a;
		a = b;
		b = d;
	}
	if(b>c){
		d = b;
		b = c;
		c = d;
	}
	if(a>b){
		d = a;
		a = b;
		b = d;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}


Measured memory_bytes: 2068
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String str = in.next();
		in.close();
		int sHold = 0;
		int deleteChar = 0;
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'S')
				sHold++;
			if (str.charAt(i) == 'T') {
				if (sHold > 0) {
					deleteChar += 2;
					sHold--;
				}
			}
		}
		System.out.println(str.length() - deleteChar);
	}
}

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

typedef unsigned long long ull;
using namespace std;

ull gcd(ull a, ull b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    ull A, B;
    cin >> A >> B;
    vector<ull> array;

    ull r = gcd(A, B);
    ull s;
    bool flag;

    for (ull i = 2; i * i < r + 1; ++i)
    {
        if (r % i == 0)
        {
            flag = true;
            for (int j = 0; j < array.size(); ++j)
            {
                if (i % array[j] == 0)
                {
                    flag = false;
                    break;
                }
                else if (array[j] % i == 0)
                {
                    flag = false;
                    array[j] = i;
                    break;
                }
            }
            if (flag)
                array.push_back(i);

            s = r / i;
            flag = true;
            for (int j = 0; j < array.size(); ++j)
            {
                if (s % array[j] == 0)
                {
                    flag = false;
                    break;
                }
                else if (array[j] % s == 0)
                {
                    flag = false;
                    array[j] = s;
                    break;
                }
            }
            if (flag)
                array.push_back(s);
        }
    }

    flag = true;
    for (int j = 0; j < array.size(); ++j)
    {
        if (r % array[j] == 0)
        {
            flag = false;
            break;
        }
    }
    if(r!=1 && flag) array.push_back(r);

    cout << array.size() + 1 << endl;
}

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

int main() {
    int h,w;cin>>h>>w;
    int a[h][w];
    rep(i,h)rep(j,w)a[i][j]=0;

    int bh[h],bw[w];
    rep(i,h)bh[i]=0;
    rep(i,w)bw[i]=0;
    
    rep(i,h){
        string s;cin>>s;
        rep(j,w)if(s[j]=='#'){
            a[i][j]=1;
            bh[i]=1;
            bw[j]=1;
        }
    }
    
    rep(i,h){
        rep(j,w){
            if(bh[i]==0||bw[j]==0)continue;
            else{
                if(a[i][j]==1)cout<<'#';
                else cout<<'.';
            }
        }
        cout<<endl;
    }
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
    for(int x=1;;x++){
        int l;
        int n;
        int v[1010]={0};
        int w[1010]={0};
        int dp[10][1010]={0};
        int we[10][1010]={0};
        cin >> l;
        if(l==0)break;
        cin >> n;
        for(int i=1;i <= n;i++){
            scanf("%d,%d",&v[i],&w[i]);
        }
        for(int i=1;i <= n;i++){
            for(int j=0;j <= l;j++){
                if(j < w[i]){
                    dp[2][j] = dp[1][j];
                    we[2][j] = we[1][j];
                }
                else{
                    if(dp[1][j]>dp[1][ j-w[i] ] + v[i]){
                        dp[2][j] = dp[1][j];
                        we[2][j] = we[1][j];
                    }
                    else{
                        dp[2][j] = dp[1][ j-w[i] ] + v[i];
                        we[2][j] = we[1][ j-w[i] ]+w[i];
                    }
                }
            }
            /*for(int k=0;k<=l;k++)cout<<we[i+1][k]<<" ";
            cout<<endl;*/
            for(int k=0;k <= l;k++){
                dp[1][k] = dp[2][k];
                we[1][k] = we[2][k];
            }
        }
        /*for(int i=1;i<=n;i++){
            for(int j=0;j<=l;j++){
            cout<<dp[i][j]<<" ";
            }
            cout<<endl;
        }*/
        cout<<"Case "<<x<<":"<<endl;
        cout<<dp[2][l]<<endl;
        cout<<we[2][l]<<endl;

    }
	return 0;
}

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

int main(){
  int K, N;
  cin >> K >> N;
  int A[N];
  rep(i, N)
    cin >> A[i];
  //ここまで入力
  
  int dist[N];
  rep(i, N-1)
    dist[i] = A[i+1]-A[i];
  dist[N-1] = A[0]+(K-A[N-1]);

  int max = 0;
  rep(i, N){
    if(max < dist[i])
      max = dist[i];
  }
  cout << K-max << endl;

  
  return 0;
}


Measured memory_bytes: 1792
MOD = 10**9 + 7

def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs


k = int(input())
s = input()
n = len(s)
ans = 0

l = k+n + 3
 
a25 = [1]
for i in range(l):
    a25.append((a25[-1] * 25) % MOD)
a26 = [1]
for i in range(l):
    a26.append((a26[-1] * 26) % MOD)

fact, inv = prepare(n+k, MOD)
for i in range(k+1):
    c25 = a25[i]
    f = fact[i+n-1] * inv[i] % MOD * inv[n-1] % MOD
    c25 *= f
    c25 %= MOD

    c26 = a26[k-i]
    ans += (c25 * c26 % MOD)
    ans %= MOD
print(ans)


Measured memory_bytes: 203812