akhauriyash/Code-Regression huggingface dataset:
import sys
import bisect
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def merge(a, b):
    res = []
    i, j = 0, 0
    while i < len(a) or j < len(b):
        if j >= len(b) or (i < len(a) and a[i][0] < b[j][0]):
            w, v = a[i]
            i += 1
        else:
            w, v = b[j]
            j += 1
        if not res or (res[-1][1]) < v:
            res.append((w, v))
        elif res[-1][0] == w and res[-1][1] <= v:
            res.pop()
            res.append((w, v))
    return res


def best(L, a, b):
    res = 0
    i = 0
    j = len(b) - 1
    while i < len(a):
        w, v = a[i]
        if j < 0:
            break
        if b[j][0] + w > L:
            j -= 1
            continue
        res = max(res, v + b[j][1])
        i += 1
    return res


def main():
    N = int(input())
    VW = [(-1, -1)] + [list(map(int, input().split())) for _ in range(N)]
    Q = int(input())
    query = tuple(tuple(map(int, input().split())) for _ in range(Q))

    dp = [[] for _ in range(2048)]
    dp[0] = [(0, 0)]
    for i in range(1, min(N + 1, 2048)):
        vi, wi = VW[i]
        a1 = dp[i // 2]
        a2 = [(w + wi, v + vi) for w, v in a1]
        dp[i] = merge(a1, a2)

    for n, L in query:
        if n < 2048:
            w, v = zip(*dp[n])
            i = bisect.bisect_right(w, L) - 1
            print(v[i])
        else:
            a = [(0, 0)]
            while n >= 2048:
                vi, wi = VW[n]
                b = [(w + wi, v + vi) for w, v in a]
                a = merge(a, b)
                n //= 2
            print(best(L, a, dp[n]))


if __name__ == "__main__":
    main()

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    
}

int main() {
    fastio
    string s, t;
    cin >> s >> t;
    t += s;
    cout<<t<<endl;
    
	return 0;
}






Measured memory_bytes: 256
import numpy as np

H, W = map(int, input().split())

A = np.empty((H, W), dtype='str')
for i in range(H):
    A[i, :] = list(input())


def delete_row(A):
    nrow = A.shape[0]
    ncol = A.shape[1]

    idx = []
    for i in range(nrow):
        if (''.join(A[i, :]) != '.'*ncol):
            idx.append(i)
    return(A[idx, :])


def delete_col(A):
    nrow = A.shape[0]
    ncol = A.shape[1]

    idx = []
    for i in range(ncol):
        if (''.join(A[:, i]) != '.'*nrow):
            idx.append(i)
    return(A[:, idx])

while(True):
    nrow, ncol = A.shape
    A = delete_row(A)
    A = delete_col(A)
    nrow_, ncol_ = A.shape
    if (nrow_ == nrow and ncol_ == ncol):
        break

for i in range(A.shape[0]):
    print(''.join(A[i, :]))


Measured memory_bytes: 21632
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

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

    vector<string> l;
    bool z = true;
    string wp = "";
    for(int i = 0; i < n; i++){
        string w;
        cin >> w;
        if(find(l.begin(), l.end(), w) != l.end()){
            z = false;
            break;
        }else if(i != 0 && wp[wp.length()-1] != w[0]){
            z = false;
            break;
        }else{
            l.push_back(w);
        }
        wp = w;
    }
    if(z) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = (ull)1e9+7;


int main(void)
{
	ll k,n;
	cin >> k >> n;
	if (k * 500 >= n) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    int64_t ans=0;
    rep(i,1,N) ans+=i;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
dp = [[0] * 4 for i in range(n + 2)]  # dp[i][j]=(長さiの最後の文字がjで条件を満たす文字列の数:j= 0:A 1:G 2:C 3:T)
# 番兵を2つ置いておくと都合がいい
for i in range(4):
    dp[2][i] = 1
mod = 10**9 + 7
for i in range(3, n + 2):
    for j in range(4):
        for k in range(4):
            dp[i][j] += dp[i - 1][k]
    dp[i][2] -= dp[i - 2][0]  # AGCを取り除く.
    dp[i][2] -= dp[i - 2][1]  # GACを取り除く.
    dp[i][1] -= dp[i - 2][0] - dp[i - 3][1]  # ACGを取り除く. ただしGACGはすでに取り除いている.
    dp[i][2] -= 3 * dp[i - 3][0]  # すでに取り除いているものに注意する.結果的にAGGC,ATGC,AGTCを取り除く.

    for j in range(4):
        dp[i][j]%mod
print(sum(dp[-1])%mod)


Measured memory_bytes: 9128
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int A[][] = new int[3][3];
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                A[i][j] = scan.nextInt();
            }
        }
        int N = scan.nextInt();
        boolean b[][] = new boolean[3][3];

        for(int i = 0; i < N; i++) {
            helper(A, b, scan.nextInt());
        }

        if((b[0][0] && b[0][1] && b[0][2]) || (b[0][0] && b[1][1] && b[2][2]) || (b[0][0] && b[1][0] && b[2][0])
            || (b[1][0] && b[1][1] && b[1][2]) || (b[2][0] && b[2][1] && b[2][2]) || (b[0][1] && b[1][1] && b[2][1])
            || (b[0][0] && b[0][1] && b[0][2]) || (b[0][2] && b[1][2] && b[2][2]) || (b[2][0] && b[1][1] && b[0][2])) {
            os.println("Yes");
        } else
            os.println("No");

    }

    static void helper(int A[][], boolean b[][], int tgt) {
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                if(A[i][j] == tgt) {
                    b[i][j] = true;
                    return;
                }
            }
        }
    }
}

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

int main(){
	int N, D, X;
	cin >> N >> D >> X;
	vector <int> A(N);
	for (int i = 0; i < N; i++) cin >> A.at(i);
	int ans = N;
	for (int i = 0; i < N; i++){
		ans += (D - 1) / A.at(i);
	}
	cout << ans + X << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c,i,n;
    //scanf("%d%d%d%d",&n,&a,&b,&c);
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d%d%d",&a,&b,&c);
        if(a==b || a==c || b==c)
        printf("NO\n");
        else if(a*a+b*b==c*c)
        printf("YES\n");
        else if(a*a+c*c==b*b)
        printf("YES\n");
        else if(b*b+c*c==a*a)
        printf("YES\n");
        else printf("NO\n");

    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int num[100005],n,l,pp;

int main(){
    cin >> n >> l;
    for(int i=0;i<n;i++)cin >> num[i];
    for(int i=1;i<n;i++){
                if(num[i-1]+num[i]>=l){
                    pp=i;
                    break;
                }
        }

        if(pp!=0){
        cout << "Possible" << endl;
        for(int i=1;i<pp;i++){
            cout << i << endl;
        }
        for(int i=n-1;i>=pp;i--){
            cout << i << endl;
        }
        }else{
        cout << "Impossible" << endl;
        }


return 0;
}


Measured memory_bytes: 1152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        v: [usize; 7]
    }
    let mut ans = v[0] / 2 * 2 + v[1] + v[3] / 2 * 2 + v[4] / 2 * 2;
    match v[0] % 2 + v[3] % 2 + v[4] % 2 {
        3 => {ans += 3;},
        2 if v[0] > 0 && v[3] > 0 && v[4] > 0 => {ans += 1;},
        _ => {}
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	vector<int>v(102);
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	v[A]++;
	v[C]++;
	v[B + 1]--;
	v[D + 1]--;
	for (int i = 1; i < 102; i++) {
		v[i] += v[i - 1];
	}
	int ans = 0;
	for (int i = 0; i < 102; i++) {
		if (v[i] == 2) {
			ans++;
		}
	}ans--;
	cout << max(0, ans) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 998244353;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int pSum[100005];
int main()
{
    IO;
    int n,q;
    string s;
    cin >> n >> q >> s;
    for(int i = 0;i < s.length()-1;i++)
    {
        if(s[i] == 'A' && s[i+1] == 'C')
            pSum[i]++;
    }
    for(int i = 1;i <= n;i++)
        pSum[i] += pSum[i-1];
    while(q--)
    {
        int l,r;
        cin >> l >> r;
        l--;
        r--;
        r--;
        cout << pSum[r] - (l ? pSum[l-1] : 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 1488
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define FOR(variable,start,end) for(int variable = start; variable < end; ++variable)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	int x;
	cin >> x;
	if(x==1){
		cout << 0 << endl;
	}
	else{
		cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3608
// 2020-09-23 23:07:13
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  set<int> ss, ws;
  {
    repc(i, 1500) repc(j, 1500) {
      int k = c * i + d * j;
      if (k <= f) ss.insert(k);
    }
    repc(i, 30) repc(j, 15) {
      int k = 100 * a * i + 100 * b * j;
      if (0 < k && k <= f) ws.insert(k);
    }
  }
  int anss = 0, answ = 0, mx = -1;
  for (auto s : ss)
    for (auto w : ws) {
      bool ok = true;
      ok &= (s + w <= f);
      ok &= (s * 100 <= e * w);
      if (ok && chmax(mx, 10000 * s / (s + w))) {
        anss = s;
        answ = w;
      }
    }
  cout << anss + answ << ' ' << anss << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3720
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n;

ll k;
int main() {

    cin >> n >> k;
    vector<int> a(n);
    vector<int> m;
    vector<bool> seen(n, false);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    int now = 0;
    ll b;
    ll MOD;
    while(m.size()<n+1){
        if(m.size()==n){
            b = 0;
            MOD = n;
        }
        if(seen[now]){
            for (ll i = 0; i < m.size(); i++)
            {
                if(m[i]==now){
                    b = i;
                    MOD = m.size()-i;
                    break;
                }
            }
            break;
        }
        seen[now]=true;
        m.push_back(now);
        now=a[now];
    }
    int ans;
    if(k<b){
        ans = m[k]+1;
    }else{
        k=(k-b)%MOD;
        ans = m[b+k]+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5132
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
	int a;
	long double ans=0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		ans = ans + (long double)1 / (long double)a;
	}
	ans = (long double)1 / ans;
	cout <<fixed<<setprecision(9)<< ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
 
int main(){
  int n;
  cin >> n;
  vi b(n-1);
  rep(i,n-1) cin >> b.at(i);

  vi a(n);
  for(int i = 1; i < n-1; i++){
    a.at(i) = min(b.at(i-1),b.at(i));
  }

  a.at(0) = b.at(0);
  a.at(n-1) = b.at(n-2);
  int ans = 0;
  rep(i,n){
    ans += a.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from operator import itemgetter


def r(n, l):
    l.sort(reverse=True)
    lm = l[0]
    ln = sum(l[1:])
    return 'Yes' if lm < ln else 'No'


def main():
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))

    print(r(n, l))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
/* LETS SEE IF U CAN PULL IT UP THIS TIME OR NOT */
/* WORK HARD MAN ! IT DEFINETELY AIN'T EASY FOR THE PRIZE IT HOLDS .... */
/* GET YOUR ASS TO WORK ALREADY */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define mod 1000000007
#define inf 1e15
#define pii pair<int,int>
#define ff first
#define ss second
// #define N --

using namespace std;

int32_t main() {
    fast
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    unordered_map<int, int> h, m;
    int cs = 1, cnt = 0;
    while (!h.count(cs)) {
        h[cs] = cnt;
        m[cnt] = cs;
        cs = a[cs];
        cnt++;
    }

    if (h[cs] > k)
        cout << m[k] << endl;
    else {
        k -= h[cs];
        int cycle = cnt - h[cs];
        cout << m[h[cs] + k % cycle] << endl;
    }

}

Measured memory_bytes: 20996
#include <cstdio>
#include <vector>

typedef long long int ll;

const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;

int n, k, u, v;
ll ans;
ll dp[MAXN];

std::vector<int> con[MAXN];

void ins(int start, int end) {
    con[start].push_back(end);
}

void get_dp(int nv, int fa) {
    int tmp = (nv == 1) ? (k - 1) : (k - 2);
    for (int i = 0; i < con[nv].size(); ++i) {
        if (con[nv][i] == fa)
            continue;
        else {
            dp[con[nv][i]] = tmp;
            get_dp(con[nv][i], nv);
            --tmp;
        }
    }
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i < n; ++i) {
        scanf("%d%d", &u, &v);
        ins(u, v);
        ins(v, u);
    }
    dp[1] = k;
    get_dp(1, 0);
    ans = 1;
    for (int i = 1; i <= n; ++i) {
        ans = ans * dp[i] % mod;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 11136
/*
	*	Created By: 'Present_Sir'
	*	Created On: Friday 04 September 2020 11:18:23 AM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
#define ld long double
using namespace std;

class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            ld a,b,c;
            cin>>a>>b>>c;
            ld y = (ld)sqrt((ld)b);
            ld x = (ld)sqrt((ld)a);
            ld z = (ld)sqrt((ld)c);
            ld eps = 1.0E-14;
            if( (ld)x + (ld)y + eps < (ld)z ){
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }
};


int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}



Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> b;
    rep(i, n) {
        ll tmp = a[i];
        b.push_back(tmp);
        FOR(j, i+1, n) {
            tmp += a[j];
            b.push_back(tmp);
        }
    }
    sort(b.rbegin(), b.rend());
    ll ans = 0;
    for(int i=40; i>=0; i--) {
        ll now = ans + (1ll<<i);
        int cnt = 0;
        rep(j, sz(b)) {
            if ((now & b[j]) == now) cnt++;
        }
        if (cnt >= k) {
            ans = now;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
import sys
from collections import Counter

A = sys.stdin.readline().strip()
la = len(A)

ans = la * (la - 1) // 2 + 1
counter = Counter(A)
for key, count in counter.items():
    if count == 1:
        continue
    ans -= count * (count - 1) // 2

print(ans)

Measured memory_bytes: 9572
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,m,r[50],R,f[220][220],xx,yy,zz,ans;
bool b[50];
void dfs(int x,int c,int s){
	if (c==R){
		if (s<ans) ans=s;
		return;
	}
	b[x]=1;
	fo(i,1,R)
		if (!b[i]) dfs(i,c+1,s+f[r[x]][r[i]]);
	b[x]=0;
}
int main(){
	scanf("%d%d%d",&n,&m,&R);
	fo(i,1,n) fo(j,1,n) f[i][j]=0x3fffffff;
	fo(i,1,R) scanf("%d",&r[i]);
	fo(i,1,m){
		scanf("%d%d%d",&xx,&yy,&zz);
		if (zz<f[xx][yy]) f[xx][yy]=f[yy][xx]=zz;
	}
	fo(k,1,n)
		fo(i,1,n)
			fo(j,1,n)
				if (f[i][k]+f[k][j]<f[i][j])
					f[i][j]=f[i][k]+f[k][j];
	ans=0x3fffffff;
	fo(i,1,R) dfs(i,1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int n=read(),k=read(),a[999];
int main(){
int ans=0;
for (re0 i=1;i<=n;++i){
  int x=read();
  ans+=min(x,k-x)*2;
  }
write(ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<string> s;
int main() {
  cin >> n;
  read_n(s, n);
  i64 ans = 0;
  i64 ca = 0, cb = 0, cba = 0;
  for (auto&& t : s) {
    if (t.front() == 'B' && t.back() == 'A') ++cba;
    else if (t.front() == 'B') ++cb;
    else if (t.back() == 'A') ++ca;
    for (i64 i = 0; i < t.size() - 1; ++i) {
      if (t[i] == 'A' && t[i + 1] == 'B') ++ans;
    }
  }
  bool f = false;
  while (ca > 0 || cb > 0 || cba > 0) {
    if (f) {
      if (cba > 0) { --cba; ++ans; }
      else if (cb > 0) { --cb; f = false; ++ans; }
      else { f = false; --ca; }
    } else {
      if (ca > 0) { --ca; f = true; }
      else if (cba > 0) { --cba; f = true; }
      else { --cb; }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100005]={0};
	int n;
	while(~scanf("%d",&n))
	{
		scanf("%s",a);
	int sum=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			continue;
		}
		else
		{
			sum++;
		}
	}
	
	printf("%d\n",sum);
	}
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main(){
    int n,l=0;
    while(cin>>n,n){
        if(l)cout<<endl;l++;
        map<int,vector<string> >m;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            m[3*a+c].push_back(s);
        }
        for (map<int,vector<string> >::reverse_iterator it=m.rbegin(); it!=m.rend(); ++it){
            vector<string>v=it->second;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<","<<it->first<<endl;
            }
        }
    }
}

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

int main() {
    int n, k;
    cin >> n >> k;

    int h[n];
    for (int i = 0; i < n; i++) cin >> h[i];

    sort(h, h + n);

    int ans = 1000000000;
    for (int i = 0; i <= n - k; i++) {
        ans = min(ans, h[i + k - 1] - h[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long int 
#define pb  push_back
#define mp  make_pair
#define pii pair<int, int>
using namespace std;

const ll mod = 1e9+7;
const int N = 3000;
double p[N+1] = {0};
bool check[N+1][N+1] = {0};
double dp[N+1][N+1] = {0};
int in;

double dp_recurse(int n, int k){
	if(n==1){
		if(k==0){
			return 1 - p[in];
		}
		else if(k==1){
			return p[in];
		}

		return 0;
	}

	if(n<k){
		return 0;
	}

	if(check[n][k] == 1){
		return dp[n][k];
	}

	dp[n][k] = p[in - n + 1]*dp_recurse(n-1, k-1) + (1 - p[in - n + 1])*dp_recurse(n-1, k);
	check[n][k] = 1;

	return dp[n][k];
}


void solve(){
    //solve here//
	//int n;
	cin >> in;

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

	double ans = 0;
	for(int i=(in/2)+1;i<=in;i++){
		ans += dp_recurse(in, i);
	}

	cout << setprecision(12) << ans << endl;
}


int main(){
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
}



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

int main(){
    int n; cin >> n;
    int node[n+1];
    for(int i=1; i<=n; ++i){
        cin >> node[i];
    }
    for(int i=1; i<=n; ++i){
        cout << "node " << i << ": key = " << node[i] << ", ";
        int x = floor(i/2);
        if (i != 1) cout << "parent key = " << node[x] << ", ";
        if (2*i <= n) cout << "left key = " << node[2*i] << ", ";
        if (2*i + 1 <= n) cout << "right key = " << node[2*i+1] << ", ";
        cout << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using std::cin;
using std::cout;

std::string s, t;

int main() {
	int n; cin >> n;
	cin >> s >> t;
	for (int p = n; ~p; p--)
	{
		bool ok = true;
		for (int q = 0; q < p; q++)
		{
			if(t[q] != s[n - p + q])
				ok = false;
		}
		if(ok) 
		{
			printf("%d\n", 2 * n - p);
			return 0;	
		}
	}
	return 0;
}





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

int w, h;
char tile[20][20];
int ans = 0;
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };

void solve(int x, int y)
{
	ans++;
	tile[y][x] = '#';
	for (int i = 0; i < 4; i++)
	{
		int X = x + dx[i];
		int Y = y + dy[i];
		if (tile[Y][X] == '.' && 0 <= X && X < w && 0 <= Y && Y < h)
		{
			solve(X, Y);
		}
	}
}

int main()
{

	while (cin >> w >> h, w + h != 0){
		
		ans = 0;

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				cin >> tile[i][j];
			}
		}
		
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (tile[i][j] == '@') solve(j, i);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int i,j,k,v;
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int array[] = new int[n];

		for(i=0;i<n;i++)array[i] = in.nextInt();

	for(i=0;i<n;i++){
		v = array[i];
		j = i-1;
		while(j>=0 && array[j]>v){
			array[j+1] = array[j];
			j--;
		array[j+1] = v;
		}
	    for(k = 0;k<n-1;k++)System.out.print(array[k]+" ");
	    if(i<(n-1))System.out.println(array[k]);
	    else System.out.println(array[k]);
	}
	}

}

Measured memory_bytes: 31404
#include <bits/stdc++.h>
using namespace std;
int N, M, Q, ans = 0;
vector<int> A(55), B(55), C(55), D(55);
vector<vector<int>> S;

void calc(vector<int> &v)
{
  int score = 0;
  for (int i = 0; i < Q; i++)
  {
    if (v.at(B.at(i)) - v.at(A.at(i)) == C.at(i))
    {
      score += D.at(i);
    }
  }
  ans = max(ans, score);
}

void dfs(int n, string s)
{
  if (s.size() == N)
  {
    vector<int> v;
    for (int i = 0; i < N; i++)
    {
      v.push_back((int)(s.at(i) - '0'));
    }
    return calc(v);
  }
  for (int i = n; i <= M; i++)
  {
    char c = '0' + i;
    dfs(i, s + c);
  }
}

int main()
{
  cin >> N >> M >> Q;
  for (int i = 0; i < Q; i++)
  {
    cin >> A.at(i) >> B.at(i) >> C.at(i) >> D.at(i);
    A.at(i)--, B.at(i)--;
  }
  dfs(1, "");
  cout << ans << endl;
}


Measured memory_bytes: 3624
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

    count = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    count += 1
    print(count)



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

typedef long long ll;
typedef long double ld;

const int MOD = 1000000009;

int add(int a, int b){
    return (a+b)%MOD;
}

int mul(int a, int b){
    return (1LL*a*b)%MOD;
}

int pre[300005];
//int pways[300005];
int suf[300005];
//int sways[300005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, k, c;
    cin >> n >> c >> k;
    string s;
    cin >> s;
    for(int i=1; i-k-1<n; i++){
        pre[i] = pre[i-1];
        if(i > k && s[i-k-1] == 'o'){
            pre[i] = max(pre[i], 1 + pre[i-k-1]);
            //if(pre[i] == pre[i-k-1]) pways[i] = pways[i-k-1];
        }
        //if(pre[i] == pre[i-1]) pways[i] = add(pways[i], pways[i-1]);
    }
    //for(int i=n+1; i<=2*n; i++) pre[i] = pre[i-1];
    for(int i=n; i>=1; i--){
        suf[i] = suf[i+1];
        if(s[i-1] == 'o'){
            suf[i] = max(suf[i], 1 + suf[i+k+1]);
            //if(suf[i] == suf[i+k+1]) sways[i] = sways[i+k+1];
        }
        //if(suf[i] == suf[i+1]) sways[i] = add(sways[i], sways[i+1]);
    }
    //cout << pre[1+k] << endl;
    //cout << suf[3] << endl;
    for(int i=1; i<=n; i++){
        if(s[i-1] == 'o'){
            if(pre[i-1+k] + suf[i+1] < c) cout << i << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3348
#include<iostream>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<math.h>
#include<string>
#include<stack>
#include<typeinfo>
using namespace std;
typedef pair<int, int> P;
int main() {
	// x/u=(l-x)/v
	//ul-ux=xv
	//xv+ux=ul
	//x=ul/(v+u)//x=1から見た長さu=1からくる電車の速度
	int  l[10];
	vector<int>rui(11,0);
	double v1, v2, sum,x;
	char ch;
	while (cin>>l[0]>>ch) {
		sum = 0;
		sum += l[0];
		rui[1] = l[0];
		for (int i = 1; i < 10; ++i) {
			cin >> l[i] >> ch;
			sum += l[i];
			rui[i + 1] = l[i] + rui[i];
		}
		cin >> v1 >> ch >> v2;
		x = v1*sum / (v2 + v1);
		for (int i = 1; i <= 10; ++i) {
			if (rui[i - 1] < x&&x < rui[i] || x == rui[i]) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3164
N,M,K=map(int,input().split())

par=[-1]*N
num=[0]*N

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(x,y):
    p,q=find(x),find(y)
    if p==q:
        return
    if p>q:
        p,q=q,p
    par[p]+=par[q]
    par[q]=p   

def size(x):
    return -par[find(x)]

def same(x,y):
    return find(x)==find(y)
        

for _ in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    union(a,b)
    num[a]+=1
    num[b]+=1

for _ in range(K):
    c,d=map(int,input().split())
    c-=1
    d-=1
    if same(c,d):
        num[c]+=1
        num[d]+=1

for i in range(N):
    print(size(i)-1-num[i],end=" ")


Measured memory_bytes: 11396
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <ctime>
using namespace std;
#pragma warning(disable: 4996)
int c[10][10], H, W, a[1009][1009], s[1009], ans;
int main() {
	cin >> H >> W;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++)cin >> c[i][j];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j]; if (a[i][j] >= 0)s[a[i][j]]++;
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++)c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
		}
	}
	for (int i = 0; i < 10; i++)ans += c[i][1] * s[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n,k;
  std::cin >> n>>k;
  char tmp,be;
  std::cin >> be;
  int ans=0;
  for (int i = 1; i < n; i++) {
    std::cin >> tmp;
    if(tmp==be)ans++;
    else be=tmp;
  }

  if(k*2+ans>n-1)std::cout << n-1 << '\n';
  else std::cout << k*2+ans << '\n';


  return 0;
}


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

#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;
#define pow10(n) int(1e##n + n)

// dp[i][j][k] …… i:確定した桁数 / j:残りの使える被ゼロ数 / k: N超でないことが確定
LL dp[101][4][2];
bool flag[101][4][2];
LL L;
string S;

LL rec(int i, int j, int isOk)
{
    if (i == L) // 被ゼロを使い切ったか？
        return (j == 0);

    if (flag[i][j][isOk])
        return dp[i][j][isOk];

    flag[i][j][isOk] = true;

    LL ans = 0;

    REP0(d, 10)
    { // d:次にえらぶやつ / nd その桁の数字
        int nd = S[i] - '0';
        int next_i = i + 1, next_j = j, next_isOk = isOk;

        if (d != 0)
            next_j--;

        if (next_j < 0)
            continue;

        if (nd < d and isOk == 0)
            continue;

        if (d < nd)
            next_isOk = true;

        ans += rec(next_i, next_j, next_isOk);
    }
    return dp[i][j][isOk] = ans;
}

void solve()
{
    cin >> S;
    L = S.length();
    int K;
    cin >> K;

    cout << rec(0, K, false) << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 2e5 + 10;
int a[MAXN];
int dp[MAXN][2][3];
bool vis[MAXN][2][3];
int n;

int rec_even(int idx,int type,int cnt){
    if(idx > n) return 0;
    int &ans = dp[idx][type][cnt];

    if(vis[idx][type][cnt]) return ans;
    vis[idx][type][cnt] = 1;

    ans = -1e16;

    if(type == 0) {
        ans = max(ans,rec_even(idx+1,1,cnt));
        if(cnt == 0) ans = max(ans,rec_even(idx+1,0,cnt+1));
    }else {
        ans = max(ans,rec_even(idx+1,0,cnt) + a[idx]);
    }

    return ans;
}

int rec_odd(int idx,int type,int cnt){
    if(idx > n) return 0;
    int &ans = dp[idx][type][cnt];

    if(vis[idx][type][cnt]) return ans;
    vis[idx][type][cnt] = 1;

    ans = -1e16;

    if(type == 0) {
        ans = max(ans,rec_odd(idx+1,1,cnt));
        if(cnt < 2) ans = max(ans,rec_odd(idx+1,0,cnt+1));
    }else {
        ans = max(ans,rec_odd(idx+1,0,cnt) + a[idx]);
    }

    return ans;
}
void solve(){
    cin>>n;

    FOR(i,1,n) cin>>a[i];

    if(n%2 == 0){
        int ans = 0;
        for(int i=2;i<=n;i+=2) ans = ans + a[i];
        ZERO(vis);
        ans = max(ans,rec_even(1,1,0));
        cout<<ans<<endl;
    }else {
        int ans = 0;
        for(int i=3;i<=n;i+=2) ans = ans + a[i];
        ZERO(vis);
        ans = max(ans,rec_odd(1,1,0));
        ZERO(vis);
        ans = max(ans,rec_even(2,1,0));
        cout<<ans<<endl;
    }
}

signed main(){

   FastRead; 


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}





Measured memory_bytes: 31344
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;

const int MAXN = 1001;
int N, indegree[MAXN][MAXN] = {0};
vector<pair<int, int>> edges[MAXN][MAXN];

int solve()
{
    int out = 0;
    queue<pair<int, int>> que[2];
    for (int i = 1; i <= N - 1; i++)
        for (int j = i + 1; j <= N; j++)
            if (indegree[i][j] == 0)
                que[0].push(make_pair(i, j));

    bool flag = true;
    while (flag)
    {
        flag = false;
        while (!que[out % 2].empty())
        {
            pair<int, int> top = que[out % 2].front();
            que[out % 2].pop();
            for (pair<int, int> v : edges[top.first][top.second])
            {
                indegree[v.first][v.second]--;
                if (indegree[v.first][v.second] == 0)
                    que[(out + 1) % 2].push(make_pair(v.first, v.second));
            }
            flag = true;
        }
        if (flag)
            out++;
    }

    // check loop
    for (int i = 1; i <= N - 1; i++)
        for (int j = i + 1; j <= N; j++)
            if (indegree[i][j] > 0)
                out = -1;

    return out;
}

int main()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        int prev;
        cin >> prev;
        for (int j = 2; j <= N - 1; j++)
        {
            int v;
            cin >> v;
            edges[min(i, prev)][max(i, prev)].push_back(make_pair(min(i, v), max(i, v)));
            indegree[min(i, v)][max(i, v)]++;
            prev = v;
        }
    }

    cout << solve() << endl;
    // system("pause");
}

Measured memory_bytes: 43264
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
 ll a,b,c,d;
  	ci(a>>b>>c>>d);
  if(abs(a-c)<=d) co("Yes")
    else if(abs(a-b)<=d&&abs(b-c)<=d) co("Yes")
    else co("No")
    }

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int num[300];
int main(){
	int a,b,c,d=0,e=0;
	cin>>a>>b>>c;
	for(int i=0;i<b;i++){
		cin>>num[i];
		if(num[i]>c)d++;
		if(num[i]<c)e++;
	}
	printf("%d",d>e?e:d);
	return 0;
}


Measured memory_bytes: 256
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int c=0;
            boolean flag=false;
            for(int i=0;i<n;i++){
                int d1=scan.nextInt();
                int d2=scan.nextInt();
                if(d1==d2){
                    c++;
                }else{
                    c=0;
                }
                if(c==3){
                    flag=true;
                }
            }
            if(flag){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


Measured memory_bytes: 32476
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 2005;

vector <int> ans, e[N];

int n, siz[N], fa[N], a[N];

int pos[N];

bool blocked[N];

bool cmp(const int &x, const int &y) {
	return siz[x] > siz[y];
} 

void dfs(int u) {
	siz[u] = 1;
	for (int v : e[u]) {
		dfs(v), siz[u] += siz[v];
		sort (e[u].begin(), e[u].end(), cmp);
	}
}

int dfs(int u, int val) {
	if (blocked[u]) return -1;
	int res = -1, tmp;
	for (int v : e[u]) {
		tmp = dfs(v, val);
		if (tmp < 0) continue;
		if (res < 0 || a[res] < a[tmp]) {
			res = tmp;
		}
	}
	if (res == -1 && a[u] > val) res = u;
	return res;
}

void rot(int u) {
	if (1 == u) return;
	rot(fa[u]);
	a[fa[u]] = a[u];
}

void rotate(int u) {
	ans.push_back(u);
	int i, tmp;
	pos[a[1]] = u;
	for (i = u; i != 1; i = fa[i])
		pos[a[i]] = fa[i];
	tmp = a[1];
	rot(u);
	a[u] = tmp;
}

int main() {
	//freopen("test.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 2; i <= n; i ++) {
		cin >> fa[i], fa[i] ++;
		e[fa[i]].push_back(i);
	}
	for (int i = 1; i <= n; i ++)
		cin >> a[i], a[i] ++, pos[a[i]] = i;
	dfs(1);
	for (int i = n; i > 0; i --) {
		if (a[i] == i) {
			blocked[i] = 1;
			continue;
		}
		while (a[1] != i) {
			int j = pos[i];
			int u = dfs(j, a[1]);
			rotate(u);
		}
		rotate(i);
		blocked[i] = 1;
	}
	printf("%d\n", (int)ans.size());
	for (int i : ans)
		printf("%d\n", i - 1);
	return 0;
}

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


signed main(){
    int x;
    cin >> x;
    int temp;
    bool z=false;
    int a,b;
    rep(i,1000){
        for(int j=-1000;j<1000;j++){
            if((i*i*i*i*i)-(j*j*j*j*j)==x){
                a=i;
                b=j;
                z=true;
                break;
            }
        }
        if(z) break;
    }

    cout << a << " " << b;
}

Measured memory_bytes: 3632