akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin >> d;
  if (d == 25) cout << "Christmas" << endl;
  else if (d == 24) cout << "Christmas Eve" << endl;
  else if (d == 23) cout << "Christmas Eve Eve" << endl;
  else if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
const int K = 1e5 + 5;
const int N = 100 + 5;
int dp[K];
int arr[N];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if(i - arr[j] >= 0)
				dp[i] |= !dp[i - arr[j]];
		}
	}
	cout << (dp[k] ? "First" : "Second");
}


Measured memory_bytes: 640
using System;

public class Program{

	public static void Main(){
		
		var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
		
		int min = 1;
		int max = input[0];
		
		int[] hoge;
		
		for(int i = 0; i < input[1]; i++){
			hoge = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			min = Math.Max(min, hoge[0]);
			max = Math.Min(max, hoge[1]);
		
		}
		var a = ((max - min) + 1);
		Console.WriteLine( a >= 0 ? a : 0);
		
		
	
	}
		
	
	
}

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

int gcd(int a, int b) {
  if (b == 0) return a;
  else gcd(b, a%b);
}

int gcd(vector<int> a) {
  int ans = a[0];
  for (int i=0; i<a.size(); i++) {
    ans = gcd(ans, a[i]);
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  cout << gcd(A) << endl;
  
  
  
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<int> l(2*N);
    for(int i=0; i<2*N; i++) cin >> l[i];
    sort(l.begin(), l.end());


    int ans = 0;
    for(int i=0; i<2*N; i+=2) ans += l[i];

    cout << ans << endl;
}

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

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<vector<int>> G(N, vector<int>(0));
    for (int i=0; i<N-1; i++) {
        G.at(i).emplace_back(i+1);
        G.at(i+1).emplace_back(i);
    }
    G.at(X-1).emplace_back(Y-1);
    G.at(Y-1).emplace_back(X-1);
    map<int, int> hist;
    for (int i=1; i<=N-1; i++) hist[i] = 0;
    for (int i=0; i<N-1; i++) {
        queue<int> q;
        q.push(i);
        vector<bool> check(N, false);
        vector<int> dist(N, 1e9);
        dist.at(i) = 0;
        while (!q.empty()) {
            int p = q.front();
            q.pop();
            for (auto target : G.at(p)) {
                if (!check.at(target)) {
                    q.push(target);
                    dist.at(target) = min(dist.at(target), dist.at(p)+1);
                    check.at(target) = true;
                }
            }
        }
        for (int j=i+1; j<N; j++) {
            hist[dist.at(j)]++;
        }
    }
    for (auto ans : hist) {
        cout << ans.second << endl;
    }
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100005
using namespace std;
inline int read(){
	int sum = 0, t = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') t = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ sum = sum * 10 + ch - '0'; ch = getchar(); }
	return sum * t;
}

int n, A, B;
int h[N], Max;

bool check(int x){
	int least = x;
	for(int i = 1; i <= n && least >= 0; i++)
		least -= (max(h[i] - x * B, 0) + A - 1) / A;
	return least >= 0;
}

int main(){
	n = read(); A = read(); B = read();
	A -= B;
	for(int i = 1; i <= n; i++)
		Max = max(Max, h[i] = read());
	int l = 0, r = Max / B + 1;
	while(l < r){
		int mid = l + r >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", l);
}


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

const int letter_MAX = 1201;
int co[26] = {};
int letter[letter_MAX];


int main(){
	for (int j = 0; j < letter_MAX;j++){
		letter[j]=getchar();
		if (letter[j] == EOF)break;
		letter[j] = tolower(letter[j]);
		for (int i = 0; i < 26; i++){
			if (i == letter[j] - 'a')co[i]++;
		}
	}
	for (int i = 0; i < 26; i++){
		char a = i + 'a';
		cout << a << " : " << co[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

import static java.util.Arrays.sort;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int K=sc.nextInt();
        int[] D=new int[K];
        for(int i=0; i<K; i++){
            D[i]=sc.nextInt();
        }

        for(int i=0; i<=100000; i++){
            if(kakunin(i,D)){
                if(i >= N){
                    System.out.println(i);
                    System.exit(0);
                }
            }
        }
    }
    public static boolean kakunin(int i,int[] D){
        while(i>0){
            int am=i%10;
            for(int j=0; j<D.length; j++){
                if(am == D[j]){
                    return false;
                }
            }
            i/=10;
        }
        return true;
    }
}


Measured memory_bytes: 23252
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 c = scan.nextInt();
		int d = scan.nextInt();
		int l = a + b;
		int r = c + d;
		String message = "Balanced";
		if(l > r) {
			message = "Left";
		} else if(l < r) {
			message = "Right";
		}
		System.out.println(message);
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>

using namespace std;

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

struct Data
{
	short x, y;
	char state;
	int dist;
	Data() {}
	Data(short _x, short _y, int _dist, char _state)
	{
		x = _x;
		y = _y;
		dist = _dist;
		state = _state;
	}
};

Data data_[5 * 1000 * 1000];

class MockQueue
{
public:
	int head, tail;

	void Clear()
	{
		head = tail = 0;
	}
	
	void Enqueue(const Data &d)
	{
		data_[tail++] = d;
	}

	Data Dequeue()
	{
		return data_[head++];
	}
};

char fld[1000][1000];
bitset<1000> *isUsed;

inline int GetNext(int n)
{
	return (n == 4) ? 0 : n + 1;
}

inline int GetPrev(int n)
{
	return (n == 0) ? 4 : n - 1;
}

signed main()
{
	int W, H;
	MockQueue q;
	isUsed = new bitset<1000>[5 * 1000];
	while (cin >> W >> H, W || H)
	{
		int sx, sy, gx, gy;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				scanf(" %c", &fld[i][j]);
				if (fld[i][j] == 'S')
				{
					sx = j;
					sy = i;
				}
				else if (fld[i][j] == 'G')
				{
					gx = j;
					gy = i;
				}
			}
		}
		
		int mi = INT_MAX / 2, ans;
		for (int i = 0; i < 5; i++)
		{
			q.Clear();
			Data qf;
			
			q.Enqueue(Data(sx, sy, 0, i));
			for (int j = 0; j < 5; j++)
			{
				for (int k = 0; k < H; k++)
				{
					isUsed[j * H + k].reset();
				}
			}
			isUsed[i * H + sy][sx] = true;
			while (q.head != q.tail)
			{
				qf = q.Dequeue();
				//printf("%d, %d, %d\n", qf.x, qf.y, qf.state);
				if (qf.x == gx && qf.y == gy && qf.state == GetPrev(i))
				{
					if (mi > qf.dist)
					{
						mi = qf.dist;
						ans = i;
					}
					break;
				}
				for (int j = 0; j < 4; j++)
				{
					int nx = qf.x + dx[j];
					int ny = qf.y + dy[j];
					if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
					int state = qf.state;
					if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state))
					{
						state = GetNext(state);
					}
					if (isUsed[state * H + ny][nx]) continue;
					isUsed[state * H + ny][nx] = true;
					q.Enqueue(Data(nx, ny, qf.dist + 1, state));
				}
			}
		}
		if (mi == INT_MAX / 2) puts("NA");
		else printf("%d %d\n", ans + 1, mi);
	}
	return 0;
}

Measured memory_bytes: 53008
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N, K, p[1010];
    cin >> N >> K;
    for(int i = 0; i < N; ++i)
        cin >> p[i];
    sort(p, p + N);
    int ans = 0;
    for(int i = 0; i < K; ++i)
        ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,R;
	scan(N>>R);
	if(N>=10) prin(R);
	else prin(R+100*(10-N));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    string s;
    cin >> s;
    int len = s.size();
    int ans = 1000;
    for(int i = 0; i < len-2; i++){
        string n = s.substr(i, 3);
        int diff = abs(753 - stoi(n));
        ans = min(ans, diff);
    }
    cout << ans << endl;
}


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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl

using namespace std;
const int N = 100005;
ll t, n, m, k, q, a, b, x, y, ans, arr[N];
bool vis[N], valid;
ll mod = 998244353;
string s;

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        cin >> x >> y;
        bool ans = false;
        for (int i = 0; i <= 100; ++i) {
            for (int j = 0; j <= 100; ++j) {
                if (i + j == x && 2 * i + 4 * j == y)
                    ans = true;
            }
        }
        if (ans)
            s = "Yes";
        else
            s = "No";
        cout << s << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


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

using namespace std;

int main(void) {
	string input;
	while(1) {
		getline(cin, input);
		if(input == ".") {
			break;
		}

		vector<char> sign;
		for(int i = 0; i < input.size(); i++) {
			if(input[i] == '(') {
				sign.push_back('(');
			}
			if(input[i] == '[') {
				sign.push_back('[');
			}
			if(input[i] == ')') {
				if(sign.empty()) {
					sign.push_back(')');
					break;
				}else if(*(sign.end() - 1) != '(') {
					break;
				}
				sign.pop_back();
			}
			if(input[i] == ']') {
				if(sign.empty()) {
					sign.push_back(']');
					break;
				}else if(*(sign.end() - 1) != '[') {
					break;
				}
				sign.pop_back();
			}
		}

		if(sign.empty()) {
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    std::sort(s.begin(), s.end());
    std::cout << (s[0] == s[1] && s[1] != s[2] && s[2] == s[3] ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
//#define inf 1000000000000000000
using namespace std;
ll mod=1e18;
bool check(long long a,long long b){
    if(a*b<0) return true;
    else return false;
}
string multiply(string num1, string num2) 
{ 
    int len1 = num1.size(); 
    int len2 = num2.size(); 
    if (len1 == 0 || len2 == 0) 
    return "0"; 
  
    // will keep the result number in vector 
    // in reverse order 
    vector<int> result(len1 + len2, 0); 
  
    // Below two indexes are used to find positions 
    // in result.  
    int i_n1 = 0;  
    int i_n2 = 0;  
      
    // Go from right to left in num1 
    for (int i=len1-1; i>=0; i--) 
    { 
        int carry = 0; 
        int n1 = num1[i] - '0'; 
  
        // To shift position to left after every 
        // multiplication of a digit in num2 
        i_n2 = 0;  
          
        // Go from right to left in num2              
        for (int j=len2-1; j>=0; j--) 
        { 
            // Take current digit of second number 
            int n2 = num2[j] - '0'; 
  
            // Multiply with current digit of first number 
            // and add result to previously stored result 
            // at current position.  
            int sum = n1*n2 + result[i_n1 + i_n2] + carry; 
  
            // Carry for next iteration 
            carry = sum/10; 
  
            // Store result 
            result[i_n1 + i_n2] = sum % 10; 
  
            i_n2++; 
        } 
  
        // store carry in next cell 
        if (carry > 0) 
            result[i_n1 + i_n2] += carry; 
  
        // To shift position to left after every 
        // multiplication of a digit in num1. 
        i_n1++; 
    } 
  
    // ignore '0's from the right 
    int i = result.size() - 1; 
    while (i>=0 && result[i] == 0) 
    i--; 
  
    // If all were '0's - means either both or 
    // one of num1 or num2 were '0' 
    if (i == -1) 
    return "0"; 
  
    // generate the result string 
    string s = ""; 
      
    while (i >= 0) 
        s += std::to_string(result[i--]); 
  
    return s; 
} 

int main(){
    string a,b;
    cin>>a>>b;
    int dec=-1;
    for(int i=b.size(); i>=0; i--){
        if(b[i]=='.') {
            dec=b.size()-i-1;
            b.erase(b.begin()+i);
        }
    }
    //cout<<dec<<endl;
    string ans=multiply(a,b);
    //cout<<ans<<endl;
    int count=0;
    int cond=0;
    for(int i=ans.size(); i>=0; i--){
        if(count==dec){
            cond=1;
            for(int j=i; j<ans.size(); j++){
                ans.erase(ans.begin()+j);
                j--;
            }
        }
        count++;
    }
    if(cond==1)
    cout<<ans<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 3684
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
queue<int> pre;
vector<int> in, post;
void reconstruction(int left, int right)
{

	if (left >= right)
		return;
	int root = pre.front();
	pre.pop();
	int idx = distance(in.begin(), find(in.begin(), in.end(), root));
	reconstruction(left, idx);
	reconstruction(idx + 1, right);
	post.push_back(root);
}
int main()
{
	int n;
	cin >> n;
	in.resize(n);
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		pre.push(t);
	}
	for (int i = 0; i < n; i++)
		cin >> in[i];
	reconstruction(0, n);
	for (int i = 0; i < post.size(); i++)
		if (i != post.size() - 1)
			cout << post[i] << " ";
		else
			cout << post[i] << endl;
}


Measured memory_bytes: 3140
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;
 
 
ll n, p;
ll a[2];

ll fac[N], ifac[N];
 
ll powmod(ll b, ll p) {
    if (p == 0) return 1;
    if (p&1) return (b*powmod(b,p-1))%MOD;
    ll a = powmod(b,p>>1);
    return (a*a)%MOD;
}
 
void work() {
    fac[0] = 1;
    rep(i,1,N) fac[i] = (fac[i-1]*i)%MOD;
    ifac[N-1] = powmod(fac[N-1],MOD-2);
    per(i,0,N-1) ifac[i] = (ifac[i+1]*(i+1))%MOD;
}
 
ll choose(ll n, ll k) {
    return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD;
}

void solve() {
    work();
    cin >> n >> p;
    rep(i,0,n) {
        ll c;
        cin >> c;
        a[c&1]++;
    }

    ll ans = 0;

    if (p) {
        for (ll i = 1; i <= a[1]; i+=2)
            ans += choose(a[1],i);
    }
    else {
        for (ll i = 0; i <= a[1]; i+=2)
            ans += choose(a[1],i);        
    }
    ans <<= a[0];
    cout << ans << endl;

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

Measured memory_bytes: 15872
"use strict";

function Main(input) {
  let x = input.trim().split(' ')[0];
  let y = input.trim().split(' ')[1];
  let ans = "";
  if(x > y){
  	ans = y.repeat(x);
  }else {
	ans = x.repeat(y);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<stdio.h>
int main(void){
	int n,i,r=0;
	int p[51];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&p[i]);
		if(p[i]!=i){
			r++;
		}
	}
	printf(r==0||r==2?"YES":"NO");
	return 0;
}


Measured memory_bytes: 1700
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())

lst = [tuple(map(int, input().split())) for _ in range(M)]
lst.sort(key = lambda x: x[1])
lst.sort(key = lambda x: x[0])

#セグメント木
#次の2つの処理をO(log N)で実施することができる
# s, tが与えられた時、区間[s, t)の最小値を求める
# i, xが与えられた時、a_iの値をxに変更する

INIT = 10 ** 18 #初期値 答えに関係ないもの
MAX_N = 10 ** 6 #与えられる要素数の最大
# INIT = 100
data = [INIT] * (2 * MAX_N - 1) #MAX_Nで初期化

#ここに機能をもたせる
def func(vl, vr):
    return min(vl, vr)

def init(n_):
    #簡単のため要素数を2のべき乗に
    n = 1
    while n < n_:
        n *= 2
    return n

# N = int(input()) #配列の数
n = init(N)

def update(k, a): #k番目の値をaに変更 0-index
    # B[a] = k
    k += n - 1
    data[k] = a
    while k > 0: #登りながら更新
        k = (k - 1)//2
        data[k] = func(data[k * 2 + 1], data[k * 2 + 2])

def query(a, b, k = 0, l = 0, r = n):
    if r <= a or b <= l:
        return INIT
    if a <= l and r <= b:
        return data[k]
    else:
        vl = query(a, b, k * 2 + 1, l, (l + r)//2)
        vr = query(a, b, k * 2 + 2, (l + r)//2, r)
        return func(vl, vr)

def initialize(A): #リストAを与えて初期化する
    for i, a in enumerate(A):
        data[i + n - 1] = a
        # B[a] = i
    for i in range((2 * n - 3)//2, -1, -1):
        data[i] = func(data[i * 2 + 1], data[i * 2 + 2])

# def index(a): #要素aがもとのどこに保存されているかを返す関数
#     return B[a]

def value(index): #indexが与えられた時、index番目の値を得る
    return data[index + n - 1]

#初期値の入力
D = [INIT] * N
D[0] = 0
# B = dict() #同じ要素がないのが前提 0-index管理
initialize(D)

#クエリの数
# print (lst)
# print (D)
for a, b, c in lst:
    a -= 1
    b -= 1
    tmp = query(a, b)
    if D[b] > tmp + c:
        D[b] = tmp + c
        update(b, tmp + c)
    # print (D)

# print (D)
print (-1 if D[N - 1] == INIT else D[N - 1])

Measured memory_bytes: 123612
n= int(input())
dic = {}
for i in range(1, n+1):
    s, p = input().split()
    if s in dic.keys():
        dic[s].append((int(p), i))
    else:
        dic[s]=[(int(p), i)]
List = sorted(dic.items())
for li in List:
    ll = sorted(li[1], reverse = True, key = lambda x:x[0])
    for lli in ll:
        print(lli[1])

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

#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(I,N) for(I=0;I<N;++I)
ll n,k;
vector<ll> v,w, memo[101];

ll DP(ll x, ll y)
{
	if(x>=n || y<=0)
		return 0;
	if(memo[x][y]!= -1)
		return memo[x][y];
	ll p = DP(x+1,y);
	if(y >= w[x])
		p = max(p,v[x]+DP(x+1,y-w[x]));
	memo[x][y] = p;
	return memo[x][y];
}

int main()
{
	ll W,i,j,x,y;
	cin>>n>>W;
	FOR(i,n)
	{
		cin>>x>>y;
		w.pb(x);
		v.pb(y);
		FOR(j,W+1)
			memo[i].pb(-1);
	}
	x=max(v[0]+DP(1,W-w[0]),DP(1,W));
	cout<<x;
}

Measured memory_bytes: 79348
import sys
input = sys.stdin.readline
def main():
	N = int(input())
	a = list(map(int,input().split()))
	a.sort(reverse=True)
	sum_list = [a[0]]
	for i in range(N-1):
		sum_list.append(sum_list[i]+a[i+1])
	count = 1
	A = sum(a)
	for i in range(N):
		if (A-sum_list[i])*2 >= a[i]:
			count += 1
		else:
			break

	print(count)

if __name__ == "__main__":
	main()

Measured memory_bytes: 14276
#include <iostream>
#include <string>
#include <vector>
#define MAXN 1000000

using namespace std;

vector <string> p = {
    "dream", "dreamer", "erase", "eraser",
};

bool ok[MAXN];

bool solve() {
    string s;
    cin >> s;

    ok[0] = true;
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 0; j < p.size(); j++) {
            int m = p[j].size();
            if (i >= m && ok[i - m]
                    && s.substr(i - m, m) == p[j]) {
                ok[i] = true;
                break;
            }
        }
    }
    return ok[s.size()];
}

int main() {
    if (solve())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 512
from collections import deque

n=int(input())
q=deque([])

for i in range(n):
    cm=input()
    if cm!="deleteFirst" and cm!="deleteLast":
        cm,x=cm.split()
    
    if cm=="insert":
        q.appendleft(x)
    elif cm=="delete":
        try:
            q.remove(x)
        except:
            continue
    elif cm=="deleteFirst":
        q.popleft()
    else:
        q.pop()
print(*q)


Measured memory_bytes: 69732
N=input()
LL=[]
def find(s):
    count=0
    for i in xrange(len(s)-1):
        if s[i]+s[i+1]=='AB':
            count+=1
    return count        
 
ans=0
start_B=0
end_A=0
same_time=0
for i in xrange(N):
    s=raw_input()
    ans+=find(s)
    if s[-1]=='A':
        end_A+=1
    if s[0]=='B':
        start_B+=1   
    if s[0]=='B' and s[-1]=='A':
        same_time+=1
 
 
#print(ans,end_A,start_B,same_time)
final=ans+min(end_A-same_time,start_B-same_time)
if end_A!=start_B:
    print(final+same_time)
else:
    if end_A-same_time>0:
        print(final+max(same_time,0))
    else:
        print(final+max(same_time-1,0))


Measured memory_bytes: 33640
# -*- coding: utf-8 -*-

"""
・自力AC
・トポロジカルソート
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def topological_sort(N, dag):
    # ここからトポロジカルソート準備
    incnts = [0] * N
    outnodes = [[] for i in range(N)]
    for i in range(len(dag)):
        # 流入するノード数
        incnts[dag[i][1]] += 1
        # 流出先ノードのリスト
        outnodes[dag[i][0]].append(dag[i][1])
    # 流入ノード数が0であるノードのセットS
    S = set()
    for i in range(N):
        if incnts[i] == 0:
            S.add(i)

    # ここからトポロジカルソート
    L = []
    # 暫定セットが空になるまでループ
    while S:
        # 暫定セットから結果リストへ1つ入れる
        L.append(S.pop())
        # 確定させたノードから流出するノードでループ
        for node in outnodes[L[-1]]:
            # 流入ノード数を1減らす
            incnts[node] -= 1
            # 流入ノードが0なら暫定セットへ
            if incnts[node] == 0:
                S.add(node)
    return L

N, M = MAP()
nodes = [[] for i in range(N)]
edges = [None] * M
for i in range(M):
    x, y = MAP()
    nodes[x-1].append(y-1)
    edges[i] = ((x-1, y-1))

# この後の最大値更新で矛盾が生じないようにソートしておく
l = topological_sort(N, edges)

ans = [0] * N
for src in l:
    for dest in nodes[src]:
        ans[dest] = max(ans[dest], ans[src]+1)
print(max(ans))


Measured memory_bytes: 100012
#include<stdio.h>

int main() {
    int W, a, b;
    scanf("%d %d %d", &W, &a, &b);

    if(a+W <= b) {
        printf("%d", b - (a+W));
    } else if((b <= (a+W) && (a+W) <= (b+W)) || (b <= (a+W) && a <= b)){
        printf("0");
    } else {
        printf("%d", a - (b+W));
    }
    return 0;
}

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

#define MAX_N 100
#define MAX_XY 100
typedef long long int ll;

class Data {
public:
  int x;
  int y;
  ll h;

  bool operator<(const Data &d) const {
    return h < d.h;
  }
};

int main() {
  int n;
  Data ds[MAX_N];

  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::cin >> ds[i].x >> ds[i].y >> ds[i].h;
  }
  std::sort(ds, ds + n);

  for(int cx = 0; cx <= MAX_XY; ++cx) {
    for(int cy = 0; cy <= MAX_XY; ++cy) {
      Data d = ds[n - 1];
      ll ch = d.h + std::abs(cx - d.x) + std::abs(cy - d.y);

      bool flg = true;
      for(int i = 0; i < n - 1; ++i) {
        d = ds[i];
        if (d.h != std::max(0LL, ch - (ll) std::abs(cx - d.x) - (ll) std::abs(cy - d.y))) {
          flg = false;
          break;
        }
      }
      if(flg) {
        std::cout << cx << " " << cy << " " << ch << std::endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<functional>

struct ver{
	int key;
	int x;
	int y;
};

struct edge{
	int cost;
	int v1;
	int v2;
};

int main(){
	int n;
	int answer=0;
	std::vector<ver> verList;
	std::vector<std::vector<edge>> edgeList;
	std::priority_queue<edge, std::vector<edge>, std::function<bool(edge, edge)>> qList(
		[](edge a, edge b){return a.cost > b.cost;});

	std::cin>>n;
	verList.resize(n);
	edgeList.resize(n);

	for(int i=0; i<n; i++){
		std::cin>>verList[i].x>>verList[i].y;
		verList[i].key= i;
	}

	std::sort(verList.begin(), verList.end(),
		[](const ver& a, const ver& b){return a.x<b.x;});

	for(int i=1; i<n; i++){
		edgeList[verList[i-1].key].push_back({verList[i].x - verList[i-1].x ,verList[i-1].key, verList[i].key});
		edgeList[verList[i].key].push_back({verList[i].x - verList[i-1].x ,verList[i-1].key, verList[i].key});
	}

	std::sort(verList.begin(), verList.end(),
		[](const ver& a, const ver& b){return a.y<b.y;});

	for(int i=1; i<n; i++){
		edgeList[verList[i-1].key].push_back({verList[i].y - verList[i-1].y ,verList[i-1].key, verList[i].key});
		edgeList[verList[i].key].push_back({verList[i].y - verList[i-1].y ,verList[i-1].key, verList[i].key});
	}


	int edgeCount= 0;
	std::vector<int> isSelected(n, -1);
	isSelected[0]= 1;
	for(int i=0; i< edgeList[0].size(); i++)
		qList.push(edgeList[0][i]);

	while(1){
		if(edgeCount>= n-1)
			break;
		
		edge e= qList.top();
		qList.pop();

		if(isSelected[e.v1] * isSelected[e.v2] >0)
			continue;
		
		if(isSelected[e.v1]<0){
			isSelected[e.v1]= 1;
			answer+=e.cost;
			for(int i=0; i< edgeList[e.v1].size(); i++)
				qList.push(edgeList[e.v1][i]);
			edgeCount++;
		}else if(isSelected[e.v2]<0){
			isSelected[e.v2]= 1;
			answer+=e.cost;
			for(int i=0; i< edgeList[e.v2].size(); i++)
				qList.push(edgeList[e.v2][i]);
			edgeCount++;
		}

	} 
/*------------------------------*/
//	for(int i=0; i< edgeList.size(); i++)
//		std::cout<< edgeList[i].cost<<","<<edgeList[i].v1<<","<<edgeList[i].v2<<std::endl;
	std::cout<<answer<<std::endl;



	return 0;
}

Measured memory_bytes: 15600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>   
 
#define rep(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007
#define N 200005
#define se second
#define fi first
#define pie 3.14159265359
#define pll pair<ll,ll> 
#define pb push_back
#define sz(x) (int)x.size()
#define endl "\n"
 
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
 
typedef long long ll;
using namespace std;

void solve(){
 	ll n;
 	cin >> n;
 	ll a[n+5]={0},b[n+5]={0}; 
 	rep(i,1,n){
 		cin >> b[i];
 	}
 	ll prev = INT_MAX;
 	for(int i = n; i >= 2; i--){
 		a[i] = min(prev,b[i - 1]);
 		prev = b[i-1];
 	}
 	a[1] = prev;
 	prev = 0;
 	rep(i,1,n+1){
 		prev += a[i];
 	}
 	cout << prev << "\n";
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tc=1;
	//cin>>tc;
	while(tc--)solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<int> rsp(n, -1);
    
    lli score = 0;
    for(int i=0; i<n; i++){
        if(i < k){
            // k未満の時は好きな手を選べる
            if(t[i] == 'r'){
                // 相手の手がグーならパーを出して勝つ
                rsp[i] = 2;
                score += p;
            }
            else if(t[i] == 's'){
                // 相手の手がチョキならグーを出して勝つ
                rsp[i] = 0;
                score += r;
            }
            else{
                // 相手の手がパーならチョキを出して勝つ
                rsp[i] = 1;
                score += s;
            }
        }
        else{
            // k以上の時は使えるかどうか調べる
            if(t[i] == 'r'){
                // 相手の手がグーなら
                if(rsp[i-k] != 2){
                    // パーが出せるなら出して勝つ
                    rsp[i] = 2;
                    score += p;
                }
                else{
                    // パーが出せないならk個先を見て影響の無いほうを選ぶ
                    if(i+k > n || t[i+k] == 's'){
                        rsp[i] = 1;
                    }
                    else{
                        rsp[i] = 0;
                    }
                }
            }
            else if(t[i] == 's'){
                // 相手の手がチョキなら
                if(rsp[i-k] != 0){
                    // グーが出せるなら出して勝つ
                    rsp[i] = 0;
                    score += r;
                }
                else{
                    // グーが出せないならk個先を見て影響の無いほうを選ぶ
                    if(i+k > n || t[i+k] == 'p'){
                        rsp[i] = 2;
                    }
                    else{
                        rsp[i] = 1;
                    }
                }
            }
            else{
                // 相手の手がパーなら
                if(rsp[i-k] != 1){
                    // チョキが出せるなら出して勝つ
                    rsp[i] = 1;
                    score += s;
                }
                else{
                    // チョキが出せないならk個先を見て影響の無いほうを選ぶ
                    if(i+k > n || t[i+k] == 'r'){
                        rsp[i] = 0;
                    }
                    else{
                        rsp[i] = 2;
                    }
                }
            }            
        }  
    }
    cout << score << endl;
}

Measured memory_bytes: 848
h,w,k = map(int, input().split())
s = []
Nm = [[0]*w for i in range(h)]
nm = 1
Q = []
empty =[]
for i in range(h):
    si = input()
    s.append(si)
    berry = False
    for j in range(w):
        if si[j]=="#":
            berry = True
            Nm[i][j]=nm
            nm+=1
            Q.append((i,j))
    if not berry:
        empty.append(i)

for i,j in Q:#横に伸ばす
    for t in range(j+1,w):
        if Nm[i][t]==0:
            Nm[i][t]=Nm[i][j]
        else:
            break
    for t in range(j-1,-1,-1):
        if Nm[i][t]==0:
            Nm[i][t]=Nm[i][j]
        else:
            break
if not empty:
    for i in range(h):
        print(*Nm[i])
    exit()
j=0###
if 0 in empty:#下から延ばす必要がある場合
    j = 0
    while empty[j]==j:
        j+=1
        if j<len(empty):
            continue
        else:
            break
    for t in range(j):
        for s in range(w):
            Nm[t][s] = Nm[j][s]
#print(j)
for i in empty[j:]:#縦下に伸ばす
    for j in range(w):
        Nm[i][j] = Nm[i-1][j]

for i in range(h):
    print(*Nm[i])


Measured memory_bytes: 53336
n, m = map(int, input().split())
xyz = [tuple(int(x) - 1 for x in input().split()) for _ in range(m)]


class UnionFind:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def find_root(self, x):
        if self.p[x] != x:
            self.p[x] = self.find_root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def unite(self, x, y):
        u = self.find_root(x)
        v = self.find_root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def get_size(self, x):
        return self.size[self.find_root(x)]

uft = UnionFind(n)
for x, y, z in xyz:
    uft.unite(x, y)

p = set()
for i in range(n):
    p.add(uft.find_root(i))

print(len(p))



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

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

	vector<int> A(N);
	for (int i = 0; i < N; i++)cin >> A[i];

	int Q = 1;

	for (int i = 0; i < N; i++) {
		if (A[Q - 1] == 2) {
			cout << i + 1 << endl;
			return 0;
		}
		else Q = A[Q - 1];

		if (i == N - 1) {
			cout << -1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3732
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll LINF = 1LL << 60;

int V, E, r;
vector<vector<pair<int, int>>> graph;
vector<ll> dist;

bool spfa(int s) {
    dist.assign(V, LINF);
    dist[s] = 0;
    queue<int> que;
    que.push(s);
    vector<bool> in_queue(V);
    vector<int> cnt_update(V, 0);
    cnt_update[s]++;

    while (!que.empty()) {
        int v = que.front(); que.pop();
        in_queue[v] = false;

        for (auto& e : graph[v]) {
            if (dist[v] + e.first < dist[e.second]) {
                dist[e.second] = dist[v] + e.first;

                if (!in_queue[e.second]) {
                    que.push(e.second);
                    in_queue[e.second] = true;

                    cnt_update[e.second]++;
                    if (cnt_update[e.second] == V) return true;
                }
            }
        }
    }

    return false;
}

int main() {
    cin >> V >> E >> r;
    graph.resize(V);
    for (int i = 0; i < E; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        graph[s].emplace_back(d, t);
    }

    bool nc = spfa(r);

    if (nc) {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else {
        for (ll d : dist) {
            if (d == LINF) {
                cout << "INF" << endl;
            }
            else {
                cout << d << endl;
            }
        }
    }
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int alp[27];
int main() {
	int N;
	string S;
	cin >> N >> S;
	for(int i=0; i<N; ++i) ++alp[S[i]-'a'];
	long ans=1, mod=1000000007;
	for(int i=0; i<26; ++i) ans=(ans*(alp[i]+1))%mod;
	cout << ans-1 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;

const int MOD = 1000000007;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator-(mint a) {
  return -a.n + MOD * (a.n != 0);
}
mint operator+(mint a, mint b) {
  int x = a.n + b.n;
  return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
  int x = a.n - b.n;
  return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) {
  return (long long)a.n * b.n % MOD;
}
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

void naive() {
  static mint dp[50][50];
  int N, H, D;
  cin >> N >> H >> D;
  dp[0][N] = 1;
  for (int i = 0; i <= H; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = i + 1; k <= min(H, i + D); k++) {
        dp[k][1] += dp[i][j];
      }
      if (j < N) {
        dp[i][j + 1] += dp[i][j] * (j + 1);
      }
    }
  }
  cout << dp[H][N] << endl;
}

int main() {
  int N, H, D;
  cin >> N >> H >> D;
  mint f = 1;
  mint s = 0;
  for (int i = 1; i <= N; i++) {
    f *= i;
    s += f;
  }
  vector<mint> dp(H + 2); // dp[i][1]
  dp[1] += 1;
  dp[D + 1] -= 1;
  for (int i = 1; i < H; i++) {
    dp[i + 1] += dp[i];
    int l = i + 1;
    int r = min(H + 1, i + D + 1);
    dp[l] += dp[i] * s;
    dp[r] -= dp[i] * s;
  }
  mint ans = dp[H] * f;
  cout << ans << '\n';
}


Measured memory_bytes: 4096
// Nurstan Duisengaliev
// ASA KONKRETNO KATAIMASH

/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/                   
      
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
 
using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;                         

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;

void solve () {
	int x;
	cin >> x;
	cout << 1 - x ;
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 3652
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args) {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
      String[] sArr = in.readLine().split(" ");
      int num = 10*Integer.parseInt(sArr[1])+Integer.parseInt(sArr[2]);
      if(num%4==0){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }

    }catch(IOException e){
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 21204
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
//------------------------------>> coding space <<------------------------------//



int main() {
	lint Q, H, S, D, N;
	cin >> Q >> H >> S >> D;
	cin >> N;
	
	lint R = min(Q * 4, min(H * 2, S));
	
	if (2 * R <= D) {
		cout << N * R << endl;
	} else {
		if (N % 2 == 0) cout << N / 2 * D << endl;
		else cout << N / 2 * D + R << endl;
	}
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int n , c;

const int N = 505;

int l[N];

double f[N][2 << 7] , ans , t;

int main(){
	cin >> n >> c;
	for(int i = 0; i < n; i++)
		cin >> l[i];
	sort(l , l + n);
	do{
		memset(f, 0, sizeof(f));
        f[l[n - 1] * n][0] = 1;
        for(int i = 0; i <= n * c; i++)
            for(int j = i; j <= n * c; j++)
                for(int S = 0; S < (1 << n - 1); S++)
                    if(i % n && !((S >> (i % n - 1)) & 1))
                        f[min(n * c, max(j, i + l[i % n - 1] * n))][S | (1 << (i % n - 1))] += f[j][S];
        ans += f[n * c][(1 << n - 1) - 1];
        ++t;
	}while(next_permutation(l , l + n - 1));
	printf("%.15lf" , (double)ans / t / pow(c , n - 1));
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

typedef long long ll;

using namespace std;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    long long X[N]; 
    long long SX[N];
    for (int i = 0; i < N; ++i) {
        long long x; cin >> x;
        X[i] = SX[i] = x;
    }

    sort(SX, SX+N);

    for (int i = 0; i < N; ++i) {
        if (X[i] <= SX[N/2-1]) cout << SX[N/2] << endl;
        else cout << SX[N/2-1] << endl;
    }
}


Measured memory_bytes: 5376
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    long long a = 0;
    for ( int i = 0 ; i < ( 1 << ( s.length() - 1 ) ) ; i++ ) {
        long long b = s[0] - '0';
        for ( int j = 1 ; j < s.length() ; j++ ) {
            if ( i & ( 1 << ( j - 1 ) ) ) {
                a += b;
                b = s[j] - '0';
            } else {
                b = b * 10 + s[j] - '0';
            }
        }
        a += b;
    }
    cout << a << endl;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2249

//
//  main.cpp
//

#include <iostream>
#include <algorithm>
#include <vector>
//#include <limits>
#include <math.h>
#include <queue>
//#include <tuple>
//#include <stdio.h>
//#include <stdlib.h>
//#include <string>
//#include "string.h"
#include <unordered_map>
#include <map>
#include <unordered_set>
//#include <array>
#include <set>
#include <limits>

using namespace std;

using ll = long long;

int main() {
    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 && M == 0) {
            return 0;
        }
        struct Edge {
            int to;
            int dist;
            int cost;
            Edge(int to, int dist, int cost) : to(to), dist(dist), cost(cost) {}
        };
        vector<vector<Edge>> graph(N, vector<Edge>());
        for (int i = 0; i < M; i++) {
            int u,v,d,c;
            cin >> u >> v >> d >> c;
            u--;
            v--;
            graph[u].emplace_back(v, d, c);
            graph[v].emplace_back(u, d, c);
        }
        struct P {
            int idx;
            int dist;
            int cost;
            P(int idx, int dist, int cost) : idx(idx), dist(dist), cost(cost) {};
        };
        struct GreaterP {
            bool operator()(const P& lhs, const P& rhs) {
                return lhs.dist > rhs.dist || (lhs.dist == rhs.dist && lhs.cost > rhs.cost);
            }
        };
        priority_queue<P, vector<P>, GreaterP> queue;
        int totalCost = 0;
        vector<bool> reached(N, false);
        vector<int> distances(N, numeric_limits<int>::max() / 2);
        queue.emplace(0, 0, 0);
        distances[0] = 0;
        while (!queue.empty()) {
            P p = queue.top();
            queue.pop();
            if (reached[p.idx]) {
                continue;
            }
            reached[p.idx] = true;
            totalCost += p.cost;
            for (Edge& e : graph[p.idx]) {
                if (distances[p.idx] + e.dist <= distances[e.to]) {
                    distances[e.to] = distances[p.idx] + e.dist;
                    queue.emplace(e.to, distances[e.to], e.cost);
                }
            }
        }
        cout << totalCost << endl;
    }
    return 0;
}





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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int n;

    cin >> n;

    vi v(n);
    vi dp(n);

    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        if(i == 0)
        {
            dp[i] = v[i];
        }

        else
        {
            dp[i] = min(dp[i - 1], v[i]);
        }
    }

    int brojac = 0;

    for(int i = 0; i < n; i++)
    {
        if(v[i] <= dp[i])
        {
            brojac++;
        }
    }

    cout << brojac << '\n';

    return 0;
}


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

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

const int N=(1<<20);
int dat[1<<21];
int lazy[1<<21];

void lazy_upd(int k,int l,int r){
	dat[k]+=lazy[k]*(r-l);
	if(k<N-1){
		lazy[k*2+1]+=lazy[k];
		lazy[k*2+2]+=lazy[k];
	}
	lazy[k]=0;
}

void lazy_calc(int k){
	dat[k]=dat[k*2+1]+dat[k*2+2];
}

void add(int a,int b,int x,int k=0,int l=0,int r=N){
	lazy_upd(k,l,r);
	if(r<=a || b<=l)return;
	if(a<=l && r<=b){
		lazy[k]+=x;
		lazy_upd(k,l,r);
		return;
	}
	add(a,b,x,k*2+1,l,(l+r)/2);
	add(a,b,x,k*2+2,(l+r)/2,r);
	lazy_calc(k);
}

int query(int a,int b,int k=0,int l=0,int r=N){
	lazy_upd(k,l,r);
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	int vl=query(a,b,k*2+1,l,(l+r)/2);
	int vr=query(a,b,k*2+2,(l+r)/2,r);
	lazy_calc(k);
	return vl+vr;
}

vector<int> xi;
int n;
int x[1000001];

bool check(int v){
	if(query(0,1)==1)return false;
	int v1=query(1,v+1);
	int v2=query(v+1,N);
	if(v1==v && v2>0)return false;
	return true;
}

void puts(int v){
	int l=0,r=v+1;
	while(l+1<r){
		int mid=(l+r)/2;
		if(query(mid,v+1)==v+1-mid)r=mid;
		else l=mid;
	}
	add(r,v+1,-1);
	add(r-1,r,1);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
		xi.push_back(x[i]);
	}
	for(int i=0;i<=500000;i++){
		xi.push_back(i);
	}
	sort(xi.begin(),xi.end());
	xi.erase(unique(xi.begin(),xi.end()),xi.end());
	for(int i=0;i<n;i++){
		x[i]=lower_bound(xi.begin(),xi.end(),x[i])-xi.begin();
	}
	for(int i=0;i<n;i++){
		if(check(x[i])){
			printf("Yes\n");
			puts(x[i]);
		}else{
			printf("No\n");
		}
	}
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::map<int, int> ma;
	int res = 1;
	for (int i = 0; i < n; i++){
		int a = ri();
		if (i && !a) res = 0;
		if (!i && a) res = 0;
		ma[a]++;
	}
	int prev = -1, cnt = 1;
	for (auto i : ma) {
		if (i.first != prev + 1) res = 0;
		prev = i.first;
		for (int j = 0; j < i.second; j++) res = (int64_t) res * cnt % 998244353;
		cnt = i.second;
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 4992