akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define xx first
#define yy second

const int N = 2001;
const int mod = 1e9 + 7;

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

int dp[N][N];
string a[N];

void solve() {
    int h, w; cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> a[i];
    for (int i = 0; i < h; i++)
        fill(dp[i], dp[i] + w, 0);
    
    auto bnd = [&](int x, int y) {
        return x < h && y < w;
    };
    dp[0][0] = 1;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            for (int k = 0; k < 2; k++) {
                int x = i + dx[k];
                int y = j + dy[k];
                if (!bnd(x, y)) continue;
                if (a[x][y] == '#') continue;
                dp[x][y] = (dp[x][y] + dp[i][j]) % mod;
            }
    cout << dp[h - 1][w - 1] << '\n'; 
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 12472
#include<stdio.h>

int main()
{
	long long n,m,count=0;
	scanf("%lld %lld",&n,&m);
	if(m-n*2<=0)
	count=m/2;
	else
	{
		count+=n;
		m=m-2*n;
		count+=m/4;
	}
	printf("%lld",count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    int x;
    scanf("%d", &x);
    vector<int> v(n);
    for (int &a : v) scanf("%d", &a);
    sort(v.begin(), v.end());

    int ans = 0;
    while (ans < n && x >= v[ans]) {
      x -= v[ans];
      ans++;
    }
    if (ans == n && x > 0) {
      ans--;
    }
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
s=[list(input()) for i in range(n)]
abc=list('abcdefghijklmnopqrstuvwxyz')
ans=''
for i in range(26):
  tmp=10*8
  for j in range(n):
    tmp=min(tmp,s[j].count(abc[i]))
  ans+=abc[i]*tmp
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long cum [ 100001];

int main(){
        int n , m ,time ; 
        cin>>n>>m>>time ; 
        int a[n],b[m];
        for(int i =0;i<n;i++)cin>>a[i];
        for(int i =0;i<m;i++)cin>>b[i];
        vector<long long> v ; 
        long long sum = 0 , Max=0 ; 
        for(int i =0;i<m;i++){
                sum+=b[i];
                if(sum<=time)Max=i +1; 
                v.push_back(sum);
        }
       
        long long int M=m-1;
        sum=0; 
        for(int i =0;i<n;i++){
                sum+=a[i]; 
                if(sum>time){
                        Max = max(1ll*i,Max ) ; 
                        break ;} 
                if(sum==time){
                          Max = max(1ll*i+1,Max ) ; 
                        break ;
                }   
                while(M>=0){
                        if(sum+v[M]<=time){
                        
                                Max=max(Max,i+M+2);
                                        break;
                                
                        }
                        
                 M-- ;}
              //  cout<<sum+v[M]<<" "; 
                
        }cout<<Max ;  
        
        
}

Measured memory_bytes: 6940
<?php
//標準入力一行取得
$length = trim(fgets(STDIN));
$dice_result = [];
for($i = 0; $i < $length; $i++){
    //空白区切りの標準入力取得
    $stdin = explode(' ',trim(fgets(STDIN)));
    $dice_result[$i][0] = $stdin[0];
    $dice_result[$i][1] = $stdin[1];
}
$continue_dice = 0;
$stdout = 'No';
foreach ($dice_result as $value){
    if($value[0] === $value[1]){
        ++$continue_dice;
        if($continue_dice === 3){
            $stdout = 'Yes';
            break;
        }
    }else{
        $continue_dice = 0;
    }
}
echo $stdout;
?>


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

using namespace std;
typedef long long ll;

template <int MD>
struct ModInt {
    typedef ModInt M;
    int v;
    ModInt(int _v = 0) : v(_v) {}
    M& operator += (const M &r) {
        if ((v += r.v) >= MD) v -= MD;
        return *this;
    }
    M& operator *= (const M &r) {
        v = ll(v) * r.v % MD;
        return *this;
    }
    M& operator -= (const M &r) {
        if ((v -= r.v) < 0) v += MD;
        return *this;
    }
    M operator + (const M &r) const { return M(*this) += r; }
    M operator * (const M &r) const { return M(*this) *= r; }
    M operator - (const M &r) const { return M(*this) -= r; }
    M pow(int n) const { 
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return this->pow(MD - 2); }
};
typedef ModInt<1000000007> Mint;

const int MN = 233333;
int h, w, a, b;
Mint fac[MN], ifac[MN];

void first() {
    fac[0] = 1;
    for (int i = 1; i < MN; i++) {
        fac[i] = fac[i - 1] * Mint(i);
    }
    ifac[MN - 1] = fac[MN - 1].inv();
    for (int i = MN - 2; i >= 0; i--) {
        ifac[i] = ifac[i + 1] * Mint(i + 1);
    }
}

Mint C(int x, int y) {
    if (x < 0 || y < 0 || x < y) return Mint(0);
    return fac[x] * ifac[y] * ifac[x - y];
}

int main() {
    first();
    cin >> h >> w >> a >> b;
    Mint ans = C(h + w - 2, h - 1);
    for (int x = 1; x <= b; x++) {
        ans -= C(h - a + x - 2, x - 1) * C(a - 1 + w - x, a - 1);
    }
    cout << ans.v << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	int al[26] = {0};
	cin >> s;

	if(s == "zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << endl;
		return 0;
	}

	for(int i = 0; i < s.length(); i++){
		al[s[i]-'a']++;
	}

	if(s.length() != 26){
		for(int i = 0; i < 26; i++){
			if(al[i] == 0){
				s += (i+'a');
				break;
			}
		}
	}else{
		for(int i = 24; i >= 0 ; i--){
			if(s[i] - 'a' < s[i+1] -'a'){
				//cout << s[i] << endl;
				char c = s[i];
				//cout << c << endl;
				bool flag = false;
				for(int j = 25; j > i; j--){
					if(!flag){
						if(c < s[j]){
							c = s[j];
							flag = true;
						}
					}else{
						if(c > s[j]) c = s[j];
					}
				}
				s[i] = c;
				string t;
				for(int j = 0; j <= i; j++){
					t += s[j];
				}
				s = t;
				break;
			}
		}
	}



	cout << s << endl;

  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int N;
	int M;
	int px_R,py_R;
	int all_gem;
	int ope;
	std::string move;

	cin >> N;
	
	while (N != 0) {
		all_gem = 1;
		px_R = 10;
		py_R = 10;
		int *gem_x = new int[ N ];
		int *gem_y = new int[ N ];
		int *gem = new int[ N ];

		int px_G,py_G;
		for (int i = 0; i < N; i++) {
			cin >> gem_x[i];
			cin >> gem_y[i];
			gem[i] = 1;
		}

		cin >> M;
		for (int i = 0; i < M; i++) {
			cin >> move;
			cin >> ope;

			if (move == "N") {
				for (int j = 0; j < N; j++) {
					if (gem[j]) {
						if (gem_x[j] == px_R) {
							if (gem_y[j] >= py_R && gem_y[j] <= (py_R+ope)) {
								gem[j] = 0;
							}
						}
					}
				}
				py_R += ope;
			}
			if (move == "S") {
				for (int j = 0; j < N; j++) {
					if (gem[j]) {
						if (gem_x[j] == px_R) {
							if (gem_y[j] <= py_R && gem_y[j] >= (py_R-ope)) {
								gem[j] = 0;
							}
						}
					}
				}
				py_R -= ope;
			}
			if (move == "E") {
				for (int j = 0; j < N; j++) {
					if (gem[j]) {
						if (gem_y[j] == py_R) {
							if (gem_x[j] >= px_R && gem_x[j] <= (px_R+ope)) {
								gem[j] = 0;
							}
						}
					}
				}
				px_R += ope;
			}
			if (move == "W") {
				for (int j = 0; j < N; j++) {
					if (gem[j]) {
						if (gem_y[j] == py_R) {
							if (gem_x[j] <= px_R && gem_x[j] >= (px_R-ope)) {
								gem[j] = 0;
							}
						}
					}
				}
				px_R -= ope;
			}
		}
		for (int i = 0; i < N; i++) {
			if (gem[i] == 1){
				all_gem = 0;
				break;
			}
		}
		if (all_gem) {
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
		
		cin >> N;
		delete[] gem_x;
		delete[] gem_y;
		delete[] gem;
	}
	return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( a % 10 == 7 || a / 10 % 10 == 7 || a / 100 % 10 == 7 ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << ((floor(a / 2) + fmod(a, 2)) / a) << endl;
    
    return 0; 
}


Measured memory_bytes: 3632
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	long h = read.to!long;
	long w = read.to!long;
	
	long ans = long.max;
	long p;
	
	p = p1(h, w); if(p < ans) ans = p;
	p = p2(h, w); if(p < ans) ans = p;
	p = p3(h, w); if(p < ans) ans = p;
	p = p4(h, w); if(p < ans) ans = p;
	p = p5(h, w); if(p < ans) ans = p;
	p = p6(h, w); if(p < ans) ans = p;
	p = p7(h, w); if(p < ans) ans = p;
	p = p8(h, w); if(p < ans) ans = p;
	
	ans.writeln;
	}

long p1(long h, long w){
	long a = (h / 3) * w;
	long b = (h / 3) * w;
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p2(long h, long w){
	long a = h * (w / 3);
	long b = h * (w / 3);
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p3(long h, long w){
	long a = (h / 3) * w;
	long b = (h - h / 3) * (w / 2);
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p4(long h, long w){
	long a = h * (w / 3);
	long b = (h / 2) * (w - w / 3);
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p5(long h, long w){
	long a = ((h + 2) / 3) * w;
	long b = (h - (h + 2) / 3) * (w / 2);
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p6(long h, long w){
	long a = h * ((w + 2) / 3);
	long b = (h / 2) * (w - (w + 2) / 3);
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p7(long h, long w){
	long a = ((h + 2) / 3) * w;
	long b = ((h + 2) / 3) * w;
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}

long p8(long h, long w){
	long a = h * ((w + 2) / 3);
	long b = h * ((w + 2) / 3);
	long c = h * w - a - b;
	return max(a, b, c) - min(a, b, c);
	}



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

int main(){
	int num;
	double w, h, bmi;
	vector<int> seito;
	while(scanf("%d,%lf,%lf", &num, &w, &h) != EOF){
		bmi = (double)w/h/h;
		if(25.0<=bmi){
			seito.push_back(num);
		}
	}
	for(int i=0;i<seito.size();i++){
		cout<<seito[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include<iostream>

using namespace std;

int main() {

	int a,b;
	cin >> a >> b;
	
	int n = b - a;
	int sum = 0;
	for (int i = 1; i < n; i++) {
		sum += i;
	}
	int x = sum - a;

	cout << x;
	return 0;
}

Measured memory_bytes: 256
C = 3.times.map{[]}
3.times do |i|
  C[i] = gets.split.map(&:to_i)
end
N = 100
ans = 'No'
0.step 100 do |a1|
  b1 = C[0][0] - a1
  a2 = C[1][0] - b1
  a3 = C[2][0] - b1
  if [C[0][1] - a1, C[1][1] - a2, C[2][1] - a3].uniq.size == 1
    if [C[0][2] - a1, C[1][2] - a2, C[2][2] - a3].uniq.size == 1
      ans = 'Yes'
      break
    end
  end
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	int h, a;
	cin >> h >> a;
	int ans = h / a;
	if (h % a != 0) ans++;
	cout << ans << endl;
}

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

Measured memory_bytes: 256
import kotlin.math.*

fun main() {
    val input = readLine()!!.split(' ').map { it.toDouble() }
    println(a(input[0], input[1], theta(input[2], input[3])))
}

fun theta(h: Double, m: Double): Double {
    val md = m / 60
    val hd = h / 12
    val hTheta = 2 * PI * (hd + md / 12)
    val mTheta = 2 * PI * md
    return abs(hTheta - mTheta).let { if (it > PI) 2 * PI - it else it }
}

fun a(b: Double, c: Double, theta: Double): Double = sqrt(b.pow(2) + c.pow(2) - 2 * b * c * cos(theta))

Measured memory_bytes: 36616
t[999];main(T,W,N,w,c,i,j,m){for(;scanf("%d%d",&W,&N)>1;printf("Case %d:\n%d\n%d\n",T++,m-1,i)){
for(memset(t,0,sizeof(t)),t[0]=1,i=0;i<N;i++)
	for(scanf("%d,%d",&c,&w),j=W;j>=0;j--)if(t[j])if(t[j+w]<t[j]+c)t[j+w]=t[j]+c;
for(m=j=0;j<=W;j++)if(m<t[j])m=t[j],i=j;
}exit(0);}

Measured memory_bytes: 604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int min_cnt[26];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 26; i++) min_cnt[i] = 1 << 30;
	for (int i = 0; i < n; i++) {
		string S;
		cin >> S;
		int cnt[26] = {};
		for (int j = 0; j < S.size(); j++) cnt[S[j] - 'a']++;
		for (int j = 0; j < 26; j++) min_cnt[j] = min(min_cnt[j], cnt[j]);
	}
	string ans = "";
	for (int i = 0; i < 26; i++) {
		ans += string(min_cnt[i], 'a' + i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#Biginner Contest 157 B-Bingo
#二次元配列を使う(3*3)
bingonum=[[0,0,0],[0,0,0],[0,0,0]]
bingo=[["False","False","False"],["False","False","False"],["False","False","False"]]
for i in range(3):
    bingonum[i][0],bingonum[i][1],bingonum[i][2] = map(int,input().split())

N = int(input())
b=[]
for _ in range(N):
    b.append(int(input()))

for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"

IsBingo = "No"
for i in range(3):
    if bingo[i][0] =="True" and bingo[i][1] =="True" and bingo[i][2] =="True":
        IsBingo="Yes"
    elif bingo[0][i] =="True" and bingo[1][i] =="True" and bingo[2][i] =="True":
        IsBingo="Yes"
if (bingo[0][0] =="True" and bingo[1][1] =="True" and bingo[2][2] =="True") or (bingo[0][2] =="True" and bingo[1][1] =="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)



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

int main() {
	long long N, K, A[500], SUM = 0;
	vector<long long> V;
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i], SUM += A[i];
	sort(A, A + N);
	for (long long i = 1; i * i <= SUM; i++) {
		if (SUM % i == 0) {
			if (i != SUM / i) V.push_back(i), V.push_back(SUM / i);
			else V.push_back(i);
		}
	}
	sort(V.begin(), V.end(), greater<long long>());
	for (int i = 0; i < V.size(); i++) {
		long long X = V[i], B[500], C[500], COUNT = 0, Cur = 0;
		for (int j = 0; j < N; j++) B[j] = A[j];
		sort(B, B + N, [&](long long P, long long Q) {return P % X < Q % X; });
		for (int j = 0; j < N; j++) {
			C[j] = (B[j] / X) * X;
			Cur += C[j];
		}
		for (int j = N - 1; j >= 0; j--) {
			if (Cur < SUM) {
				C[j] += X;
				Cur += X;
			}
		}
		for (int j = 0; j < N; j++) COUNT += abs(B[j] - C[j]);
		if (COUNT <= K * 2) {
			cout << X << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
ans = 0
min = float("INF")
for i in range(n):
    x = t - h[i] * 0.006
    if abs(a - x) < min:
        min = abs(a - x)
        ans = i
print(ans + 1)

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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define pii pair<int, int>
#define ll long long

struct state {
	string s;
	int c, p;
	state(){}
	state(string _s, int _c, int _p): s(_s), c(_c), p(_p) {}
};

queue<state> que;
int pz[2][4];
map<string, int> pz_ans;

void bfs()
{
	string s = "01234567";
	pz_ans.insert(mp(s,1));
	state st(s,1,0);
	que.push(st);
	int cnt, pos;

	while(!que.empty()) {
		st = que.front(); que.pop();
		s = st.s;
		cnt = st.c;
		pos = st.p;
		rep(i,0,2) rep(j,0,4) pz[i][j] = s[i*4+j];
		int y = pos/4;
		int x = pos%4;

		if (pos%4) { // left swap
			swap(pz[y][x], pz[y][x-1]);
			rep(i,0,8) s[i] = char(pz[i/4][i%4]);
			if (pz_ans[s] == 0) {
				pz_ans[s] = cnt;
				state t(s,cnt+1,pos-1);
				que.push(t);
			}
			swap(pz[y][x], pz[y][x-1]);
		}

		if (pos%4 < 3) { // right swap
			swap(pz[y][x], pz[y][x+1]);
			rep(i,0,8) s[i] = char(pz[i/4][i%4]);
			if (pz_ans[s] == 0) {
				pz_ans[s] = cnt;
				state t(s,cnt+1,pos+1);
				que.push(t);
			}
			swap(pz[y][x], pz[y][x+1]);
		}

		if (pos/4) { // up swap
			swap(pz[1][x], pz[0][x]);
			rep(i,0,8) s[i] = char(pz[i/4][i%4]);
			if (pz_ans[s] == 0) {
				pz_ans[s] = cnt;
				state t(s,cnt+1,pos-4);
				que.push(t);
			}
			swap(pz[1][x], pz[0][x]);
		}

		if (pos/4 == 0) { // down swap
			swap(pz[0][x], pz[1][x]);
			rep(i,0,8) s[i] = char(pz[i/4][i%4]);
			if (pz_ans[s] == 0) {
				pz_ans[s] = cnt;
				state t(s,cnt+1,pos+4);
				que.push(t);
			}
			swap(pz[0][x], pz[1][x]);
		}
	}
	s = "01234567";
	pz_ans.erase(s);
	pz_ans[s] = 0;
}

void input()
{
	string str;
	while(getline(cin,str)) {
		string::iterator end_it = remove(str.begin(), str.end(), ' ');
		str.erase(end_it, str.end());
		cout << pz_ans[str] << endl;
	}
}

int main(void)
{
	bfs();
	input();
	return 0;
}

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

int main(void) {
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }
    int ans = 0;
    int active = 0;
    for(int i = 0; i < N; i++) {
        if(active > h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n,a,b;cin>>n>>a>>b;
  if((n == 1 && a != b)||(a > b)){
	cout << 0 << endl;
    return 0;
  }
  if(n < 3){
    cout << 1 << endl;
    return 0;
  }
  long long ans = (long long)(n-2)*(b-a) + 1;
  if(ans < 0)cout << 0 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
void solve() 
{
	ll n, maxi=0;
	cin>>n;
	string s;
	map<string,ll> mapa;
	rep(i,0,n){
		cin>>s;
		mapa[s]++;
		maxi=max(maxi,mapa[s]);
	}
	for(auto x : mapa)
		if(x.se==maxi)cout<<x.fi<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 25856
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 19 11:55:12 2020

@author: 17664
"""
coffee = input()

ans = 'Yes'

if coffee[2] != coffee[3]:
    ans = 'No'
if coffee[4] != coffee[5]:
    ans = 'No'
    
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	long long a;
	long long b;
	long long c;
	long long d;
	
	cin >> a >> b >> c >>d;
	long long max1 = std::max(a * c, a * d);
	long long max2 = std::max(b * c, b * d);
	long long maxf = std::max(max1, max2);
	
	std::cout << maxf <<std::endl;
	
	
	return 0;
}


Measured memory_bytes: 3604
from collections import deque
from itertools import product


#幅優先探索
def bfs(s,x, y):
    
    INF=400
    #周囲の探索に必要
    DX = [1, 0, -1, 0]
    DY = [0, 1, 0, -1]
    
    que = deque() #キュー（配列と同じ：前後からの取り出しの高速化が可能）
    res = 0
    dist = [[INF for _ in range(W)] for _ in range(H)]
 
    que.append((x, y))
    dist[x][y] = 0
    while que:
        x, y = que.pop()
        res = max(res, dist[x][y])
 
        for i in range(4):
            dx, dy = x + DX[i], y + DY[i]
 
            if dx < 0 or dx >= H or dy < 0 or dy >= W:
                continue
            if s[dx][dy] == "#":
                continue
 
            if dist[dx][dy] == 400:
                dist[dx][dy] = dist[x][y] + 1
                que.appendleft((dx, dy))
    return res
 
if __name__=="__main__":
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]


    #全部のスタート地点でbfsを行い、その時の最大を取得
    #product　デカルト積　二つの配列の全ての組み合わせを返す
    ans = 0
    for x, y in product(range(H), range(W)):
        if S[x][y] == "#":
            continue
        ans = max(ans, bfs(S,x, y))
    print(ans)

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N;
int a[1100][1100];
signed main() {
    cin >> N;
    int n = 1, c = 1;
    while (n < N) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                a[i + n][j + n] = a[i][j];
                a[i + n][j] = c;
                a[i][j + n] = c;
            }
        }
        c++;
        n *= 2;
    }
    for (int i = 1; i < N; i++) {
        for (int j = i + 1; j <= N; j++) {
            cout << a[i][j] <<
            " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e6 + 5 ; 
int n, a[N], w[10], bk[10] ; 
char s[N] ; 
signed main()
{
	n = gi() ; int m = n - 1 ; 
	scanf("%s", s + 1 ) ;
	rep( i, 1, n ) a[i] = s[i] - '1' ; 
	rep( i, 1, n ) {
		bk[a[i]] = 1 ; 
		if( ( ( i - 1 ) & m ) != ( i - 1 ) ) continue ; 
		w[a[i]] ^= 1 ; 
	}
	if( w[1] ) {
		puts("1") ; exit(0) ; 
	}
	if( w[2] && ( !bk[1] ) ) {
		puts("2") ; exit(0) ;
	}
	puts("0") ; 
	return 0 ;
} 


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

int main(){
  int s,a[4];
  cin >> s;
  for(int i=0;i<4;i++){
    a[i] = s%10;
    s /= 10;
  }
  if(a[0] != a[1] && a[1] != a[2] && a[2] != a[3])cout << "Good" << endl;
  else cout << "Bad" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, q int
	fmt.Scan(&n)
	a := make([]int, n)
	count := make(map[int]int, n)
	ans := 0
	for i, _ := range a {
		fmt.Scan(&a[i])
		count[a[i]]++
		ans += a[i]
	}
	fmt.Scan(&q)
	b := make([]int, q)
	c := make([]int, q)
	for i, _ := range b {
		fmt.Scan(&b[i], &c[i])
	}

	for i := 0; i < q; i++ {
		ans -= b[i] * count[b[i]]
		ans += c[i] * (count[b[i]])
		tmp := count[b[i]]
		count[b[i]] = 0
		count[c[i]] += tmp
		fmt.Println(ans)
	}
}

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

int main() {
  int N, M;
  cin >> N;
 
  vector <int> time(N);
  for (int i; i < N; i++) 
    cin >> time.at(i);
  
  int sum_time = 0;
  for (int i = 0; i < N; i++) 
    sum_time += time.at(i);
  
  cin >> M;
  vector <int> dp(M);
  vector <int> dt(M);
  for (int i = 0; i < M; i++)
   cin >> dp.at(i) >> dt.at(i);
  
  int d_sum = 0;
  for (int i = 0; i < M; i++){
   d_sum = sum_time - time.at(dp.at(i)-1) + dt.at(i);
   cout << d_sum << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int hughug(string hu,int len){
  int A;
  A=len/2+len%2;
  int hugcount=0;
  for(int i=0,j=len-1;i<A;i++,j--){
    if(hu[i]!=hu[len-1-i]){
      hugcount++;
    }
  }
  
  return hugcount;
}



int main(){
  int len,hug;
  string InStr;
  
  cin >> InStr;
  
  len=InStr.size();
  hug=hughug(InStr,len);
  
  cout << hug << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
int main(){
  ll n;
  cin >> n;
 
  ll res = 0;
 
  for (ll r = 1; r * r <= n; r++) {
    if ((n - r) % r == 0 && (n - r)/r > r) res += (n-r)/r;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++)
    {
        int n;
        cin >> n;
        a[i] = make_pair(n, i + 1);
    }

    SortAsc(a);

    for (int i = 0; i < n; i++)
    {
        auto p = a[i];
        if (i != 0)
        {
            cout << " ";
        }
        cout << p.second;
    }

    cout << endl;
}

Measured memory_bytes: 3988
x, a, b = (int(y) for y in input().split())
n = int(input())

for i in range(n):
    s = input()
    if s[0] == "n" :
        x = max(0,x + a)
    elif s[0] == "t" :
        x = max(0,x + b)
    else:
        x = 0
print(x)


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

//#define plong pair<long,long>;
using plong=pair<long,long>;

int main(){
  int N;cin>>N;
  long K;cin>>K;
  vector<plong> A(N);
  for(int i=0;i<N;i++){
    long X,Y;cin>>X>>Y;
    A.at(i)=make_pair(X,Y);
  }
  sort(A.begin(),A.end());
  int X=0;
  long count=0;
  int ans=1;
  while(true){
    while(true){
      if(A.at(X).first!=ans) break;
      count+=A.at(X).second;
      if(count>=K) break;
      X++;
    }
    if(count>=K) break;
    ans++;
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 4848
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    SC = [il() for _ in range(M)]

    for n in range(pow(10, N)):
        tmp = str(n)
        if len(tmp) == N and all(tmp[s - 1] == str(c) for s, c in SC):
            print(n)
            exit()
    else:
        print(-1)


if __name__ == '__main__':
    main()


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

// int N = 4;
// vector<int> a = {20, 18, 2, 18};

int N;


int main() {
    cin >> N;

    vector<int> a(N);
    rep(i, N) {
        cin >> a[i];
    }

    int alice = 0;
    int bob = 0;

    sort(a.begin(), a.end(), greater<int>());
    for (int i = 0; i < a.size(); i++) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    cout << alice - bob << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer writer.Flush()
	n, k, q := scanInt(), scanInt(), scanInt()
	a := make(map[int]int, q)
	for i := 0; i < q; i++ {
		a[scanInt()]++
	}

	for i := 0; i < n; i++ {
		v, ok := a[i+1]
		if !ok {
			v = 0
		}
		if (k - q + v) > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}

func fact(n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= i
	}
	return ret
}

func perm(n, r int) int {
	ret := 1
	for i := 0; i < r; i++ {
		ret *= n
		n--
	}
	return ret
}

func isPrimeNum(n int) bool {

	if n <= 1 {
		return false
	}

	l := int(math.Sqrt(float64(n)) + 1.)
	for i := 2; i < l; i++ {
		if n%i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()

int main() {
  int n;
  cin >> n;
  vector<char> c(n);
  for(int i=0;i<n;i++){
  	cin >> c[i];
  }
  ll count=0;
  for(int i=0;i<n;i++){
  	if(c[i]=='R'){count++;}
  }
  ll co=0;
  for(int i=0;i<count;i++){
  	if(c[i]=='R'){co++;}
  }
  cout << count - co << endl;
}



Measured memory_bytes: 3640
//
// Created by yamunaku on 2019/07/30.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int a,b;
    cin >> a >> b;
    if((a-b)%2==0){
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

Scanner keyboard = new Scanner(System.in);
int N, K, R;

N = keyboard.nextInt();
K = keyboard.nextInt();
R = N % K;

if (R == 0) {
System.out.println("0");
} else {
System.out.println("1");
}
keyboard.close();
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> cnt(n, 1);
  vector<bool> ans(n);
  ans[0] = true;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    if(ans[x]) {
      if(cnt[x] == 1) ans[x] = false, ans[y] = true;
      else ans[y]= true;
    }
    cnt[x]--; cnt[y]++;
  }
  cout << accumulate(all(ans), 0) << endk;
  return 0;
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,p,i,j,ans=1,r;
	cin>>p>>n;
	for (i=2;i*i<=n;i++){
		if (n%i==0){
			r=0;
			while (n%i==0){
				n/=i;
				r++;
			}
			j=r/p;
			while (j>0){
				ans*=i;
				j--;
			}
		}
	}
	if (n>1&&p==1){
		ans*=n;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a == 1 && b == 2) {
      System.out.println(3);
    } else if (a == 1 && b == 3) {
      System.out.println(2);
    } else if (a == 2 && b == 1) {
      System.out.println(3);
    } else if (a == 2 && b == 3) {
      System.out.println(1);
    } else if (a == 3 && b == 1) {
      System.out.println(2);
    } else if (a == 3 && b == 2) {
      System.out.println(1);
    }
  }
}


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;

int main() {
	int k;
	int a[5], i, j;

	rep(i, 5) {
		cin >> a[i];
	}
	cin >> k;

	rep(i, 5) {
		rep(j, 5) {
			if (abs(a[i] - a[j]) > k) {
				cout << ":(";
				return 0;
			}
		}
	}
	cout << "Yay!";	

	return 0;
}


Measured memory_bytes: 256
n, t = map(int, input().split())
candt = []
for _ in range(n) :
    candt += [list(map(int, input().split()))]
candidate = []
for i in range(n) :
    if candt[i][1] <= t :
        candidate += [candt[i]]

if candidate == [] :
    print("TLE")
else :
    costlist = [i[0] for i in candidate]
    print(min(costlist))

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    ll count = 0;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) {
        if(A[i] < B[i]) {
            ll temp = B[i] - A[i];
            temp += temp % 2;
            A[i] += temp;
            count += temp / 2;
        }
    }
    rep(i, N) {
        if(A[i] > B[i]) count -= A[i] - B[i];
    }
    cout << (count < 0 ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 3780
#include <stdio.h>
int main() {
int a,b,i;
  scanf("%d %d",&a,&b);
  if(a>b)
  for(i=0;i<a;i++){
  printf("%d",b);
  }
  else if (a<b)
    for(i=0;i<b;i++){
      printf("%d",a);
    }else
      for(i=0;i<a;i++){
      printf("%d",a);
      }
return 0;
}

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

const int N = 3005;
int n, t;
vector<pair<int, int>> AB;
int dp[N][N];

int solve(int idx, int rem) {
    if(idx == n) return 0;
    if(rem <= 0) return 0;

    if(dp[idx][rem]) return dp[idx][rem];
    return dp[idx][rem] = max(AB[idx].second + solve(idx + 1, rem - AB[idx].first), solve(idx + 1, rem));
}

int main() {
    cin >> n >> t;
    AB.resize(n);
    for(int i = 0; i < n; i++) {
        cin >> AB[i].first >> AB[i].second;
    }

    sort(AB.begin(), AB.end());
    solve(0, t);
    cout << dp[0][t];
}

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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(k>=e-a) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> T(N);
  for(int i=0; i<N; i++)cin>>T[i];
  int M;cin>>M;
  vector<int> P(M);
  vector<int> X(M);
  for(int i=0; i<M; i++)cin>>P[i]>>X[i];
  
  for(int i=0; i<M; i++){
    int s=0;
    for(int j=0; j<N; j++){
      if(P[i]==j+1)s+=X[i];
      else s+=T[j];
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>

using namespace std;

string T[6] =
{
    "",
    " afkpuz",
    " bglqv.",
    " chmrw?",
    " dinsx!",
    " ejoty "
};

void Solution(string str)
{
    if ( str.size() % 2 != 0 )  //input is should be even numbers
    {
        cout<< "NA" << endl;
        return;
    }
    
    string ans = "";
    
    for (int i = 0; i < (int)str.size(); i += 2)
    {
        int first = str[i] - '0';
        int second = str[i+1] - '0';
        
        if (1 <= first && first <= 6 && 1 <= second && second <= 5 )
        {
            ans += T[second][first];
        }
        else
        {
            cout << "NA" << endl;
            return;
        }
    }
    
    cout << ans << endl;
    
}

int main()
{
    string str;
    
    while(cin>>str)
    {
        Solution(str);
    }

    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N;
double p[3030];
double prob[3030][3030];

void solve() {
    prob[0][0] = 1;
    FOR(n, 1, N + 1) {
        FOR(i, 0, n + 1) {
            prob[n][i] = prob[n - 1][i] * (1.0 - p[n - 1]);
            if (i >= 1)
                prob[n][i] += prob[n - 1][i - 1] * p[n - 1];
        }
    }
    double ans = 0;
    FOR(i, N / 2 + 1, N + 1) {
        ans += prob[N][i];
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    cin >> N;
    FOR(N)
    cin >> p[i];


    solve();
    return 0;
}


Measured memory_bytes: 70272
package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)
	H := make([]int, N)
	heightPeakEnableds := make([]bool, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &H[i])
		heightPeakEnableds[i] = true
	}

	for i := 0; i < M; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)
		if H[a-1] > H[b-1] {
			heightPeakEnableds[b-1] = false
		} else if H[a-1] < H[b-1] {
			heightPeakEnableds[a-1] = false
		} else {
			heightPeakEnableds[b-1] = false
			heightPeakEnableds[a-1] = false
		}
	}

	r := 0
	for _, heightPeakEnabled := range heightPeakEnableds {
		if heightPeakEnabled {
			r++
		}
	}
	fmt.Println(r)
}


Measured memory_bytes: 6460
#include <stdio.h>
#include <string.h>
#define STMAX 50
int main(void)
{
  int i, slen, tlen, spos, tpos, sflag = 0;
  char str[STMAX+1], ttr[STMAX+1];
  scanf("%s%*c", str);
  scanf("%s%*c", ttr);
  slen = strlen(str);
  tlen = strlen(ttr);
  spos = slen - 1;
  tpos = tlen - 1;
  while (spos >= 0) {
    if (str[spos] != '?') {
      while (tpos < tlen && str[spos] != ttr[tpos]) tpos++;
    }
    if (tpos == 0) {
      sflag = 1;
      break;
    }
    spos--;
    tpos--;
  }
  if (sflag) {
    for (i = spos; i < spos + tlen; i++) str[i] = ttr[i-spos];
    for (i = 0; i < slen; i++) {
      if (str[i] == '?') str[i] = 'a';
    }
    printf("%s\n", str);
  } else printf("UNRESTORABLE\n");
}

Measured memory_bytes: 128
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    W = LI()

    W_cum = [0] * (N + 1)
    for i in range(N):
        W_cum[i+1] = W_cum[i] + W[i]

    sum_W = sum(W)
    ans = INF
    for i in W_cum:
        ans = min(abs(sum_W - 2 * i), ans)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10088
import math
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
M,K=map(int,input().split())
a=map(int,input().split())
A=list(a)
c=0
A.sort()
for i in range(M-K+1):
 c+=cmb(M-1-i, K-1, mod)*(A[M-1-i]-A[i])
print(c%mod)

Measured memory_bytes: 132832
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {

  int input;
  vector<int> yama;

  for ( int i = 0; i < 10; i++ ) {
    cin >> input;
    yama.push_back(input);
  }

  sort( yama.begin(), yama.end(), greater<int>() );

  cout << yama[0] << endl << yama[1] << endl << yama[2] << endl;

  return 0;

}

Measured memory_bytes: 1216
N, K = map(int, input().split())
ps = list(map(int, input().split()))
Es = [(ps[i]+1)/2 for i in range(N)]
maxs = []
for i in range(1, N+1):
  if i<K:
    continue
  elif i==K:
    tmp = sum(Es[:i])
    maxs.append(tmp)
  else:
    tmp = tmp +Es[i-1]-Es[i-K-1]
    maxs.append(tmp)
print(max(maxs))

Measured memory_bytes: 25604
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        if(s.length() >= 1 && s.length() <= 10){
            String t = scan.next();

            char[] x = new char[s.length()];
            for(int i = 0 ; i < s.length() ; i++){
                x[i] = s.charAt(i);
            }
            char[] y = new char[t.length()];
            for(int i = 0 ; i < t.length() ; i++){
                y[i] = t.charAt(i);
            }

            String out = "Yes";

            if((s.length() + 1) == t.length()){
                for(int i = 0 ; i < s.length() ; i++){
                    if(x[i] != y[i]){
                        out = "No";
                        break;
                    }
                }
                System.out.println(out);
            }
        }
    }
}


Measured memory_bytes: 35672