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

bool IsPalindrome(string s){
    string aux=s;
    reverse(aux.begin(),aux.end());
    return s==aux;
}
bool IsPalindrome2(string s){
    int a=s.size();
    string s2;
    for(int i=0;i<(a-1)/2;i++){
        s2+=s[i];
    }
    string aux=s2;
    reverse(aux.begin(),aux.end());
    return s2==aux;
}
bool IsPalindrome3(string s){
    int a=s.size();
    string s3;
    for(int i=(a+3)/2-1;i<a;i++){
        s3+=s[i];
    }
    string aux=s3;
    reverse(aux.begin(),aux.end());
    return s3==aux;
}

int main(){
    string s;
    bool a=false,b=false,c=false,d=false;
    cin >> s;
    a=IsPalindrome(s);
    b=IsPalindrome2(s);
    c=IsPalindrome3(s);
    d=a&&b&&c;
    if(d)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int a = int.Parse(cin[0]);
        int b = int.Parse(cin[1]);
        int c = int.Parse(cin[2]);

        if (a <= c && c <= b) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int X, N;
    cin >> X >> N;
    vector<int> a(102, 0);
    int b;
    for (int i = 0; i < N; i++) {
        cin >> b;
        a[b] = 1;
    }
    int ans = 0, minD = INF;
    for (int i = 0; i < 102; i++) {
        if (a[i] == 1) continue;
        if (abs(i - X) < minD) {
            minD = abs(i - X);
            ans = i;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 100010
#define ll long long
using namespace std;
ll f[N],p[N],s[N],ans[N];
int n;
void get_nxt(ll f[],const ll g[])
{
	for(int i=1;i<=n;i++) s[i]=f[g[i]];
	for(int i=1;i<=n;i++) f[i]=s[i];
}
void ksm(ll f[],ll k)
{
	for(int i=1;i<=n;i++) ans[i]=i;
	for(;k;k>>=1)
	{
		if(k&1) get_nxt(ans,f);
		get_nxt(f,f);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&f[i]),p[i]=i;
	int m;
	ll k;
	scanf("%d%lld",&m,&k);
	for(int i=1;i<=m;i++)
	{
		int a;
		scanf("%d",&a);
		swap(p[a],p[a+1]);
	}
	ksm(p,k);
	for(int i=1;i<=n;i++) printf("%lld\n",s[i]=s[i-1]+f[ans[i]]-f[ans[i]-1]);
	return 0;
}

Measured memory_bytes: 6276
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;  
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 3e5 + 10;
const int mod = 1e9 + 7;

int f[MAXN];

int powmod(int a, int p) {
    if (p == 0) return 1;
    if (p == 1) return a % mod;
    int k = powmod(a, p / 2);
    if (p & 1) return (k * k % mod) * a % mod;
    return k * k % mod;
}

int rev(int x) {
    return powmod(x, mod - 2);
}

int C(int n, int k) {
    int ans = f[n];
    ans = ans * rev(f[n - k]) % mod;
    ans = ans * rev(f[k]) % mod;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    f[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        f[i] = f[i - 1] * i % mod;
    }
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int ans = 0;
    for (int down = 0; down <= h - a - 1; down++) {
        ans += C(down + b - 1, b - 1) * C(h - 1 - down + w - 1 - b, w - 1 - b) % mod;
        ans %= mod;
    }
    cout << ans << "\n";
}
/*

*/

Measured memory_bytes: 5996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<string>s0(n);
    ll r=0,g=0,b=0;
    rep(0,i,n){
        s0[i]=s.substr(i,1);
        if(s0[i]=="R")++r;
        if(s0[i]=="G")++g;
        if(s0[i]=="B")++b;
    }
    ll uc=0;
    rep(0,i,n){
        string ns=s0[i];
        rep(i+1,j,n){
            string nns=s0[j];
            if(ns!=nns && j+j-i<n){
                string nnns=s0[j+j-i];
                if(nns!=ns && nnns!=ns && nns!=nnns){
                    ++uc;
                }
            }
        }
        //cout<<uc<<endl;
    }
    cout<<r*g*b-uc;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int n, a[100], x;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    int sol = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], x -= a[i];

    sort(a, a + n);
    cout << n + x / a[0];
}


Measured memory_bytes: 256
import sys
from collections import deque
from copy import deepcopy

input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
m = [['#' for _ in range(w+2)] for _ in range(h+2)]

for hi in range(1, h+1):
    for wi, s in enumerate(input().strip(), start=1):
        m[hi][wi] = s

def bfs(hs, ws, m):
    cost = -1
    if m[hs][ws] == '#':
        return cost
    q = deque([(hs, ws)])
    m[hs][ws] = '#'
    while q:
        cost += 1
        q_ = deque(q)
        q = deque([])
        for h, w in q_:
            m[h][w] = '#'
            for offset in [(0, 1), (-1, 0), (0, -1), (1, 0)]:
                if m[h+offset[0]][w+offset[1]] == '.':
                    m[h+offset[0]][w+offset[1]] = '#'
                    q.append((h+offset[0], w+offset[1]))
    return cost

ans = 0
for hi in range(1, h+1):
    for wi in range(1, w+1):
        ans = max(ans, bfs(hi, wi, deepcopy(m)))

print(ans)

Measured memory_bytes: 3436
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	h, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	w, _ := strconv.Atoi(sc.Text())

	skipRows := makeTrues(h)
	skipCols := makeTrues(w)
	white := byte('.')

	matrix := make([][]byte, h)
	for i := 0; i < h; i++ {
		sc.Scan()
		row := sc.Text()
		matrix[i] = make([]byte, w)

		skipRow := true
		for j := 0; j < w; j++ {
			matrix[i][j] = row[j]
			skipRow = skipRow && matrix[i][j] == white
			skipCols[j] = skipCols[j] && matrix[i][j] == white
		}
		skipRows[i] = skipRow
	}

	colIdxs := make([]int, 0)
	for j, skip := range skipCols {
		if !skip {
			colIdxs = append(colIdxs, j)
		}
	}

	out := bufio.NewWriter(os.Stdout)
	for i, row := range matrix {
		if skipRows[i] {
			continue
		}
		for _, j := range colIdxs {
			fmt.Fprintf(out, string(row[j]))
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

func makeTrues(n int) []bool {
	bs := make([]bool, n)
	for i := 0; i < n; i++ {
		bs[i] = true
	}
	return bs
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN (int)5e5+5
#if !testing
#define cerr if(0)cout
#endif
/*
 * >< -> 0
 * >> A[i]=A[i+1]+1
 * <> A[i]=min(A[i-1],A[i+1])+1
 * << A[i]=A[i-1]+1
*/
string str; 
int dp[MAXN];
int n;
int dpdp(int x, int p){
	//db(x);
	if(~dp[x])return dp[x];
	if(x==1){
		if(str[x]=='<')return dp[x]=0;
		else return dp[x] = dpdp(x+1,x)+1;
	}
	if(x==n) {
		if(str[x-1]=='>')return dp[x]=0;
		else return dp[x] = dpdp(x-1,x)+1;
	}
	if(str[x-1]=='<') {
		if(str[x]=='<') return dp[x] = dpdp(x-1,x)+1;
		int ans=-1;
		if(p^(x-1))ans=dpdp(x-1,x)+1;
		if(p^(x+1))ans=max(ans,dpdp(x+1,x)+1);
		return dp[x]=ans;
	} else {
		if(str[x]=='<')return dp[x]=0;
		else return dp[x]=dpdp(x+1,x)+1;
	}

}
int32_t main() {
	IAMSPEED
	memset(dp,-1,sizeof dp);
	cin>>str;
	str="A"+str;
	n = str.size();
	//exit(0);
	int ans = 0;
	FOR(i,1,n)ans+=dpdp(i,-1);
	cout<<ans;
}


Measured memory_bytes: 28208
#include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

ll plot(bool ifx, ll val, ll time, char dir){
    if((dir == 'L' && ifx) || (dir == 'D' && !ifx)){
        return val - time;
    }else if((dir == 'R' && ifx) || (dir == 'U' && !ifx)){
        return val + time;
    }else{
        return val;
    }
}

void bs(ll &lb, ll ub, ll &comp, ll kind, bool ifx, bool ifma, vec &v, vector<char> &d, vec &t){
    while(ub - lb > 1){
        ll cen = (ub + lb) / 2, tmp = (ifma ? -1e+9 : 1e+9);
        rep(i,N) {
            ifma ? chmax(tmp, plot(ifx, v[i], cen, d[i]))
                 : chmin(tmp, plot(ifx, v[i], cen, d[i]));
        }
        (comp + kind * cen == tmp ? lb : ub) = cen;
    }
    t.push_back(lb);
    comp += kind * lb;
}
void search(bool ifx, vec &v, vec &t, vector<char> &d){
    ll lb = 0, ub = 1e+9, mi = 1e+9, ma = -1e+9;
    rep(i,N) chmin(mi, v[i]);
    rep(i,N) chmax(ma, v[i]);
    bs(lb, ub, mi, 1, ifx, false, v, d, t);
    bs(lb, ub, mi, 0, ifx, false, v, d, t);
    lb = 0;
    bs(lb, ub, ma, -1, ifx, true, v, d, t);
    bs(lb, ub, ma, 0, ifx, true, v, d, t);
}

ll solve(ll time, vec &x, vec &y, vector<char> &d){
    ll xa, xi, ya, yi;
    xa = ya = -1e+9;
    yi = xi = 1e+9;
    rep(i,N){
        chmax(xa, plot(true, x[i], time, d[i]));
        chmax(ya, plot(false, y[i], time, d[i]));
        chmin(xi, plot(true, x[i], time, d[i]));
        chmin(yi, plot(false, y[i], time, d[i]));
    }
    return (ya - yi) * (xa - xi);
}

int main(){
    cin>>N;
    vec t(1, 0), x(N), y(N);
    vector<char> d(N);
    rep(i,N){
        cin>>x[i]>>y[i]>>d[i];
        x[i] *= 2;
        y[i] *= 2;
    }
    search(true, x, t, d);
    search(false, y, t, d);
    ll ans = 1e+18;
    for(ll ti : t) chmin(ans, solve(ti, x, y, d));
    cout<<fixed<<setprecision(10)<<((long double)ans) / 4.0<<endl;
}

Measured memory_bytes: 1920
n = gets.to_i
s = gets.chomp
a = s.chars

l = nil
r = nil

nr = 0
for i in 0...n
    if a[i] == 'R'
        nr += 1
        r = i
    else
        l = i unless l
    end
end

l = nr unless l

ans = 0
for i in 0...n
    r = n-1-i

    break if l >= r || l >= nr

    if a[r] == 'R'
        # swap l <-> r
        # p "swap l:#{l} r:#{r}"
        a[r] = 'W'
        a[l] = 'R'
        l += 1
        ans += 1
        while a[l] == 'R' && l < r
            l += 1
        end
    end
end

nl = n - nr

ans = nl if ans > nl
ans = nr if ans > nr

puts ans

Measured memory_bytes: 32124
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

struct Edge {
  int to, w;
};

vector<ll> dijkstra(const vec<Edge, 2>& G, int s) {
  const int N = G.size();
  vector<ll> dist(N, 1ll << 60);
  priority_queue<pair<ll, int>> q;
  dist[s] = 0;
  q.emplace(0, s);
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    ll d = -p.first;
    int v = p.second;
    if (dist[v] < d) continue;
    for (auto& e : G[v]) {
      if (dist[e.to] <= d + e.w) continue;
      dist[e.to] = d + e.w;
      q.emplace(-dist[e.to], e.to);
    }
  }
  return dist;
}

int main() {
  int N, M, S, T;
  while (cin >> N >> M >> S >> T) {
    --S;
    --T;
    vec<Edge, 2> yG(N), sG(N);
    for (int i = 0; i < M; i++) {
      int u, v, a, b;
      cin >> u >> v >> a >> b;
      --u;
      --v;
      yG[u].push_back(Edge{v, a});
      yG[v].push_back(Edge{u, a});
      sG[u].push_back(Edge{v, b});
      sG[v].push_back(Edge{u, b});
    }
    vector<ll> yDist = dijkstra(yG, S), sDist = dijkstra(sG, T);
    vector<ll> ans(N, 1ll << 60);
    for (int i = 0; i < N; i++) {
      ans[i] = yDist[i] + sDist[i];
    }
    for (int i = N - 2; i >= 0; i--) ans[i] = min(ans[i], ans[i + 1]);
    ll base = 1000000000000000ll;
    for (ll x : ans) cout << base - x << endl;
  }
  return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int x[6];

	for (int i = 1; i <= 5; ++i) {
		cin >> x[i];
	}

	for (int i = 1; i <= 5; ++i) {
		if (!x[i])
			cout << i << '\n';
	}



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


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

const int YEAR=365;

struct Req{
    int i,j,w;
};

void cmax(int &lhs,int rhs){
    lhs=max(lhs,rhs);
}
int solve(int n){
    vector<vector<Req>> req(YEAR);
    for(int k=0;k<n;k++){
        int i,j,w;
        cin>>i>>j>>w;
        i--;
        req[i].push_back({i,j,w});
    } 
    vector<vector<int>> dp(YEAR+1,vector<int>(YEAR+1));
    for(int i=0;i<=YEAR;i++){
        for(int j=0;j<=YEAR;j++){
            if(i==YEAR && j==YEAR) continue;
            if(i<j){
                for(auto &r:req[i]){
                    cmax(dp[r.j][j],dp[i][j]+r.w);
                }
                cmax(dp[i+1][j],dp[i][j]);
            }
            else if(j<i){
                for(auto &r:req[j]){
                    cmax(dp[i][r.j],dp[i][j]+r.w);
                }
                cmax(dp[i][j+1],dp[i][j]);
            }
            else{
                assert(i<YEAR && j<YEAR);
                for(int ki=0;ki<req[i].size();ki++){
                    for(int kj=ki+1;kj<req[j].size();kj++){
                        cmax(dp[req[i][ki].j][req[j][kj].j],dp[i][j]+req[i][ki].w+req[j][kj].w);                        
                    }
                }        
                for(auto &r:req[i]){
                    cmax(dp[r.j][j+1],dp[i][j]+r.w);
                }
                for(auto &r:req[j]){
                    cmax(dp[i+1][r.j],dp[i][j]+r.w);
                }
                cmax(dp[i+1][j+1],dp[i][j]);    
            }
        }
    }
    return dp[YEAR][YEAR];
}
int main(){
    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3312
// OfficialHouse.cc
// Ａ大学は１フロア１０部屋、３階建ての公舎４棟を管理しています。
// 公舎の入居・退去の情報を読み込み、各部屋の入居者数を出力するプログラムを作成して下さい。
// n件の情報が与えられます。各情報では、４つの整数b, f, r, vが与えられます。
// これは、b棟f階のr番目の部屋にv人が追加で入居したことを示します。
// vが負の値の場合、-v人退去したことを示します。
// 最初、全ての部屋には誰も入居していないものとします。
// 【入力】
// 最初の行に情報の数 n が与えられます。
// 続いて n 件の情報が与えられます。
// 各情報には４つの整数 b, f, r, v が空白区切りで１行に与えられます。
// 【出力】
// ４棟について入居者数を出力して下さい。
// 各棟について、１階、２階、３階の順に入居者数を出力します。
// 各階については、１番目、２番目、・・・、１０番目の部屋の入居者数を順番に出力します。
// 入居者数の前には１つの空白を出力して下さい。
// また、各棟の間には####################(20個の#)で区切って下さい。
// 【制約】
// ・間違った棟番号・階・部屋番号は与えられない。
// ・管理の過程で１部屋の入居者数が０より少なくなることはない。
// ・管理の過程で１部屋の入居者数が9より多くなることはない。
// 【例】
// 入力：
// 3
// 1 1 3 8
// 3 2 2 7
// 4 3 8 1
// 出力：
//  0 0 8 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
// ####################
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
// ####################
//  0 0 0 0 0 0 0 0 0 0
//  0 7 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
// ####################
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 1 0 0
#include<iostream>
using namespace std;

int main( void) {
  int n;	// 情報の数
  int b, f, r, v;	// b棟、f階、r番目の部屋、v人
  int move_in_person_num[ 4][ 3][ 10] = {};

  // 入居者情報の入力
  cin >> n;
  for ( int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    move_in_person_num[ b-1][ f-1][ r-1] += v;
  }

  for ( int i = 0; i < 4; i++) {	// 1-4棟
    for ( int j = 0; j < 3; j++) {	// 1-3階
      for ( int k = 0; k < 10; k++) {	// 1-10部屋
	cout << " " << move_in_person_num[ i][ j][ k];
      }
      cout << endl;
    }
    if ( i < 3) cout << "####################" << endl;
  }

  return 0;
}



Measured memory_bytes: 3124
#include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

bool uruu(int y)
{
	if (y % 4 == 0)
	{
		if (y % 100 == 0 && y % 400 == 0)return true;
		if (y % 100 == 0)return false;
		return true;
	}
	return false;
}

int main()
{
	int dat[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int y, m, d, Y, M, D;
	while (cin >> y >> m >> d >> Y >> M >> D && y != -1)
	{
		int ans = 0;
		ans -= d - 1; d = 1;
		for (; m >= 1; m--)
		{
			ans -= dat[m - 1];
			if (uruu(y) && m == 2)
			{
				ans -= 1;
			}
		}

		ans += D - 1; D = 1;
		for (; M >= 1; M--)
		{
			ans += dat[M - 1];
			if (uruu(Y) && M == 2)
			{
				ans += 1;
			}
		}
		for (; y < Y; y++)
		{
			ans += 365;
			if (uruu(y))
			{
				ans += 1;
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long llong;
llong mod=1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  llong h,i,to;
  i=0;
  to=0;
  cin>>h;
  while(h!=0){
    h/=2;
    i++;
  }
  to+=pow(2,i)-1;
  cout<<to<<endl;
  return 0;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(b-(b/c+b/d-b/(c*d/__gcd(c,d))))-((a-1)-((a-1)/c+(a-1)/d-(a-1)/(c*d/__gcd(c,d))))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int n, K;
    while(cin>>n>>K){
        vl pre(n+1);
        fore(i,1,n+1)
            pre[i] = (pre[i-1] + i)%mod;
        // print(pre,1);
        
        ll ans = 0;
        for(int k=K; k<=n; ++k){
            ll left = pre[k-1];
            ll right = pre[n] - pre[n-k];
            // deb3(k,left, right);
            add_self(ans, right - left + 1);
        }
        add_self(ans,1);
        cout<<ans<<endl;
    }
    return 0;
}

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

int main()
{
  string s;
  int k;
  cin >> s >> k;
  int ans = 1;
  if (s.size() < k) k = s.size();
  for (auto i = 0; i < k; i++) {
    if (s[i] != '1') {
      ans = s[i] - '0';
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

struct cards{
    ll num;
    ll amo;
    bool operator<(const cards c)const{
        return num>c.num;
    }
};

int main(){fastio
    ll n,m;cin>>n>>m;
    multiset<cards>s;
    rep(i,1,n){
        ll a;cin>>a;
        s.insert(cards{a,1});
    }
    while(m--){
        ll b,c;cin>>b>>c;
        s.insert(cards{c,b});
    }
    ll ans=0;
    /*for(auto x:s){
        cout<<x.num<<" "<<x.amo<<endl;
    }*/
    for(auto x:s){
        if(x.amo<=n){
            n-=x.amo;
            ans+=x.num*x.amo;
        }else{
            ans+=x.num*n;
            n=0;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>
#include <map>
#include <chrono>
#include <cstdlib>
#include <ctime>
#include <list>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793





int main() {
    ll n,x,t;
    cin >> n;
    cin >> x;
    cin >> t;
    ll a = n % x;
    ll ans = n / x;
    if (a != 0) {
        ans++;
    }
    //cout << a << endl;
    cout << ans*t << endl;
    return 0;
}


Measured memory_bytes: 3632
N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=P
T=A[P-1]
for i in range(P,N):
 if A[P-1]-A[i]<=M and T-(i-P+1)*A[i]<=M*(N-V):
  ans+=1
 T+=A[i]
print(ans)


Measured memory_bytes: 62576
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

int main() {
	lnt n,a,b,c,d;
	std::cin >> n >> a >> b >> c >> d;
	n-=1;
	for(lnt u=0;u<=n;u++) {
		lnt base = a+c*(2*u-n);
		lnt r=d-c;
		if(base+r*u>=b&&base-r*(n-u)<=b) {
			print("YES");
			return 0;
		}
	}
	print("NO");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int n, k; cin >> n >> k;
	vi v(n); rep(i, 0, n) cin >> v[i];
	ll lo = *max_element(all(v)) - 1;
	ll hi = 1e9;
	ll p, P, m;
	while(hi - lo > 1) {
		p = P = (lo + hi) / 2;
		m = 1;
		rep(i, 0, n) {
			if(v[i] > p) {
				p = P;
				++m;
			}
			p -= v[i];
		}
		(m <= k ? hi : lo) = P;
	}
	P(hi);
	return 0;
}

Measured memory_bytes: 3280
S = input()

countA = 0
countC = 0
for i in range(len(S)):
    if i == 0:
        if S[i] != 'A':
            print('WA')
            quit()
        else:
            countA += 1
            continue
    if S[i] == 'C':
        if i < 2 or i == len(S)-1:
            print('WA')
            quit()
        countC += 1
    elif not S[i].islower():
        print('WA')
        quit()
    if countA > 1 or countC > 1:
        print('WA')
        quit()

if countA != 1 or countC != 1:
    print('WA')
    quit()
print('AC')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long double dp[305][305][305];
int main()
{
    int n;
    cin>>n;
    vector<int>arr(n);
    int a,b,c;
    a=b=c=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]==1)
            a++;
        if(arr[i]==2)
            b++;
        if(arr[i]==3)
            c++;
    }
    dp[0][0][0]=0;

    for(int k=0;k<=c;k++)
    {
        for(int j=0;j<=n-k;j++)
        {
            for(int i=0;i<=n-k-j;i++)
            {
                long double ks=(long double)n/(i+j+k);
                if(i!=0)
                    dp[i][j][k]+=i*(ks+dp[i-1][j][k]);
                if(j!=0)
                    dp[i][j][k]+=j*(ks+dp[i+1][j-1][k]);
                if(k!=0)
                {
                    dp[i][j][k]+=k*(ks+dp[i][j+1][k-1]);
                }

                if((i+j+k)!=0)
                {
                    dp[i][j][k]=dp[i][j][k]/(long double)(i+j+k);
                }

            }
        }
    }
//     for(int k=0;k<=c;k++)
//    {
//        for(int j=0;j<=n-k;j++)
//        {
//
//            for(int i=0;i<=n-k-j;i++)
//            {
//             cout<<dp[i][j][k]<<" ";
//
//            }
//            cout<<endl;
//        }
//        cout<<endl;
//    }
cout.precision(17);
    cout<<dp[a][b][c];
return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> x(N+1), y(M+1);
    cin >> x[0] >> y[0];
    for(int i=1; i<N+1; i++) cin >> x[i];
    for(int j=1; j<M+1; j++) cin >> y[j];

    if(*max_element(x.begin(), x.end())
        >= *min_element(y.begin(), y.end())) cout << "War\n";
    else cout << "No War\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);
string S;cin>>S;
string Q="abc";
  
  
 int A=(int)Q[0]*(int)Q[1]*(int)Q[2];
 int B=(int)S[0]*(int)S[1]*(int)S[2];
  
  if(A==B){
  cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  
  
}


Measured memory_bytes: 256
import heapq
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
logof2=[0]*N
mi=0
buf=0
#print(A)
for i in range(N):
    A[i]=-A[i]  #heapqは実装上最初値しか取り出さないので、数列を-1倍し、最小値が最大に当たるようにする
heapq.heapify(A)#priority_que化
for i in range(M):
    buf=heapq.heappop(A)    #最大値を取り出すことに相当
    buf=(-buf)/2           #切り捨て(floor)の挙動は負数の時おかしくなるので一旦正値に変換して計算し
    buf=-buf                #負数に戻す
    heapq.heappush(A,buf)   #
    #print(A)
for i in range(N):
    mi=mi+math.floor(-1*A[i])  #残った要素ごとの足し算に相当する

print(mi)


Measured memory_bytes: 14380
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
    int N;
    cin>>N;
    string S,T;
    cin>>S>>T;
    
    for(int i=0;i<N;i++){
        cout<<S.at(i)<<T.at(i);
    }
    cout<<endl;
}

Measured memory_bytes: 256
//
// Created by Takaaki Hirano on 2018/09/01.
//
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>


using namespace std;
int K;

void solve() {
    int even = 0, odd = 0;
    for (int i = 1; i <= K; ++i) {
        if (i % 2 == 0)even++;
        else odd++;
    }

    printf("%d\n", even * odd);
}

int main() {
    cin >> K;
    solve();
    return 0;
}


Measured memory_bytes: 764
#include <atcoder/string>
#include <iostream>
using ll = long long;
#define rep(i, j, n) for (int i = j; i < n; ++i)

int main() {
  std::string s;
  std::cin >> s;
  ll n = s.length();
  auto sa = atcoder::suffix_array(s);
  ll ans = n * (n + 1) / 2;
  auto lcp = atcoder::lcp_array(s, sa);
  for (int x : lcp) ans -= x;
  std::cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 15388
import Data.Bool (bool)

main :: IO ()
main = do
    n  <- read <$> getLine
    xs <- map read . words <$> getLine
    answer $ solve n xs

type Answer = Bool
answer :: Answer -> IO ()
answer = putStrLn . bool "NO" "YES"

solve :: Int -> [Int] -> Answer
solve n as = inner (as ++ [head as]) (m == 0)
  where
    (k, m) = sum as `divMod` ((n * n + n) `div` 2)
    inner (xa : xxs@(xb : xs)) =
        (&&) `flip` bool (inner xxs) id (null xs) (d <= 0 && d `mod` n == 0)
      where
        d = xb - xa - k


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

int main(){

 
  int N;
  cin>>N;
  int A[N];
  
  rep(i,N)cin>>A[i];
  
  sort(A, A + sizeof(A)/sizeof(A[0]));
  
  for(int i=1;i<N;i++){

    if(A[i-1]==A[i]){

      cout<<"NO";
      return 0;
      
    }
    
  }
  
  cout<<"YES";
  
}


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

int main()
{
  vector<int> a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  int ans = 10*a[2]+a[1]+a[0];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[3001][3001];

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	rep(i,s.size()) rep(j,t.size()){
	    if(s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
	    dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1]);
	    dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]);
	}
	string ans = "";
	ll i=s.size(),j=t.size();
	while(i>0&&j>0){
	    if(dp[i][j] == dp[i-1][j]) i--;
	    else if(dp[i][j] == dp[i][j-1]) j--;
	    else{
	        ans += s[i-1];
	        i--;
	        j--;
	    }
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}


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

int main(){
    
    int N;
    int sum = 0;
    cin >> N;
    vector<int> d(N);
    
    for(int i = 0; i < N; i++) cin >> d[i];
    
    for(int i = 0; i < N; i++)
        for(int j = i+1; j < N; j++)
            sum += d[i]*d[j];
            
    
    cout << sum << endl;
    
}

Measured memory_bytes: 256
import sys
from collections import deque

input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())

    prefix = deque()
    surfix = deque()
    prefix_append = prefix.appendleft
    surfix_append = surfix.append
    is_reversed = False
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            is_reversed = not is_reversed
        else:
            if q[1] == "1":
                if is_reversed:
                    surfix_append(q[2])
                else:
                    prefix_append(q[2])
            else:
                if is_reversed:
                    prefix_append(q[2])
                else:
                    surfix_append(q[2])

    ans = "".join(["".join(prefix), S, "".join(surfix)])
    if is_reversed:
        ans = ans[::-1]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6516
#include<cstdio>
#include<iostream>
#include<cctype>
#include<algorithm>
#include<stack>
#include<cstdlib>
using namespace std;
int main() {
	int count=0,s,n, q, S[100000], T[50000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}
	cin >> q;
	for (int i = 0; i <q; i++) {
		cin >> T[i];
	}
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (S[j] == T[i]) {
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3676
# ｴ゛ｳ゛ｴ゛ｳ゛ｴ゛ｳ゛ｱ゛ｧ゛ｱ゛ｧ゛ｲ゛ｨ゛
N = int(input())
A = map(int, input().split())
flag = 0
for i in A:
  if i % 2 == 0:
    if i % 3 != 0 and i % 5 != 0:
      print("DENIED")
      exit()
print("APPROVED")

Measured memory_bytes: 2940
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int d,g,p[110],c[110],dp[110][1010],ans=1e9;

int main()
{
	cin>>d>>g;
	rep(i,d) cin>>p[i]>>c[i];
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	rep(i,d)
	{
		rep(j,1005)
		{
			if(dp[i][j]==-1) continue;
			rep(k,p[i]+1)
			{
				dp[i+1][j+k]=max(dp[i+1][j+k],dp[i][j]+k*(i+1)*100+(k==p[i] ? c[i]:0));
				if(dp[i+1][j+k]>=g) ans=min(ans,j+k);
			}
		}
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;

long long a, b;

int main(){

    cin >> a >> b;

    for(long long i = 0; i < 100000; i++){
        if(floor(i*0.08) == a && floor(i*0.1) == b){
            cout << i;
            return 0;
        }
    }

    cout << -1;
    return 0;



}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

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

using namespace std;

vector<int> prime;
bool isPrime[1000000];
void primeCalc()
{
	for(int i = 0; i < 1000000; ++i)
	{
		isPrime[i] = true;
	}
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < 1000000; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < 1000000; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	primeCalc();
	int a, d, n;
	while(cin >> a >> d >> n, a || d || n)
	{
		int count = 0;
		int num = a;
		int ans = 0;
		while(count < n)
		{
			if(isPrime[num])
			{
				ans = num;
				++count;
			}
			num += d;
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 2564
#include <bits/stdc++.h>
using namespace std;
using P=pair<int ,int>;
int main(){
  int h,w; cin>>h>>w;
  vector<vector<int>> num(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>num[i][j];
    }
  }
  int n=0,mh=0,mw=0;
  bool flag=true,skip=true;
  vector<P> base,move;
  while(mh!=h && mw!=w){
    skip=true;
    if(num[mh][mw]%2!=0){
      base.push_back(P(mh+1,mw+1));
      n++;
      skip=false;
    }
    if(flag){
      mw++;
      if(mw==w){
        mh++; mw--;
        flag=false;
      }
    }else{
      mw--;
      if(mw==-1){
        mh++; mw=0;
        flag=true;
      }
    }
    if(skip) continue;
    if(mh<0 || mh>=h || mw<0 || mw>=w){
      n--;
      break;
    }num[mh][mw]++;
    move.push_back(P(mh+1,mw+1));
  }
  cout<<n<<endl;
  for(int i=0;i<n;i++){
    cout<<base[i].first<<' '<<base[i].second<<' '<<move[i].first<<' '<<move[i].second<<endl;
  }
}

Measured memory_bytes: 5228
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (ll i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (ll i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (ll i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (ll i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (ll i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (ll i = (x), a = 0; a < (N);   \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);
    ll n, k;
    cin >> n >> k;
    int r = 0;

    while(n != 0){
        n /= k;
        ++r;
    }

    cout << r;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,c = map(int,readline().split())
stc = []
for i in range(n):
    stc.append(list(map(int,readline().split())))
stc.sort(key=lambda x: (x[2], x[0]))
 
nstc = []
for i in range(n):
    if len(nstc) > 0 and nstc[-1][2] == stc[i][2] and nstc[-1][1] == stc[i][0]: #同じチャンネルかつ終了時刻と始まりの時刻が同じ
        nstc[-1][1] = stc[i][1]
    else:
        nstc.append(stc[i])
n = len(nstc)
 
h = [0]*200005
for i in range(n):
    h[2*nstc[i][0] - 1] += 1
    h[2*nstc[i][1]] += -1
ah = list(accumulate(h))
print(max(ah))

Measured memory_bytes: 102188
module IntSet = Set.Make (struct type t = int let compare = compare end)

let rec tabulate n f = 
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let rec solve (ds : IntSet.t) (k : int -> int) (k' : int -> int) : int -> int = function
  | 0 -> k 0
  | n ->
      let m, n = n mod 10, n / 10 in
      if IntSet.mem m ds then
        solve ds (fun n -> k (10 * n + m)) (fun n -> k' (10 * n + IntSet.min_elt ds)) n
      else
        tabulate 10 (fun n -> n)
        |> List.filter (fun n -> IntSet.mem n ds && m < n)
        |> (function
            | [] ->
                let k n = k' (10 * n + IntSet.min_elt ds) in
                solve ds k k (n + 1)
            | m :: _ ->
                solve ds (fun n -> k' (10 * n + m)) (fun n -> k' (10 * n + IntSet.min_elt ds)) n) 

let () =
  let n, k = Scanf.scanf "%d %d\n" (fun n k -> n, k) in
  let ds =
    IntSet.diff
      (IntSet.of_list (tabulate 10 (fun k -> k)))
      (IntSet.of_list (tabulate k (fun _ -> Scanf.scanf "%d " (fun d -> d)))) in
  Printf.printf "%d\n" (solve ds (fun n -> n) (fun n -> n) n)


Measured memory_bytes: 384